Showing
1 changed file
with
34 additions
and
23 deletions
... | @@ -18,6 +18,7 @@ const dayPostList = mongoose.Schema({ | ... | @@ -18,6 +18,7 @@ const dayPostList = mongoose.Schema({ |
18 | const dayPostListModel = mongoose.model('dayPostList', dayPostList); | 18 | const dayPostListModel = mongoose.model('dayPostList', dayPostList); |
19 | const post = mongoose.Schema({ | 19 | const post = mongoose.Schema({ |
20 | date: 'string', | 20 | date: 'string', |
21 | + time: 'string', | ||
21 | title: 'string', | 22 | title: 'string', |
22 | content: 'string', | 23 | content: 'string', |
23 | password: 'string' | 24 | password: 'string' |
... | @@ -49,6 +50,17 @@ function getCurrentDate(originDate) { | ... | @@ -49,6 +50,17 @@ function getCurrentDate(originDate) { |
49 | return year + '-' + month + '-' + day; | 50 | return year + '-' + month + '-' + day; |
50 | } | 51 | } |
51 | 52 | ||
53 | +function getCurrentTime() { | ||
54 | + var date = new Date(); | ||
55 | + var hour = date.getHours(); | ||
56 | + hour = hour < 10 ? '0' + hour.toString() : hour.toString(); | ||
57 | + | ||
58 | + var minute = date.getMinutes(); | ||
59 | + minute = minute < 10 ? '0' + minute.toString() : minute.toString(); | ||
60 | + | ||
61 | + return hour + ":" + minute; | ||
62 | +} | ||
63 | + | ||
52 | function arrayEquals(a, b) { | 64 | function arrayEquals(a, b) { |
53 | return Array.isArray(a) && | 65 | return Array.isArray(a) && |
54 | Array.isArray(b) && | 66 | Array.isArray(b) && |
... | @@ -80,7 +92,7 @@ router.get('/api/getList/:date', async (req, res) => { | ... | @@ -80,7 +92,7 @@ router.get('/api/getList/:date', async (req, res) => { |
80 | } | 92 | } |
81 | }); | 93 | }); |
82 | 94 | ||
83 | -router.get('/api/get', async (req, res) => { // 특정 id(여러개)의 게시물 내용 요약 불러오기 | 95 | +router.post('/api/get', async (req, res) => { // 특정 id(여러개)의 게시물 내용 요약 불러오기 |
84 | try { | 96 | try { |
85 | const idArray = req.body.idArray; | 97 | const idArray = req.body.idArray; |
86 | var resultArray = []; | 98 | var resultArray = []; |
... | @@ -88,10 +100,12 @@ router.get('/api/get', async (req, res) => { | ... | @@ -88,10 +100,12 @@ router.get('/api/get', async (req, res) => { |
88 | const onePost = await postModel.findById(id); | 100 | const onePost = await postModel.findById(id); |
89 | var tempJSON = {}; | 101 | var tempJSON = {}; |
90 | tempJSON.id = onePost.id; | 102 | tempJSON.id = onePost.id; |
103 | + tempJSON.time = onePost.time; | ||
91 | tempJSON.title = onePost.title; | 104 | tempJSON.title = onePost.title; |
92 | tempJSON.content = onePost.content; | 105 | tempJSON.content = onePost.content; |
93 | - tempJSON.content = tempJSON.content.replace(/(?:\r\n|\r|\n)/g, ''); | 106 | + tempJSON.content = tempJSON.content.replace(/(?:\r\n|\r|\n| )/g, ''); |
94 | const sliceLength = 10; | 107 | const sliceLength = 10; |
108 | + if (tempJSON.title.length > sliceLength) tempJSON.title = tempJSON.title.slice(0, sliceLength) + "..."; | ||
95 | if (tempJSON.content.length > sliceLength) tempJSON.content = tempJSON.content.slice(0, sliceLength) + "..."; | 109 | if (tempJSON.content.length > sliceLength) tempJSON.content = tempJSON.content.slice(0, sliceLength) + "..."; |
96 | resultArray.push(tempJSON); | 110 | resultArray.push(tempJSON); |
97 | } | 111 | } |
... | @@ -105,7 +119,7 @@ router.get('/api/get', async (req, res) => { | ... | @@ -105,7 +119,7 @@ router.get('/api/get', async (req, res) => { |
105 | router.get('/api/get/:id', async (req, res) => { // 특정 id의 게시물 불러오기 | 119 | router.get('/api/get/:id', async (req, res) => { // 특정 id의 게시물 불러오기 |
106 | try { | 120 | try { |
107 | const currentPost = await postModel.findById(req.params.id); | 121 | const currentPost = await postModel.findById(req.params.id); |
108 | - res.send({ title: currentPost.title, content: currentPost.content }); | 122 | + res.send({ date: currentPost.date, time: currentPost.time, title: currentPost.title, content: currentPost.content }); |
109 | } | 123 | } |
110 | catch (err) { | 124 | catch (err) { |
111 | res.send(err.message); | 125 | res.send(err.message); |
... | @@ -127,6 +141,7 @@ router.post('/api/postSave', async (req, res) => { | ... | @@ -127,6 +141,7 @@ router.post('/api/postSave', async (req, res) => { |
127 | try { | 141 | try { |
128 | var isFirst = false; | 142 | var isFirst = false; |
129 | const today = getCurrentDate(); | 143 | const today = getCurrentDate(); |
144 | + const time = getCurrentTime(); | ||
130 | 145 | ||
131 | var testDayPostList = await dayPostListModel.findOne({ date: today }); | 146 | var testDayPostList = await dayPostListModel.findOne({ date: today }); |
132 | if (testDayPostList == null) { | 147 | if (testDayPostList == null) { |
... | @@ -134,7 +149,7 @@ router.post('/api/postSave', async (req, res) => { | ... | @@ -134,7 +149,7 @@ router.post('/api/postSave', async (req, res) => { |
134 | isFirst = true; | 149 | isFirst = true; |
135 | } | 150 | } |
136 | var postListArr = testDayPostList.idArray; | 151 | var postListArr = testDayPostList.idArray; |
137 | - var newPost = new postModel({ date: today, title: req.body.title, content: req.body.content, password: req.body.password }); | 152 | + var newPost = new postModel({ date: today, time:time, title: req.body.title, content: req.body.content, password: req.body.password }); |
138 | var newPostData = await newPost.save(); | 153 | var newPostData = await newPost.save(); |
139 | postListArr.push(newPostData._id.toString()); | 154 | postListArr.push(newPostData._id.toString()); |
140 | 155 | ||
... | @@ -166,9 +181,9 @@ router.delete('/api/delete/:id', async (req, res) => { | ... | @@ -166,9 +181,9 @@ router.delete('/api/delete/:id', async (req, res) => { |
166 | const id = req.params.id; | 181 | const id = req.params.id; |
167 | const list = await dayPostListModel.find(); | 182 | const list = await dayPostListModel.find(); |
168 | for (const dayList of list) { | 183 | for (const dayList of list) { |
169 | - var newArray = dayList.idArray.filter((data)=>{return data != id;}) | 184 | + var newArray = dayList.idArray.filter((data) => { return data != id; }) |
170 | - if(!arrayEquals(dayList.idArray, newArray)){ | 185 | + if (!arrayEquals(dayList.idArray, newArray)) { |
171 | - await dayPostListModel.findByIdAndUpdate(dayList._id.toString(), {idArray: newArray}); | 186 | + await dayPostListModel.findByIdAndUpdate(dayList._id.toString(), { idArray: newArray }); |
172 | } | 187 | } |
173 | } | 188 | } |
174 | await postModel.findByIdAndDelete(id); | 189 | await postModel.findByIdAndDelete(id); |
... | @@ -195,8 +210,8 @@ router.get('/api/waiting', async (req, res) => { | ... | @@ -195,8 +210,8 @@ router.get('/api/waiting', async (req, res) => { |
195 | const time = Number(hour + minute); | 210 | const time = Number(hour + minute); |
196 | 211 | ||
197 | var result = []; | 212 | var result = []; |
198 | - for(const waiting of waitingList){ | 213 | + for (const waiting of waitingList) { |
199 | - if(time - Number(waiting.time.replace(':','')) <= 100){ | 214 | + if (time - Number(waiting.time.replace(':', '')) <= 100) { |
200 | result.push(waiting) | 215 | result.push(waiting) |
201 | } | 216 | } |
202 | } | 217 | } |
... | @@ -212,18 +227,13 @@ router.post('/api/waiting', async (req, res) => { | ... | @@ -212,18 +227,13 @@ router.post('/api/waiting', async (req, res) => { |
212 | const today = getCurrentDate(); | 227 | const today = getCurrentDate(); |
213 | var waitingList = await waitingModel.findOne({ date: today }); | 228 | var waitingList = await waitingModel.findOne({ date: today }); |
214 | 229 | ||
215 | - const date = new Date(); | 230 | + const time = getCurrentTime(); |
216 | - var hour = date.getHours(); | 231 | + const newWaiting = { value: req.body.value, time: time }; |
217 | - hour = hour < 10 ? '0' + hour.toString() : hour.toString(); | ||
218 | - var minute = date.getMinutes(); | ||
219 | - minute = minute < 10 ? '0' + minute.toString() : minute.toString(); | ||
220 | - const time = hour + ":" + minute; | ||
221 | - const newWaiting = {value: req.body.value, time: time}; | ||
222 | 232 | ||
223 | - if (waitingList == null) await waitingModel({date: today, waiting: [newWaiting]}).save(); | 233 | + if (waitingList == null) await waitingModel({ date: today, waiting: [newWaiting] }).save(); |
224 | - else{ | 234 | + else { |
225 | waitingList.waiting.push(newWaiting); | 235 | waitingList.waiting.push(newWaiting); |
226 | - await waitingModel.findOneAndUpdate({ date: today }, {waiting: waitingList.waiting}); | 236 | + await waitingModel.findOneAndUpdate({ date: today }, { waiting: waitingList.waiting }); |
227 | } | 237 | } |
228 | 238 | ||
229 | var waitingListResult = await waitingModel.findOne({ date: today }); | 239 | var waitingListResult = await waitingModel.findOne({ date: today }); |
... | @@ -235,7 +245,8 @@ router.post('/api/waiting', async (req, res) => { | ... | @@ -235,7 +245,8 @@ router.post('/api/waiting', async (req, res) => { |
235 | }); | 245 | }); |
236 | 246 | ||
237 | 247 | ||
238 | -function setting(resultJson){ | 248 | + |
249 | +function setting(resultJson) { | ||
239 | var result = {} | 250 | var result = {} |
240 | result.fo_date = [resultJson.fo_date1, resultJson.fo_date2, resultJson.fo_date3, resultJson.fo_date4, resultJson.fo_date5]; | 251 | result.fo_date = [resultJson.fo_date1, resultJson.fo_date2, resultJson.fo_date3, resultJson.fo_date4, resultJson.fo_date5]; |
241 | result.fo_menu_lun = [resultJson.fo_menu_lun1, resultJson.fo_menu_lun2, resultJson.fo_menu_lun3, resultJson.fo_menu_lun4, resultJson.fo_menu_lun5]; | 252 | result.fo_menu_lun = [resultJson.fo_menu_lun1, resultJson.fo_menu_lun2, resultJson.fo_menu_lun3, resultJson.fo_menu_lun4, resultJson.fo_menu_lun5]; |
... | @@ -298,12 +309,12 @@ router.get('/api/todayMenu', async (req, res) => { | ... | @@ -298,12 +309,12 @@ router.get('/api/todayMenu', async (req, res) => { |
298 | newRequest.onreadystatechange = () => { | 309 | newRequest.onreadystatechange = () => { |
299 | if (newRequest.status == 200 && newRequest.readyState == 4) { | 310 | if (newRequest.status == 200 && newRequest.readyState == 4) { |
300 | var dt = new Date(); | 311 | var dt = new Date(); |
301 | - if(dt.getDay() > 0 && dt.getDay() < 6){ | 312 | + if (dt.getDay() > 0 && dt.getDay() < 6) { |
302 | resJSON = JSON.parse(newRequest.responseText).root[0].WEEKLYMENU[0]; | 313 | resJSON = JSON.parse(newRequest.responseText).root[0].WEEKLYMENU[0]; |
303 | const weekMenu = setting(resJSON); | 314 | const weekMenu = setting(resJSON); |
304 | - const todayMenu = [weekMenu.fo_menu_lun[dt.getDay()-1], weekMenu.fo_menu_eve[dt.getDay()-1]]; | 315 | + const todayMenu = [weekMenu.fo_menu_lun[dt.getDay() - 1], weekMenu.fo_menu_eve[dt.getDay() - 1]]; |
305 | res.send(todayMenu); | 316 | res.send(todayMenu); |
306 | - }else res.send("weekend"); | 317 | + } else res.send("weekend"); |
307 | 318 | ||
308 | } | 319 | } |
309 | } | 320 | } | ... | ... |
-
Please register or login to post a comment