- filtro se GAS o Prodotti
This commit is contained in:
@@ -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
|
||||
]
|
||||
}]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user