Showing
1 changed file
with
21 additions
and
3 deletions
... | @@ -185,8 +185,22 @@ router.get('/api/waiting', async (req, res) => { | ... | @@ -185,8 +185,22 @@ router.get('/api/waiting', async (req, res) => { |
185 | const today = getCurrentDate(); | 185 | const today = getCurrentDate(); |
186 | var waitingList = await waitingModel.findOne({ date: today }); | 186 | var waitingList = await waitingModel.findOne({ date: today }); |
187 | if (waitingList == null) waitingList = [] | 187 | if (waitingList == null) waitingList = [] |
188 | - else waitingList = waitingList. waiting; | 188 | + else waitingList = waitingList.waiting; |
189 | - res.send(waitingList); | 189 | + |
190 | + const date = new Date(); | ||
191 | + var hour = date.getHours(); | ||
192 | + hour = hour < 10 ? '0' + hour.toString() : hour.toString(); | ||
193 | + var minute = date.getMinutes(); | ||
194 | + minute = minute < 10 ? '0' + minute.toString() : minute.toString(); | ||
195 | + const time = Number(hour + minute); | ||
196 | + | ||
197 | + var result = []; | ||
198 | + for(const waiting of waitingList){ | ||
199 | + if(time - Number(waiting.time.replace(':','')) <= 100){ | ||
200 | + result.push(waiting) | ||
201 | + } | ||
202 | + } | ||
203 | + res.send(result); | ||
190 | } | 204 | } |
191 | catch (err) { | 205 | catch (err) { |
192 | res.send(err.message); | 206 | res.send(err.message); |
... | @@ -199,7 +213,11 @@ router.post('/api/waiting', async (req, res) => { | ... | @@ -199,7 +213,11 @@ router.post('/api/waiting', async (req, res) => { |
199 | var waitingList = await waitingModel.findOne({ date: today }); | 213 | var waitingList = await waitingModel.findOne({ date: today }); |
200 | 214 | ||
201 | const date = new Date(); | 215 | const date = new Date(); |
202 | - const time = date.getHours() + ":" + date.getMinutes(); | 216 | + var hour = date.getHours(); |
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; | ||
203 | const newWaiting = {value: req.body.value, time: time}; | 221 | const newWaiting = {value: req.body.value, time: time}; |
204 | 222 | ||
205 | if (waitingList == null) await waitingModel({date: today, waiting: [newWaiting]}).save(); | 223 | if (waitingList == null) await waitingModel({date: today, waiting: [newWaiting]}).save(); | ... | ... |
-
Please register or login to post a comment