From 306c59e56c5038d13f94b9477bcdd060ab282ee6 Mon Sep 17 00:00:00 2001 From: Mateja Date: Tue, 27 Jul 2021 18:32:14 +0200 Subject: Add API endpoint for paid orders. --- server/controllers/transaction.js | 15 +++++++++++++++ server/routes/api.js | 5 +++-- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'server') diff --git a/server/controllers/transaction.js b/server/controllers/transaction.js index 9edb778..5143c2d 100644 --- a/server/controllers/transaction.js +++ b/server/controllers/transaction.js @@ -127,6 +127,21 @@ module.exports = { res.status(500).json({status: "Couldn't update order in database!"}) console.error(err); }); + }, + + async showPaid(req, res) { + const orders = await Order.find({status: 'paid'}); + let formattedResponse = []; + + orders.forEach(order => { + formattedResponse.push({ + shipping: order.shipping, + items: order.items, + updatedAt: order.updatedAt + }); + }); + + res.json(formattedResponse); } }; diff --git a/server/routes/api.js b/server/routes/api.js index feea5dd..cf1d2d6 100644 --- a/server/routes/api.js +++ b/server/routes/api.js @@ -17,7 +17,8 @@ router.post('/products', isAuth, isAdmin, upload.single('image'), productsContro router.patch('/products/:id', isAuth, isAdmin, upload.single('image'), productsController.update); router.delete('/products/:id', isAuth, isAdmin, productsController.destroy); -router.post('/transaction/setup', transactionController.setup); -router.post('/transaction/capture', transactionController.capture); +router.get('/transactions/paid', transactionController.showPaid); +router.post('/transactions/setup', transactionController.setup); +router.post('/transactions/capture', transactionController.capture); module.exports = router; -- cgit v1.2.3