- edit campi prodotti
- edit ordini
This commit is contained in:
@@ -106,6 +106,7 @@ module.exports.updateCartByCartId = async function (cartId, newCart) {
|
||||
const items = newCart.items;
|
||||
const totalQty = newCart.totalQty;
|
||||
const totalPrice = newCart.totalPrice;
|
||||
const note = newCart.note;
|
||||
|
||||
const modify_at = new Date();
|
||||
|
||||
@@ -114,7 +115,8 @@ module.exports.updateCartByCartId = async function (cartId, newCart) {
|
||||
items,
|
||||
totalPrice,
|
||||
totalQty,
|
||||
modify_at,
|
||||
note,
|
||||
modify_at: new Date(),
|
||||
},
|
||||
}, { new: false }).lean().then((ris) => {
|
||||
return ris;
|
||||
|
||||
@@ -282,6 +282,19 @@ module.exports.updateStatusOrdersElements = async function (arrOrders, myelement
|
||||
|
||||
}
|
||||
|
||||
module.exports.updateOrderByParams = async function (idOrder, paramstoupdate) {
|
||||
|
||||
const ris = await Order.findOneAndUpdate({ _id: idOrder }, { $set: paramstoupdate });
|
||||
|
||||
let myorder = await Order.findOne({ _id: idOrder }).lean();
|
||||
|
||||
this.updateTotals(myorder);
|
||||
|
||||
await Order.findOneAndUpdate({ _id: idOrder }, { $set: myorder });
|
||||
|
||||
return myorder;
|
||||
}
|
||||
|
||||
module.exports.updateTotals = function (order) {
|
||||
|
||||
try {
|
||||
|
||||
@@ -14,6 +14,9 @@ const ProductInfo = require('../models/productInfo');
|
||||
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
const CartClass = require('../modules/Cart')
|
||||
const Cart = require('../models/cart');
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
@@ -794,6 +797,46 @@ OrdersCartSchema.pre('save', async function (next) {
|
||||
}
|
||||
});
|
||||
|
||||
module.exports.updateOrdersCartByParams = async function (idOrdersCart, paramstoupdate) {
|
||||
|
||||
const ris = await OrdersCart.findOneAndUpdate({ _id: idOrdersCart }, { $set: paramstoupdate });
|
||||
|
||||
let myorderscart = await Order.findOne({ _id: idOrder });
|
||||
|
||||
return myorderscart;
|
||||
}
|
||||
|
||||
|
||||
module.exports.updateOrdersCartTotals = async function (idOrdersCart, update) {
|
||||
|
||||
try {
|
||||
let orderscart = await OrdersCart.getOrdersCartById(idOrdersCart);
|
||||
if (orderscart) {
|
||||
|
||||
let newOrdersCart = CartClass.constructByCart(orderscart);
|
||||
|
||||
await newOrdersCart.updatetotals();
|
||||
|
||||
if (update) {
|
||||
await OrdersCart.findOneAndUpdate({ _id: idOrdersCart }, {
|
||||
$set: {
|
||||
totalPrice: newOrdersCart.totalPrice,
|
||||
totalQty: newOrdersCart.totalQty,
|
||||
note: newOrdersCart.note,
|
||||
modify_at: new Date(),
|
||||
},
|
||||
}
|
||||
)
|
||||
}
|
||||
orderscart = await OrdersCart.getOrdersCartById(idOrdersCart);
|
||||
|
||||
return orderscart;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('err', e);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.getmsgorderTelegram = async function (ordersCart) {
|
||||
try {
|
||||
const statusstr = shared_consts.getStatusStr(ordersCart.status);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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