- edit campi prodotti
- edit ordini
This commit is contained in:
@@ -360,7 +360,7 @@ router.post('/:userId/ordercartstatus', authenticate, async function (req, res,
|
||||
const { User } = require('../models/user');
|
||||
|
||||
|
||||
let orderCart = await OrdersCart.findOne({ idapp, _id: order_id }).lean();
|
||||
let orderscart = await OrdersCart.findOne({ idapp, _id: order_id }).lean();
|
||||
|
||||
if ((userId !== String(req.user._id)) && !User.isManager(req.user.perm)) {
|
||||
// I'm trying to write something not mine!
|
||||
@@ -368,19 +368,19 @@ router.post('/:userId/ordercartstatus', authenticate, async function (req, res,
|
||||
}
|
||||
|
||||
try {
|
||||
if (!!orderCart) {
|
||||
if (!!orderscart) {
|
||||
|
||||
let fields_to_update = { status };
|
||||
|
||||
await OrdersCart.findOneAndUpdate({ _id: order_id }, { $set: fields_to_update }
|
||||
, { new: false })
|
||||
.then(async (ris) => {
|
||||
const userDest = await User.findById(orderCart.userId).lean();
|
||||
const userDest = await User.findById(ordersCart.userId).lean();
|
||||
|
||||
if (ris) {
|
||||
|
||||
// Aggiorna gli Stati Interni !
|
||||
orderCart = await OrdersCart.updateCmd(orderCart, status, true, options);
|
||||
ordersCart = await OrdersCart.updateCmd(ordersCart, status, true, options);
|
||||
|
||||
let ordertype = '';
|
||||
|
||||
@@ -393,7 +393,7 @@ router.post('/:userId/ordercartstatus', authenticate, async function (req, res,
|
||||
}
|
||||
|
||||
if (ordertype !== '') {
|
||||
sendemail.sendEmail_Order(userDest.lang, idapp, orderCart, userDest, ordertype, status)
|
||||
sendemail.sendEmail_Order(userDest.lang, idapp, ordersCart, userDest, ordertype, status)
|
||||
.then((ris) => {
|
||||
|
||||
})
|
||||
|
||||
@@ -42,6 +42,52 @@ router.get('/:userId', authenticate, function (req, res, next) {
|
||||
|
||||
});
|
||||
|
||||
router.post('/updateord', authenticate, async (req, res) => {
|
||||
const idOrdersCart = req.body.idOrdersCart;
|
||||
const idOrder = req.body.idOrder;
|
||||
const paramstoupdate = req.body.paramstoupdate;
|
||||
|
||||
try {
|
||||
// Aggiorno l'Ordine Singolo
|
||||
await Order.updateOrderByParams(idOrder, paramstoupdate);
|
||||
|
||||
// Aggiorno il Totale degli Ordini (OrdersCart)
|
||||
await OrdersCart.updateOrdersCartTotals(idOrdersCart, true)
|
||||
.then((orderscart) => {
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, orderscart });
|
||||
}).catch(err => {
|
||||
console.log('ERR:', err);
|
||||
res.status(400).send();
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Err', e);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
router.post('/update', authenticate, async (req, res) => {
|
||||
const idOrdersCart = req.body.idOrdersCart;
|
||||
const paramstoupdate = req.body.paramstoupdate;
|
||||
|
||||
try {
|
||||
// Aggiorno Orderscart con i parametri passati
|
||||
await OrdersCart.updateOrdersCartByParams(idOrdersCart, paramstoupdate);
|
||||
|
||||
// Aggiorno il Totale degli Ordini (OrdersCart)
|
||||
await OrdersCart.updateOrdersCartTotals(idOrdersCart, true)
|
||||
.then((orderscart) => {
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, orderscart });
|
||||
}).catch(err => {
|
||||
console.log('ERR:', err);
|
||||
res.status(400).send();
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Err', e);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
router.post('/sendmail', authenticate, async function (req, res, next) {
|
||||
const idOrdersCart = req.body.idOrdersCart;
|
||||
const idapp = req.body.idapp;
|
||||
@@ -57,8 +103,8 @@ router.post('/sendmail', authenticate, async function (req, res, next) {
|
||||
let emailto = userto.email;
|
||||
|
||||
if (userto && emailto) {
|
||||
const emailsend = await sendemail.sendEmail_byTemplate (idapp, userto, previewonly, emailto, templemail_id, test);
|
||||
|
||||
const emailsend = await sendemail.sendEmail_byTemplate(idapp, userto, previewonly, emailto, templemail_id, test);
|
||||
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, emailsend });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,4 +74,18 @@ router.post('/:code', auth_default, async function (req, res, next) {
|
||||
|
||||
});
|
||||
|
||||
router.get('/id/:id', async function (req, res) {
|
||||
|
||||
const id = req.params.id;
|
||||
|
||||
var product = await Product.getProductById(id);
|
||||
|
||||
if (product) {
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, product: product });
|
||||
} else {
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, product: null });
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user