Каждый раз, когда я пытаюсь отправить почтовый запрос в почтальоне на http://localhost: 3000 / api / orders / new
, я получаю эту ошибку: ** TypeError: невозможно деструктурировать свойство userId для req.body, поскольку оно не определено. в C: \ Users \ Web-Developer \ Desktop \ shoppy \ backend \ routes \ orders. js: 70: 10 в Layer.handle [как handle_request] (C: \ Users \ Web-Developer \ Desktop \ shoppy \ backend \ node_modules \ express \ lib \ router \ layer. js: 95: 5) в следующий (C: \ Users \ Web-Developer \ Desktop \ shoppy \ backend \ node_modules \ express \ lib \ router \ route. js: 137: 13) в Route.dispatch (C: \ Users \ Web-Developer \ Desktop \ shoppy \ backend \ node_modules \ express \ lib \ router \ route. js: 112: 3 ) в Layer.handle [как handle_request] (C: \ Users \ Web-Developer \ Desktop \ shoppy \ backend \ node_modules \ express \ lib \ router \ layer. js: 95: 5) в C: \ Users \ Web-Developer \ Desktop \ shoppy \ backend \ node_modules \ express \ lib \ router \ index. js: 281: 22 в Function.process_params (C: \ Users \ Web-Developer \ Desktop \ shoppy \ backend \ node_modules \ express \ lib \ router \ index. js: 335: 12) в следующем (C: \ Users \ Web-Developer \ Desktop \ shoppy \ backend \ node_modules \ express \ lib \ router \ index. js: 275: 10) в Function.handle (C: \ Users \ Web-Developer \ Desktop \ shoppy \ backend \ node_modules \ express \ lib \ router \ index. js: 174: 3) на маршрутизаторе (C: \ Users \ Web-Developer \ Desktop \ shoppy \ backend \ node_modules \ express \ lib \ router \ index. js: 47: 12) **
const router = express.Router();
const {database} = require('../config/helpers');
/* GET ALL ORDERS */
router.get('/', (req, res) => {
database.table('orders_details as od')
.join([
{
table: 'orders as o',
on: 'o.id = od.order_id'
},
{
table: 'products as p',
on: 'p.id = od.product_id'
},
{
table: 'users as u',
on: 'u.id = o.user_id'
}
])
.withFields(['o.id', 'p.title as name', 'p.description', 'p.price', 'u.username'])
.sort({id: 1})
.getAll()
.then(orders => {
if(orders.length > 0) {
res.status(200).json(orders);
} else {
res.json({message: 'Mo Orders Found'})
}
}).catch(err => console.log(err));
})
/* GET SINGLE ORDER */
router.get('/:id', (req, res) => {
const orderId = req.params.id;
database.table('orders_details as od')
.join([
{
table: 'orders as o',
on: 'o.id = od.order_id'
},
{
table: 'products as p',
on: 'p.id = od.product_id'
},
{
table: 'users as u',
on: 'u.id = o.user_id'
}
])
.withFields(['o.id', 'p.title as name', 'p.description', 'p.price', 'u.username'])
.filter({'o.id': orderId})
.getAll()
.then(orders => {
if(orders.length > 0) {
res.status(200).json(orders);
} else {
res.json({message: `No Orders Found with orderId ${orderId}`})
}
}).catch(err => console.log(err));
})
/* PLACE A NEW ORDER */
router.post('/new', (req, res) => {
let {userId, products} = req.body;
console.log(userId, products)
})
module.exports = router