aggiornamento ordini

This commit is contained in:
Surya Paolo
2023-12-14 15:20:21 +01:00
parent d0bf7e1b6a
commit ea2b7095c9
7 changed files with 246 additions and 130 deletions

View File

@@ -1,15 +1,16 @@
const express = require('express');
const router = express.Router();
const mongoose = require('mongoose').set('debug', false);
const {CfgServer} = require('../models/cfgserver');
const { CfgServer } = require('../models/cfgserver');
const shared_consts = require('../tools/shared_nodejs');
const tools = require('../tools/general');
const {City} = require('../models/city');
const { City } = require('../models/city');
const Product = require('../models/product');
var {authenticate} = require('../middleware/authenticate');
var { authenticate } = require('../middleware/authenticate');
router.post('/updateval', authenticate, async (req, res) => {
console.log('/updateval', req.body.pairval);
@@ -17,24 +18,24 @@ router.post('/updateval', authenticate, async (req, res) => {
pair = req.body.pairval;
return await CfgServer.findOneAndUpdate(
{chiave: pair.chiave, idapp, userId: pair.userId}, {$set: pair},
{new: false}).then((item) => {
// CfgServer.find({ chiave: pair.chiave }, (err, item) => {
if (!!item) {
res.status(200).send();
} else {
{ chiave: pair.chiave, idapp, userId: pair.userId }, { $set: pair },
{ new: false }).then((item) => {
// CfgServer.find({ chiave: pair.chiave }, (err, item) => {
if (!!item) {
res.status(200).send();
} else {
res.status(400).send();
}
}).catch(err => {
console.log('ERR:', err);
res.status(400).send();
}
}).catch(err => {
console.log('ERR:', err);
res.status(400).send();
});
});
});
router.post('/import', authenticate, async (req, res) => {
const cmd = req.body.cmd;
const data = [];
const data = req.body.data;
try {
const liste = require('../data/liste');
@@ -44,8 +45,21 @@ router.post('/import', authenticate, async (req, res) => {
return res.status(200).send(true);
});
} else if (cmd === shared_consts.Cmd.PRODUCTS) {
let dataObjects = JSON.parse(`[${data}]`);
return await Product.insertMany(dataObjects).then((ris) => {
Product.convertAfterImport().then((ris) => {
return res.status(200).send(true);
});
});
}
}catch (e) {
} catch (e) {
console.error('e', e);
res.status(400).send();
}