- Iscrizione Conacreis
- Ordini - Carrello
This commit is contained in:
@@ -178,8 +178,10 @@ router.post('/:userId/cartstatus', authenticate, async function (req, res, next)
|
||||
const user = req.user;
|
||||
let status = req.body.status;
|
||||
|
||||
|
||||
const mycart = await Cart.getCartByUserId(userId, idapp);
|
||||
const numorder = await OrdersCart.getNewNumOrder(userId, idapp);
|
||||
let statusOrderCart = await OrdersCart.getStatusCartByUserId(userId, idapp, numorder);
|
||||
|
||||
try {
|
||||
if (!!mycart) {
|
||||
@@ -205,7 +207,7 @@ router.post('/:userId/cartstatus', authenticate, async function (req, res, next)
|
||||
const myris = ris;
|
||||
// Cancella il Cart appena salvato in OrdersCart
|
||||
|
||||
Cart.deleteCartByCartId(mycart.id)
|
||||
return Cart.deleteCartByCartId(mycart.id)
|
||||
.then((ris) => {
|
||||
|
||||
const orders = OrdersCart.getOrdersCartByUserId(userId, idapp, numorder)
|
||||
@@ -216,7 +218,7 @@ router.post('/:userId/cartstatus', authenticate, async function (req, res, next)
|
||||
return res.send({
|
||||
code: server_constants.RIS_CODE_OK,
|
||||
status: myris.status,
|
||||
orders: orders[0]
|
||||
orders: orders
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -241,7 +243,70 @@ router.post('/:userId/cartstatus', authenticate, async function (req, res, next)
|
||||
|
||||
}
|
||||
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, status: 0 });
|
||||
}
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, status: statusOrderCart });
|
||||
} catch (e) {
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, status: 0 });
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
//POST cart
|
||||
router.post('/:userId/orderstatus', authenticate, async function (req, res, next) {
|
||||
let idapp = req.body.idapp;
|
||||
let userId = req.params.userId;
|
||||
let order_id = req.body.order_id;
|
||||
const user = req.user;
|
||||
let status = req.body.status;
|
||||
|
||||
const orderCart = await OrdersCart.find({ idapp, _id: order_id });
|
||||
|
||||
if ((userId !== String(req.user._id)) && !User.isManager(req.user.perm)) {
|
||||
// I'm trying to write something not mine!
|
||||
return res.status(404).send({ code: server_constants.RIS_CODE_TODO_CREATING_NOTMYUSER });
|
||||
}
|
||||
|
||||
try {
|
||||
if (!!orderCart) {
|
||||
|
||||
let fields_to_update = { status };
|
||||
|
||||
if (status === shared_consts.OrderStatus.RECEIVED) {
|
||||
fields_to_update = {
|
||||
status,
|
||||
completed_at: new Date()
|
||||
}
|
||||
}
|
||||
|
||||
await OrdersCart.findOneAndUpdate({ _id: order_id }, { $set: fields_to_update }
|
||||
, { new: false })
|
||||
.then((ris) => {
|
||||
|
||||
if (ris) {
|
||||
|
||||
let ordertype = '';
|
||||
|
||||
if (status === shared_consts.OrderStatus.ORDER_CONFIRMED) {
|
||||
ordertype = 'order_confirmed';
|
||||
} else if (status === shared_consts.OrderStatus.RECEIVED) {
|
||||
ordertype = 'order_completed';
|
||||
} else if (status === shared_consts.OrderStatus.CANCELED) {
|
||||
ordertype = 'order_canceled';
|
||||
}
|
||||
|
||||
if (ordertype !== '') {
|
||||
sendemail.sendEmail_Order(user.lang, idapp, orderCart[0], user, ordertype)
|
||||
.then((ris) => {
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, status });
|
||||
|
||||
}
|
||||
} catch (e) {
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, status: 0 });
|
||||
|
||||
Reference in New Issue
Block a user