Seleziona l'ordine GAS e compare sulla email

This commit is contained in:
Surya Paolo
2023-12-24 00:55:49 +01:00
parent 0eb287db06
commit f0495d93b3
5 changed files with 72 additions and 7 deletions

View File

@@ -100,6 +100,7 @@ const productSchema = new Schema({
minBuyQty: { // quantità minima acquistabile
type: Number,
default: 1,
required: true,
},
stockQty: { // in magazzino
type: Number,
@@ -175,7 +176,7 @@ module.exports.getFieldsForSearch = function () {
return [
{ field: 'name', type: tools.FieldType.string },
{ field: 'description', type: tools.FieldType.string },
]
]
};
module.exports.executeQueryTable = function (idapp, params) {
@@ -251,6 +252,34 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
as: 'gasordines'
}
},
{
$unwind: {
path: '$gasordines',
preserveNullAndEmptyArrays: true,
},
},
{
$match: {
$or: [
{ 'gasordines.active': true }, // Include documents where gasordines.active is true
{ 'gasordines': { $exists: false } } // Include documents where gasordines array doesn't exist
]
}
},
{
$group: {
_id: '$_id',
gasordines: { $push: '$gasordines' },
originalFields: { $first: '$$ROOT' } // Preserve all existing fields
}
},
{
$replaceRoot: {
newRoot: {
$mergeObjects: ['$originalFields', { gasordines: '$gasordines' }]
}
}
},
{
$unwind: {
path: '$producer',
@@ -438,10 +467,10 @@ module.exports.getProductByID = function (id, callback) {
}
module.exports.updateProductInOrder = async function (order) {
if (order.product)
order.product = await Product.getProductById(order.product._id);
return order;
}
@@ -467,6 +496,7 @@ module.exports.singlerecconvert_AfterImport = async function (idapp, prod) {
let objtoset = {
idapp,
img: 'upload/products/' + prod.code + '.jpg',
minBuyQty: 1,
}
if (prod.producer_name) {
@@ -552,5 +582,5 @@ module.exports.singlerecconvert_AfterImport = async function (idapp, prod) {
} catch (e) {
console.error('Err', e);
}
}