gasordine
This commit is contained in:
@@ -12,6 +12,7 @@ const Product = require('../models/product');
|
||||
const ProductInfo = require('../models/productInfo');
|
||||
const CatProd = require('../models/catprod');
|
||||
const SubCatProd = require('../models/subcatprod');
|
||||
const Gasordine = require('../models/gasordine');
|
||||
|
||||
var { authenticate } = require('../middleware/authenticate');
|
||||
|
||||
@@ -146,18 +147,23 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
|
||||
// Cerca il GAS
|
||||
let recGas = null;
|
||||
if (prod.gas_name) {
|
||||
if (product.gas_name) {
|
||||
// Cerca il GAS
|
||||
recGas = await Gasordine.findOne({ idapp, name: prod.gas_name }).lean();
|
||||
recGas = await Gasordine.findOne({ idapp, name: product.gas_name }).lean();
|
||||
}
|
||||
|
||||
if (!recGas) {
|
||||
recGas = new Gasordine({ idapp, name: product.gas_name, active: true });
|
||||
// Non esiste questo GAS, quindi lo creo !
|
||||
ris = await recGas.save();
|
||||
recGas = await Gasordine.findOne({ idapp, name: product.gas_name }).lean();
|
||||
}
|
||||
|
||||
let recProductExist = null;
|
||||
let queryprod = { idProductInfo: product.idProductInfo };
|
||||
|
||||
if (recGas) {
|
||||
queryprod = {...queryprod, gas}
|
||||
} else {
|
||||
recProductExist = await Product.findOne().lean();
|
||||
queryprod = {...queryprod, idGasordine: recGas._id};
|
||||
}
|
||||
|
||||
recProductExist = await Product.findOne({ queryprod }).lean();
|
||||
@@ -166,15 +172,15 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
isnuovo = true;
|
||||
}
|
||||
|
||||
if (!options.aggiornaStockQty && esisteindb) {
|
||||
if (!options.aggiornaStockQty && esisteindb && !isnuovo) {
|
||||
delete product.stockQty;
|
||||
delete product.maxbookableGASQty;
|
||||
}
|
||||
|
||||
// AGGIORNA PRODUCT
|
||||
let risrec = await Product.findOneAndUpdate({ idProductInfo: product.idProductInfo }, { $set: product }, { new: true, upsert: true });
|
||||
let risrec = await Product.findOneAndUpdate(queryprod, { $set: product }, { new: true, upsert: true });
|
||||
|
||||
let recnew = await Product.findOne({ idProductInfo: product.idProductInfo }).lean();
|
||||
let recnew = await Product.findOne(queryprod).lean();
|
||||
|
||||
if (risrec) {
|
||||
if (risrec._id) {
|
||||
|
||||
Reference in New Issue
Block a user