- corretto cancellazione ordine
This commit is contained in:
@@ -608,6 +608,52 @@ module.exports.getTotalOrderById = async function (id) {
|
||||
return await Order.aggregate(query);
|
||||
}
|
||||
|
||||
module.exports.RemoveDeletedOrdersInOrderscart = async function () {
|
||||
try {
|
||||
const OrdersCart = require('./orderscart');
|
||||
|
||||
// Cancella gli Ordini che non esistono in OrdersCart
|
||||
const arrorders = await OrdersCart.find({}).lean();
|
||||
for (const rec of arrorders) {
|
||||
let recordercart = await OrdersCart.getOrdersCartById(rec._id);
|
||||
|
||||
let arrord = []
|
||||
let cambiare = false;
|
||||
for (const recOrd of recordercart.items) {
|
||||
if (recOrd.order) {
|
||||
arrord.push(recOrd)
|
||||
} else {
|
||||
cambiare = true;
|
||||
}
|
||||
}
|
||||
if (cambiare) {
|
||||
await OrdersCart.findOneAndUpdate({ _id: recordercart._id }, { $set: { items: arrord } }, { new: false });
|
||||
}
|
||||
}
|
||||
|
||||
// Controllo se Order non esiste in OrdersCart
|
||||
const arrord = await Order.find({}).lean();
|
||||
for (const ord of arrord) {
|
||||
const idtofind = ord._id;
|
||||
|
||||
await OrdersCart.findOne({ 'items.order': { $in: [idtofind] } })
|
||||
.then(async (orderCart) => {
|
||||
if (!orderCart) {
|
||||
// NON TROVATO ! Allora lo cancello
|
||||
|
||||
await Order.findOneAndRemove({ _id: ord._id });
|
||||
}
|
||||
})
|
||||
.catch(err => console.error(err));
|
||||
}
|
||||
|
||||
|
||||
} catch (e) {
|
||||
console.error('Err', e);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
module.exports.GeneraCSVOrdineProdotti = async function () {
|
||||
|
||||
const myidGasordine = '65c2a8cc379ee4f57e865ee7';
|
||||
|
||||
Reference in New Issue
Block a user