From ad47c7d739eea9be3cbe8c4ce09cb86c470bc41f Mon Sep 17 00:00:00 2001 From: Jules Date: Thu, 4 Jul 2024 16:41:46 +0200 Subject: [PATCH 1/3] feat: route pour demander la suite --- routes/api/order.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/routes/api/order.js b/routes/api/order.js index b27ef80..749b898 100644 --- a/routes/api/order.js +++ b/routes/api/order.js @@ -34,7 +34,7 @@ router.get('/:id', (req, res) => { }).then (() => { // For each food ordered, get the food_ordered data - db.collection(keys.FOOD_ORDERED_COLLECTION_NAME).find({ id: {$in: orderData.food_ordered} }).toArray().then(foodOrdered => { + db.collection(keys.FOOD_ORDERED_COLLECTION_NAME).find({ id: {$in: orderData.food_ordered}, part: orderData.part }).toArray().then(foodOrdered => { foodOrderedData = foodOrdered; }).then(() => { const foodIdList = []; @@ -203,5 +203,29 @@ router.get('/status/pending', async (req, res) => { } }); +router.get('/next/:id', async (req, res) => { + try { + await client.connect(); + const db = client.db(DB_NAME); + const collection = db.collection(keys.ORDER_COLLECTION_NAME); + + collection.findOne({ id: Number(req.params.id) }) + .then ((order) => { + const newPart = order.part + 1; + collection.updateOne({ id: Number(req.params.id) }, { $set: { part: newPart, date: new Date().toISOString() } }) + .then(() => { + res.status(200).send(); + }).catch(err => { + res.status(500).send("Error updating order in database : " + err); + }); + }).catch(err => { + res.status(500).send("Error reading order from database : " + err); + }); + + } catch (err) { + res.status(500).send("Error connecting to database: " + err); + } +}); + module.exports = router; \ No newline at end of file From beb8b41982c77b29a28a8deeb7eb7447fb68d3fa Mon Sep 17 00:00:00 2001 From: Jules Date: Thu, 4 Jul 2024 16:42:19 +0200 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20date=20et=20part=20par=20d=C3=A9fau?= =?UTF-8?q?t=20quand=20les=20commandes=20sont=20envoy=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/api/order.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api/order.js b/routes/api/order.js index 749b898..698e4a5 100644 --- a/routes/api/order.js +++ b/routes/api/order.js @@ -117,7 +117,7 @@ router.post('/', (req, res) => { const db = client.db(DB_NAME); const collection = db.collection(keys.ORDER_COLLECTION_NAME); - collection.insertOne(req.body).then(result => { + collection.insertOne({...req.body, part: 1, date: new Date().toISOString()}).then(result => { res.json(result); }).catch(err => { res.status(500).send("Error inserting order into database : " + err); From 1cdc12a92fdca9ec9e3ad2dd08f0e32a3e9efdc8 Mon Sep 17 00:00:00 2001 From: Jules Date: Thu, 4 Jul 2024 16:56:51 +0200 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20PUT=20pour=20demander=20la=20suite?= =?UTF-8?q?=20plut=C3=B4t=20que=20GET?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/api/order.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api/order.js b/routes/api/order.js index 698e4a5..6461900 100644 --- a/routes/api/order.js +++ b/routes/api/order.js @@ -203,7 +203,7 @@ router.get('/status/pending', async (req, res) => { } }); -router.get('/next/:id', async (req, res) => { +router.put('/next/:id', async (req, res) => { try { await client.connect(); const db = client.db(DB_NAME);