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