Spaces:
Runtime error
Runtime error
Download controllers/orderController.js from Beshoy-mounir/firstapp: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/spaces/Beshoy-mounir/firstapp/resolve/main/controllers/orderController.js
- Command line
-
hf download hf://spaces/Beshoy-mounir/firstapp/controllers/orderController.js
-
curl -L -o orderController.js https://huggingface.co/spaces/Beshoy-mounir/firstapp/resolve/main/controllers/orderController.js
1.4 kB
| const Order = require('../models/orderModel'); | |
| const catchAsync = require('../utils/catchAsync'); | |
| // GET ALL ORDERS | |
| exports.getAllOrders = catchAsync(async (req, res) => { | |
| const orders = await Order.find().populate('user').populate('items.product'); | |
| res.status(200).json({ | |
| status: 'success', | |
| results: orders.length, | |
| data: { orders }, | |
| }); | |
| }); | |
| // GET ONE ORDER | |
| exports.getOrder = catchAsync(async (req, res) => { | |
| const order = await Order.findById(req.params.id) | |
| .populate('user') | |
| .populate('items.product'); | |
| if (!order) { | |
| return res.status(404).json({ | |
| status: 'fail', | |
| message: 'Order not found', | |
| }); | |
| } | |
| res.status(200).json({ | |
| status: 'success', | |
| data: { order }, | |
| }); | |
| }); | |
| // CREATE ORDER | |
| exports.createOrder = catchAsync(async (req, res) => { | |
| const order = await Order.create(req.body); | |
| res.status(201).json({ | |
| status: 'success', | |
| data: { order }, | |
| }); | |
| }); | |
| // UPDATE ORDER | |
| exports.updateOrder = catchAsync(async (req, res) => { | |
| const order = await Order.findByIdAndUpdate(req.params.id, req.body, { | |
| new: true, | |
| runValidators: true, | |
| }); | |
| res.status(200).json({ | |
| status: 'success', | |
| data: { order }, | |
| }); | |
| }); | |
| // DELETE ORDER | |
| exports.deleteOrder = catchAsync(async (req, res) => { | |
| await Order.findByIdAndDelete(req.params.id); | |
| res.status(204).json({ | |
| status: 'success', | |
| data: null, | |
| }); | |
| }); | |