From c001587702e081a1a232005c2a39961f357624db Mon Sep 17 00:00:00 2001 From: Surya Paolo Date: Thu, 28 Dec 2023 21:00:02 +0100 Subject: [PATCH] - filtro se GAS o Prodotti --- emails/ecommerce/makeorder/it/html.pug | 1 + emails/ecommerce/order_confirmed/it/html.pug | 1 + src/server/models/order.js | 46 +++++++++++++++++--- src/server/models/orderscart.js | 39 ++++++++--------- src/server/models/product.js | 34 ++++++++++++++- src/server/modules/Cart.js | 2 + src/server/tools/shared_nodejs.js | 4 +- 7 files changed, 95 insertions(+), 32 deletions(-) diff --git a/emails/ecommerce/makeorder/it/html.pug b/emails/ecommerce/makeorder/it/html.pug index dac233b..ef9a697 100755 --- a/emails/ecommerce/makeorder/it/html.pug +++ b/emails/ecommerce/makeorder/it/html.pug @@ -79,6 +79,7 @@ html tr td(class="sectionContent", valign="top") p Gas Ordine: #{gasordine} + p   tr td(class="sectionContentTitle boldhigh", valign="top") p #{descr} diff --git a/emails/ecommerce/order_confirmed/it/html.pug b/emails/ecommerce/order_confirmed/it/html.pug index 347852c..4119a66 100755 --- a/emails/ecommerce/order_confirmed/it/html.pug +++ b/emails/ecommerce/order_confirmed/it/html.pug @@ -80,6 +80,7 @@ html tr td(class="sectionContent", valign="top") p Gas Ordine: #{gasordine} + p   tr td(class="sectionContentTitle boldhigh", valign="top") p #{descr} diff --git a/src/server/models/order.js b/src/server/models/order.js index 596d7bb..ba8065f 100755 --- a/src/server/models/order.js +++ b/src/server/models/order.js @@ -122,7 +122,10 @@ const orderSchema = new Schema({ }, notes: { type: String - } + }, + modify_at: { + type: Date + }, }); var Order = module.exports = mongoose.model('Order', orderSchema); @@ -270,7 +273,7 @@ module.exports.createOrder = async function (order) { module.exports.updateStatusOrders = async function (arrOrders, status) { for (const order of arrOrders) { - const ret = await this.findOneAndUpdate({ _id: order._id }, { $set: status }); + let ret = await Order.updateOne({ _id: order.order._id }, { $set: { status } }); } } @@ -278,7 +281,7 @@ module.exports.updateStatusOrders = async function (arrOrders, status) { module.exports.updateStatusOrdersElements = async function (arrOrders, myelements) { for (const order of arrOrders) { - const ret = await this.findOneAndUpdate({ _id: order._id }, { $set: myelements }); + const ret = await Order.findOneAndUpdate({ _id: order.order._id }, { $set: myelements }); } } @@ -292,6 +295,7 @@ module.exports.updateTotals = function (order) { let mypricecalc = 0; order.TotalPriceProduct = 0; + order.modify_at = new Date(); // Calcolo Sconto let sconti_da_applicare = []; @@ -461,10 +465,25 @@ module.exports.getTotalOrderById = async function (id) { $expr: { $and: [ { $eq: ['$idProduct', '$$productId'] }, - { $lt: ['$status', shared_consts.OrderStatus.ORDER_CONFIRMED] } + { + $or: [ + { + $eq: ['$status', shared_consts.OrderStatus.CHECKOUT_SENT] + }, + { + $and: [{ $lt: ['$status', shared_consts.OrderStatus.CHECKOUT_SENT] }, + { + $gt: [ + '$modify_at', + { $subtract: [new Date(), 60 * 60 * 1000] } // 1 hour in milliseconds 60 * 60 + ] + }] + } + ] + } ] } - } + }, }, { $group: { @@ -486,7 +505,22 @@ module.exports.getTotalOrderById = async function (id) { $expr: { $and: [ { $eq: ['$idProduct', '$$productId'] }, - { $lt: ['$status', shared_consts.OrderStatus.ORDER_CONFIRMED] } + { + $or: [ + { + $eq: ['$status', shared_consts.OrderStatus.CHECKOUT_SENT] + }, + { + $and: [{ $lt: ['$status', shared_consts.OrderStatus.CHECKOUT_SENT] }, + { + $gt: [ + '$modify_at', + { $subtract: [new Date(), 60 * 60 * 1000] } // 1 hour in milliseconds 60 * 60 + ] + }] + } + ] + } ] } } diff --git a/src/server/models/orderscart.js b/src/server/models/orderscart.js index 07861d1..1d124b6 100755 --- a/src/server/models/orderscart.js +++ b/src/server/models/orderscart.js @@ -188,73 +188,67 @@ module.exports.getOrdersCartByQuery = async function (query) { path: 'items.order', populate: { path: 'idProduct', - model: 'Product' - }, - }) - .populate({ - path: 'items.order', - populate: { - path: 'idProduct', + model: 'Product', populate: { path: 'idProductInfo', model: 'ProductInfo' - }, - }, + } + } }) .populate({ path: 'items.order', populate: { path: 'idProducer', model: 'Producer' - }, + } }) .populate({ path: 'items.order', populate: { path: 'idProvider', model: 'Provider' - }, + } }) .populate({ path: 'items.order', populate: { path: 'idGasordine', model: 'Gasordine' - }, + } }) .populate({ path: 'items.order', populate: { path: 'idStorehouse', model: 'Storehouse' - }, + } }) .populate({ path: 'items.order', populate: { path: 'idScontisticas', model: 'Scontistica' - }, + } }) .populate({ path: 'userId', model: 'User', - select: '_id name surname username profile', // Specify the fields you want to retrieve + select: '_id name surname username profile' }) .lean(); myorderscart = myorderscart.map(order => { - order.user = order.userId - order.userId = order.user._id + order.user = order.userId; + order.userId = order.user._id; order.items = order.items.map(item => { if (item.order) { try { - item.order.product = item.order.idProduct; - item.order.idProduct = item.order.product ? item.order.product._id : ''; - if (item.order.product.idProductInfo) { - item.order.product.productInfo = item.order.product.idProductInfo; - item.order.product.idProductInfo = item.order.product ? item.order.product.productInfo._id : ''; + if (item.order.idProduct) { + item.order.idProduct.productInfo = item.order.idProduct.productInfo ? item.order.idProduct.productInfo : {...item.order.idProduct.idProductInfo}; + item.order.idProduct.idProductInfo = item.order.idProduct.productInfo ? item.order.idProduct.productInfo._id : ''; } + item.order.product = {...item.order.idProduct}; + item.order.idProduct = item.order.product ? item.order.product._id : ''; item.order.producer = item.order.idProducer; item.order.idProducer = item.order.producer ? item.order.producer._id : ''; item.order.storehouse = item.order.idStorehouse; @@ -274,6 +268,7 @@ module.exports.getOrdersCartByQuery = async function (query) { return order; }); + return myorderscart; } diff --git a/src/server/models/product.js b/src/server/models/product.js index bea3abc..dfa2c25 100755 --- a/src/server/models/product.js +++ b/src/server/models/product.js @@ -295,7 +295,22 @@ module.exports.findAllIdApp = async function (idapp, code, id) { $expr: { $and: [ { $eq: ['$idProduct', '$$productId'] }, - { $lt: ['$status', shared_consts.OrderStatus.ORDER_CONFIRMED] } + { + $or: [ + { + $eq: ['$status', shared_consts.OrderStatus.CHECKOUT_SENT] + }, + { + $and: [{ $lt: ['$status', shared_consts.OrderStatus.CHECKOUT_SENT] }, + { + $gt: [ + '$modify_at', + { $subtract: [new Date(), 60 * 60 * 1000] } // 1 hour in milliseconds 60 * 60 + ] + }] + } + ] + } ] } } @@ -320,7 +335,22 @@ module.exports.findAllIdApp = async function (idapp, code, id) { $expr: { $and: [ { $eq: ['$idProduct', '$$productId'] }, - { $lt: ['$status', shared_consts.OrderStatus.ORDER_CONFIRMED] } + { + $or: [ + { + $eq: ['$status', shared_consts.OrderStatus.CHECKOUT_SENT] + }, + { + $and: [{ $lt: ['$status', shared_consts.OrderStatus.CHECKOUT_SENT] }, + { + $gt: [ + '$modify_at', + { $subtract: [new Date(), 60 * 60 * 1000] } // 1 hour in milliseconds 60 * 60 + ] + }] + } + ] + } ] } } diff --git a/src/server/modules/Cart.js b/src/server/modules/Cart.js index acaaac7..26555e1 100755 --- a/src/server/modules/Cart.js +++ b/src/server/modules/Cart.js @@ -90,6 +90,8 @@ class Cart { myitem.order.quantitypreordered += step; } + myitem.order.modify_at = new Date(); + this.updatetotals(); await Order.findOneAndUpdate({ _id: myitem.order._id }, { $set: myitem.order }, { new: false }); return myitem.order; diff --git a/src/server/tools/shared_nodejs.js b/src/server/tools/shared_nodejs.js index d1abfdd..8a666a1 100755 --- a/src/server/tools/shared_nodejs.js +++ b/src/server/tools/shared_nodejs.js @@ -362,8 +362,8 @@ module.exports = { value: 2, }, { - label: 'Litri (L)', - short: 'L', + label: 'Litri (Lt)', + short: 'Lt', value: 3, }, {