aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/src/store/index.js4
-rw-r--r--server/controllers/transaction.js15
-rw-r--r--server/routes/api.js5
3 files changed, 20 insertions, 4 deletions
diff --git a/client/src/store/index.js b/client/src/store/index.js
index 7c3d396..ff4648f 100644
--- a/client/src/store/index.js
+++ b/client/src/store/index.js
@@ -85,7 +85,7 @@ export default createStore({
const checkoutRequest = {items: context.state.cart};
const orderId = await axios
- .post(`${process.env.VUE_APP_ROOT_API}/transaction/setup`, checkoutRequest)
+ .post(`${process.env.VUE_APP_ROOT_API}/transactions/setup`, checkoutRequest)
.then(response => response.data.orderId)
.catch(err => console.error(err));
@@ -93,7 +93,7 @@ export default createStore({
},
async captureOrder(context, orderId) {
return await axios
- .post(`${process.env.VUE_APP_ROOT_API}/transaction/capture`, {orderId})
+ .post(`${process.env.VUE_APP_ROOT_API}/transactions/capture`, {orderId})
.then(() => true)
.catch(err => console.error(err));
}
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;