aggio gasordine

This commit is contained in:
Surya Paolo
2024-01-16 16:56:39 +01:00
parent 9265e9bfb3
commit d22e808626
4 changed files with 39 additions and 14 deletions

View File

@@ -38,9 +38,7 @@ const productSchema = new Schema({
idStorehouses: [
{ type: Schema.Types.ObjectId, ref: 'Storehouse' }
],
idGasordines: [
{ type: Schema.Types.ObjectId, ref: 'Gasordine' }
],
idGasordine: { type: Schema.Types.ObjectId, ref: 'Gasordine' },
idScontisticas: [
{ type: Schema.Types.ObjectId, ref: 'Scontistica' }
],
@@ -200,7 +198,7 @@ module.exports.findAllIdApp = async function (idapp, code, id, all) {
try {
if (idapp){
if (idapp) {
myfind = { idapp };
}
@@ -266,36 +264,36 @@ module.exports.findAllIdApp = async function (idapp, code, id, all) {
{
$lookup: {
from: 'gasordines',
localField: 'idGasordines',
localField: 'idGasordine',
foreignField: '_id',
as: 'gasordines'
as: 'gasordine'
}
},
{
$unwind: {
path: '$gasordines',
path: '$gasordine',
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
{ 'gasordine.active': true }, // Include documents where gasordines.active is true
{ 'gasordine': { $exists: false } } // Include documents where gasordines array doesn't exist
]
}
},
{
$group: {
_id: '$_id',
gasordines: { $push: '$gasordines' },
gasordine: { $first: '$gasordine' },
originalFields: { $first: '$$ROOT' } // Preserve all existing fields
}
},
{
$replaceRoot: {
newRoot: {
$mergeObjects: ['$originalFields', { gasordines: '$gasordines' }]
$mergeObjects: ['$originalFields', { gasordine: '$gasordine' }]
}
}
},
@@ -649,7 +647,7 @@ module.exports.singlerecconvert_AfterImport_AndSave = async function (idapp, pro
if (rec) {
objtoset = {
...objtoset,
idGasordines: [rec._id],
idGasordine: rec._id,
}
setta = true;
}