aggio gasordine
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -144,7 +144,24 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
let recProductExist = await Product.findOne({ idProductInfo: product.idProductInfo }).lean();
|
||||
// Cerca il GAS
|
||||
let recGas = null;
|
||||
if (prod.gas_name) {
|
||||
// Cerca il GAS
|
||||
recGas = await Gasordine.findOne({ idapp, name: prod.gas_name }).lean();
|
||||
}
|
||||
|
||||
let recProductExist = null;
|
||||
let queryprod = { idProductInfo: product.idProductInfo };
|
||||
|
||||
if (recGas) {
|
||||
queryprod = {...queryprod, gas}
|
||||
} else {
|
||||
recProductExist = await Product.findOne().lean();
|
||||
}
|
||||
|
||||
recProductExist = await Product.findOne({ queryprod }).lean();
|
||||
|
||||
if (!recProductExist) {
|
||||
isnuovo = true;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ router.post('/', auth_default, async function (req, res, next) {
|
||||
if (products)
|
||||
res.send({ code: server_constants.RIS_CODE_OK, products, orders });
|
||||
else
|
||||
res.status(400).send(e);
|
||||
res.status(400).send({ code: server_constants.RIS_CODE_OK, products, orders });
|
||||
|
||||
/*
|
||||
const { query, order } = tools.categorizeQueryString(req.query)
|
||||
|
||||
@@ -1330,6 +1330,16 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
||||
} catch (e) {
|
||||
console.error('Err:', e);
|
||||
}
|
||||
} else if (mydata.dbop === 'SistemaGasOrdine') {
|
||||
const arrrec = await Product.find({}).lean();
|
||||
for (const rec of arrrec) {
|
||||
if (tools.isArray(rec.idGasordines) && rec.idGasordines.length > 0) {
|
||||
await Product.findByIdAndUpdate(rec._id, { $set: { idGasordine: rec.idGasordines[0] } })
|
||||
} else {
|
||||
await Product.findByIdAndUpdate(rec._id, { $set: { idGasordine: null } })
|
||||
}
|
||||
}
|
||||
|
||||
} else if (mydata.dbop === 'CopyPriceToCalc') {
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user