Aggiornamento cataloghi...
This commit is contained in:
@@ -116,7 +116,7 @@ async function findOrCreateCatProd(idapp, idArgomento, DescrArgomento) {
|
||||
function updateProductInfoCatProds(productInfo, reccatprod) {
|
||||
if (productInfo) {
|
||||
// Controllo che nell'array productInfo.idCatProds ci sia esattamente 1 record e che sia uguale a reccatprod._id
|
||||
const cond3 = Array.isArray(productInfo.idCatProds) && productInfo.idCatProds[0].toString() !== reccatprod._id.toString();
|
||||
const cond3 = Array.isArray(productInfo.idCatProds) && productInfo.idCatProds.length > 0 && productInfo.idCatProds[0].toString() !== reccatprod._id.toString();
|
||||
const isChanged =
|
||||
!Array.isArray(productInfo.idCatProds) || // Assicurati che sia un array
|
||||
productInfo.idCatProds.length !== 1 || // L'array deve contenere esattamente 1 elemento
|
||||
@@ -903,6 +903,8 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
|
||||
const trovato = await ImportaIsbn.findOne({ isbn: product.code }).lean();
|
||||
if (trovato) {
|
||||
// togli a recisbn l'_id
|
||||
delete trovato._id;
|
||||
recisbn = trovato;
|
||||
}
|
||||
|
||||
@@ -916,14 +918,18 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
recisbn.sottotitolo = productInfo.sottotitolo;
|
||||
// recisbn.idapp = idapp;
|
||||
|
||||
let risisbn = await ImportaIsbn.findOneAndUpdate({ isbn: product.code }, { $set: recisbn }, { new: true, upsert: true, strict: false });
|
||||
try {
|
||||
let risisbn = await ImportaIsbn.findOneAndUpdate({ isbn: product.code }, { $set: recisbn }, { new: true, upsert: true, strict: false });
|
||||
|
||||
// Update ProductInfo, non crea nuovi record !
|
||||
let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: false });
|
||||
// Update ProductInfo, non crea nuovi record !
|
||||
let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: false });
|
||||
|
||||
indprod++;
|
||||
if (indprod % 100 === 0)
|
||||
console.log(indprod + '/' + numprod);
|
||||
indprod++;
|
||||
if (indprod % 100 === 0)
|
||||
console.log(indprod + '/' + numprod);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1052,6 +1058,7 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
totFat: product.totFat || 0,
|
||||
vLast3M: product.vLast3M || 0,
|
||||
fatLast3M: product.fatLast3M || 0,
|
||||
fatLast6M: product.fatLast6M || 0,
|
||||
vLast6M: product.vLast6M || 0,
|
||||
vLastY: product.vLastY || 0,
|
||||
vLast2Y: product.vLast2Y || 0,
|
||||
@@ -1120,7 +1127,7 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
let imported = 0;
|
||||
let errors = 0;
|
||||
|
||||
const ripopola = false; //++MODIFICARE!
|
||||
const ripopola = true; //++MODIFICARE!
|
||||
|
||||
if (ripopola) {
|
||||
dataObjects = null;
|
||||
@@ -1221,7 +1228,12 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
|
||||
// se non esiste l'ISBN, allora me lo cerco in base a sku !
|
||||
|
||||
if (!product.isbn) {
|
||||
let trova = false
|
||||
if (product._id === '30310') {
|
||||
trova = true
|
||||
}
|
||||
|
||||
if (!product.isbn || product.isbn.startsWith('field')) {
|
||||
const rectrovare = await ImportaIsbn.findOne({ sku: product.sku }).lean();
|
||||
if (rectrovare) {
|
||||
// se l'isbn non inizia con 'field' allora è buono
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const express = require("express");
|
||||
const { getArticlesSalesHandler, exportArticlesSalesByJSON, viewTable, queryTable } = require("../controllers/articleController");
|
||||
const { getArticlesSalesHandler, exportArticlesSalesByJSON, viewTable, saveTable, queryTable } = require("../controllers/articleController");
|
||||
const { authenticate } = require("../middleware/authenticate");
|
||||
|
||||
const router = express.Router();
|
||||
@@ -9,6 +9,7 @@ router.post("/articles-sales", authenticate, getArticlesSalesHandler);
|
||||
router.post("/export-articles-sales-json", authenticate, exportArticlesSalesByJSON);
|
||||
|
||||
router.post("/view-table", authenticate, viewTable);
|
||||
router.post("/save-table", authenticate, saveTable);
|
||||
router.post("/query", authenticate, queryTable);
|
||||
|
||||
|
||||
|
||||
@@ -1160,6 +1160,7 @@ router.post('/duppage', authenticate, async (req, res) => {
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
router.post('/exppage', authenticate, async (req, res) => {
|
||||
const params = req.body;
|
||||
const idapp = req.body.idapp;
|
||||
|
||||
@@ -89,6 +89,8 @@ router.get('/id/:id', async function (req, res) {
|
||||
|
||||
var product = await Product.getProductById(id);
|
||||
|
||||
console.log('Product ID', id, product);
|
||||
|
||||
if (product) {
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, product: product });
|
||||
} else {
|
||||
|
||||
@@ -789,30 +789,30 @@ router.post('/login', checkBlocked, async (req, res) => {
|
||||
resalreadysent = true;
|
||||
}
|
||||
|
||||
res.status(401).send({ code: server_constants.RIS_CODE_LOGIN_ERR });
|
||||
resalreadysent = true;
|
||||
return res.status(401).send({ code: server_constants.RIS_CODE_LOGIN_ERR });
|
||||
} else {
|
||||
const myris = await user.generateAuthToken(req);
|
||||
|
||||
const usertosend = new User();
|
||||
|
||||
shared_consts.fieldsUserToChange().forEach((field) => {
|
||||
usertosend[field] = user[field];
|
||||
});
|
||||
|
||||
const subsExistonDb = await existSubScribe(usertosend._id, 'auth', req.get('User-Agent'));
|
||||
|
||||
res
|
||||
.header('x-auth', myris.token)
|
||||
.header('x-refrtok', myris.refreshToken)
|
||||
.send({
|
||||
usertosend,
|
||||
code: server_constants.RIS_CODE_OK,
|
||||
subsExistonDb,
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
const myris = await user.generateAuthToken(req);
|
||||
|
||||
const usertosend = new User();
|
||||
|
||||
shared_consts.fieldsUserToChange().forEach((field) => {
|
||||
usertosend[field] = user[field];
|
||||
});
|
||||
|
||||
const subsExistonDb = await existSubScribe(usertosend._id, 'auth', req.get('User-Agent'));
|
||||
|
||||
res
|
||||
.header('x-auth', myris.token)
|
||||
.header('x-refrtok', myris.refreshToken)
|
||||
.send({
|
||||
usertosend,
|
||||
code: server_constants.RIS_CODE_OK,
|
||||
subsExistonDb,
|
||||
});
|
||||
|
||||
} catch (e) {
|
||||
console.error('ERRORE IN LOGIN: ' + e.message);
|
||||
if (!resalreadysent)
|
||||
|
||||
Reference in New Issue
Block a user