- Aggiornato node.js alla versione 22.18.1
- Aggiornato tutti i pacchetti del server all'ultima versione. - passato mongoose da versione 5 a versione 6
This commit is contained in:
@@ -124,18 +124,6 @@ router.post('/:userId', authenticate, async function (req, res, next) {
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, cart: null, myord: null });
|
||||
}
|
||||
|
||||
/*
|
||||
Cart.updateCartByUserId(
|
||||
userId,
|
||||
newCart,
|
||||
function (err, result) {
|
||||
if (err) return next(err)
|
||||
return res.status(200).json({ cart: result })
|
||||
})
|
||||
|
||||
*/
|
||||
|
||||
|
||||
} catch (e) {
|
||||
console.error('Err:', e);
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, cart: 0 });
|
||||
@@ -189,16 +177,16 @@ router.put('/:userId', authenticate, async function (req, res, next) {
|
||||
|
||||
try {
|
||||
|
||||
await Cart.getCartByUserId(userId, async function (err, c) {
|
||||
if (err) return next(err)
|
||||
let oldCart = new CartClass(c || {})
|
||||
try {
|
||||
const cart = await Cart.getCartByUserId(userId);
|
||||
|
||||
try {
|
||||
const p = await Product.getProductByID(productId);
|
||||
|
||||
await Product.getProductByID(productId, async function (err, p) {
|
||||
if (err) return next(err)
|
||||
let newCart = oldCart.add(p, productId, { color, size })
|
||||
|
||||
//exist cart in databse
|
||||
if (c.length > 0) {
|
||||
if (cart.length > 0) {
|
||||
await Cart.updateCartByUserId(
|
||||
userId,
|
||||
{
|
||||
@@ -221,17 +209,28 @@ router.put('/:userId', authenticate, async function (req, res, next) {
|
||||
totalPriceCalc: newCart.totalPriceCalc,
|
||||
userId: userId
|
||||
}
|
||||
await Cart.createCart(newCartobj, function (err, resultCart) {
|
||||
if (err) return next(err)
|
||||
res.status(201).json(resultCart)
|
||||
})
|
||||
try {
|
||||
const resultCart = await Cart.createCart(newCartobj);
|
||||
} catch (err) {
|
||||
return next(err)
|
||||
}
|
||||
res.status(201).json(resultCart);
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
const product = await Product.getProductById(productId);
|
||||
} catch (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
const product = await Product.getProductById(productId);
|
||||
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, product });
|
||||
|
||||
} catch (err) {
|
||||
return next(err)
|
||||
}
|
||||
|
||||
let oldCart = new CartClass(c || {})
|
||||
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, product });
|
||||
} catch (e) {
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, status: 0 });
|
||||
}
|
||||
@@ -295,44 +294,42 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
|
||||
if (!!mycart) {
|
||||
if (status === shared_consts.OrderStatus.CHECKOUT_SENT) {
|
||||
|
||||
// Porta tutto il Cart nell'Ordine e lo CREO
|
||||
return await OrdersCart.updateOrdersCartById(-1, myorderCart, async function (err, ris) {
|
||||
//if (err) return next(err)
|
||||
if (err)
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, status: 0 });
|
||||
else {
|
||||
try {
|
||||
const ris = await OrdersCart.updateOrdersCartById(-1, myorderCart);
|
||||
// Gestisci il risultato qui
|
||||
await Order.updateStatusOrders(mycart.items, status);
|
||||
|
||||
await Order.updateStatusOrders(mycart.items, status);
|
||||
const myris = ris;
|
||||
// Cancella il Cart appena salvato in OrdersCart
|
||||
|
||||
const myris = ris;
|
||||
// Cancella il Cart appena salvato in OrdersCart
|
||||
return Cart.deleteCartByCartId(mycart._id)
|
||||
.then((ris) => {
|
||||
|
||||
return Cart.deleteCartByCartId(mycart._id)
|
||||
.then((ris) => {
|
||||
return OrdersCart.getOrdersCartByUserId(userId, idapp, numorder)
|
||||
.then(async (orders) => {
|
||||
if (!!orders) {
|
||||
|
||||
return OrdersCart.getOrdersCartByUserId(userId, idapp, numorder)
|
||||
.then(async (orders) => {
|
||||
if (!!orders) {
|
||||
await OrdersCart.updateCmd(orders[0], status, true, req, options);
|
||||
|
||||
await OrdersCart.updateCmd(orders[0], status, true, req, options);
|
||||
|
||||
// Invia la email dell'Ordine
|
||||
sendemail.sendEmail_OrderProduct(userDest.lang, idapp, orders[0], userDest)
|
||||
.then(async (ris) => {
|
||||
myorderCart = await OrdersCart.findById(idordercart).lean();
|
||||
return res.send({
|
||||
code: server_constants.RIS_CODE_OK,
|
||||
status: myris.status,
|
||||
orders: orders,
|
||||
recOrderCart: myorderCart
|
||||
});
|
||||
// Invia la email dell'Ordine
|
||||
sendemail.sendEmail_OrderProduct(userDest.lang, idapp, orders[0], userDest)
|
||||
.then(async (ris) => {
|
||||
myorderCart = await OrdersCart.findById(idordercart).lean();
|
||||
return res.send({
|
||||
code: server_constants.RIS_CODE_OK,
|
||||
status: myris.status,
|
||||
orders: orders,
|
||||
recOrderCart: myorderCart
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
} catch (err) {
|
||||
console.error("Errore durante l'aggiornamento dell'ordine:", err);
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, status: 0 });
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -442,7 +439,7 @@ router.post('/:userId/gestord', authenticate, async function (req, res, next) {
|
||||
$match: {
|
||||
idGasordine: {
|
||||
$type: "objectId", // Checks if the field is of type ObjectId
|
||||
$eq: ObjectId(idGasordine) // Compares the value to a specific ObjectId
|
||||
$eq: new ObjectId(idGasordine) // Compares the value to a specific ObjectId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2274,7 +2274,7 @@ router.post('/upload_from_other_server/:dir', authenticate, (req, res) => {
|
||||
function uploadFile(req, res, version) {
|
||||
// console.log('/upload dir:' + dir);
|
||||
const dir = tools.invertescapeslash(req.params.dir);
|
||||
console.log('inverted = ', dir);
|
||||
console.log('uploadFile = ', dir);
|
||||
const idapp = req.user.idapp;
|
||||
|
||||
const form = new formidable.IncomingForm();
|
||||
@@ -2296,6 +2296,7 @@ function uploadFile(req, res, version) {
|
||||
try {
|
||||
|
||||
form.on('fileBegin', async function (name, file) {
|
||||
console.log('1) Uploading ' + file.originalFilename);
|
||||
const mydir = folder + '/' + file.newFilename;
|
||||
// tools.mkdirpath(mydir);
|
||||
file.path = mydir
|
||||
@@ -2303,7 +2304,7 @@ function uploadFile(req, res, version) {
|
||||
|
||||
form.on('file', async function (name, file) {
|
||||
try {
|
||||
console.log('1) Uploading ' + file.originalFilename);
|
||||
console.log('2) Uploading ' + file.originalFilename);
|
||||
const mydir = tools.getdirByIdApp(idapp) + dirmain +
|
||||
server_constants.DIR_UPLOAD + '/' + dir;
|
||||
|
||||
|
||||
@@ -7,16 +7,16 @@ const webpush = require('web-push');
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const {authenticate} = require('../middleware/authenticate');
|
||||
const { authenticate } = require('../middleware/authenticate');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
const server_constants = require('../tools/server_constants');
|
||||
|
||||
const {User} = require('../models/user');
|
||||
const { User } = require('../models/user');
|
||||
|
||||
const globalTables = require('../tools/globalTables');
|
||||
|
||||
router.post('/', (req, res) => {
|
||||
router.post('/', async (req, res) => {
|
||||
const payload = {
|
||||
title: req.body.title,
|
||||
message: req.body.message,
|
||||
@@ -28,60 +28,59 @@ router.post('/', (req, res) => {
|
||||
tag: req.body.tag,
|
||||
};
|
||||
|
||||
Subscription.find({}, (err, subscriptions) => {
|
||||
if (err) {
|
||||
console.error(`Error occurred while getting subscriptions`);
|
||||
res.status(500).json({
|
||||
error: 'Technical error occurred',
|
||||
});
|
||||
try {
|
||||
const subscriptions = await Subscription.find({});
|
||||
} catch (err) {
|
||||
console.error(`Error occurred while getting subscriptions`);
|
||||
res.status(500).json({
|
||||
error: 'Technical error occurred',
|
||||
});
|
||||
}
|
||||
|
||||
} else {
|
||||
let parallelSubscriptionCalls = subscriptions.map((subscription) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const pushSubscription = {
|
||||
endpoint: subscription.endpoint,
|
||||
keys: {
|
||||
p256dh: subscription.keys.p256dh,
|
||||
auth: subscription.keys.auth,
|
||||
},
|
||||
};
|
||||
let parallelSubscriptionCalls = subscriptions.map((subscription) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const pushSubscription = {
|
||||
endpoint: subscription.endpoint,
|
||||
keys: {
|
||||
p256dh: subscription.keys.p256dh,
|
||||
auth: subscription.keys.auth,
|
||||
},
|
||||
};
|
||||
|
||||
const pushPayload = JSON.stringify(payload);
|
||||
const pushOptions = {
|
||||
vapidDetails: {
|
||||
subject: process.env.VAPI_KEY_SUBJECT,
|
||||
privateKey: process.env.PRIVATE_VAPI_KEY,
|
||||
publicKey: process.env.PUBLIC_VAPI_KEY,
|
||||
},
|
||||
TTL: payload.ttl,
|
||||
headers: {},
|
||||
};
|
||||
webpush.sendNotification(
|
||||
pushSubscription,
|
||||
pushPayload,
|
||||
pushOptions,
|
||||
).then((value) => {
|
||||
resolve({
|
||||
status: true,
|
||||
endpoint: subscription.endpoint,
|
||||
data: value,
|
||||
});
|
||||
}).catch((err) => {
|
||||
reject({
|
||||
status: false,
|
||||
endpoint: subscription.endpoint,
|
||||
data: err,
|
||||
});
|
||||
});
|
||||
const pushPayload = JSON.stringify(payload);
|
||||
const pushOptions = {
|
||||
vapidDetails: {
|
||||
subject: process.env.VAPI_KEY_SUBJECT,
|
||||
privateKey: process.env.PRIVATE_VAPI_KEY,
|
||||
publicKey: process.env.PUBLIC_VAPI_KEY,
|
||||
},
|
||||
TTL: payload.ttl,
|
||||
headers: {},
|
||||
};
|
||||
webpush.sendNotification(
|
||||
pushSubscription,
|
||||
pushPayload,
|
||||
pushOptions,
|
||||
).then((value) => {
|
||||
resolve({
|
||||
status: true,
|
||||
endpoint: subscription.endpoint,
|
||||
data: value,
|
||||
});
|
||||
}).catch((err) => {
|
||||
reject({
|
||||
status: false,
|
||||
endpoint: subscription.endpoint,
|
||||
data: err,
|
||||
});
|
||||
});
|
||||
q.allSettled(parallelSubscriptionCalls).then((pushResults) => {
|
||||
console.info(pushResults);
|
||||
});
|
||||
res.json({
|
||||
data: 'Push triggered',
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
q.allSettled(parallelSubscriptionCalls).then((pushResults) => {
|
||||
console.info(pushResults);
|
||||
});
|
||||
res.json({
|
||||
data: 'Push triggered',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -89,21 +88,21 @@ router.post('/', (req, res) => {
|
||||
|
||||
async function SendMsgTo(idapp, username, params) {
|
||||
|
||||
return await User.find({idapp, username}).then(async (arrusers) => {
|
||||
return await User.find({ idapp, username }).then(async (arrusers) => {
|
||||
if (arrusers !== null) {
|
||||
for (const user of arrusers) {
|
||||
await tools.sendNotificationToUser(user._id, params.title, params.content,
|
||||
params.openUrl, params.openUrl2, params.tag, params.actions, params.id).
|
||||
then(ris => {
|
||||
if (ris) {
|
||||
params.openUrl, params.openUrl2, params.tag, params.actions, params.id).
|
||||
then(ris => {
|
||||
if (ris) {
|
||||
|
||||
} else {
|
||||
// already sent the error on calling sendNotificationToUser
|
||||
}
|
||||
}).
|
||||
catch(e => {
|
||||
console.error(e.message);
|
||||
});
|
||||
} else {
|
||||
// already sent the error on calling sendNotificationToUser
|
||||
}
|
||||
}).
|
||||
catch(e => {
|
||||
console.error(e.message);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -119,10 +118,10 @@ router.post('/send', authenticate, async (req, res) => {
|
||||
let nummsg = 0;
|
||||
|
||||
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) &&
|
||||
!User.isFacilitatore(req.user.perm))) {
|
||||
!User.isFacilitatore(req.user.perm))) {
|
||||
// If without permissions, exit
|
||||
return res.status(404).
|
||||
send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
|
||||
send({ code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: '' });
|
||||
}
|
||||
|
||||
let msgcosa = 'da Inviare';
|
||||
@@ -144,7 +143,7 @@ router.post('/send', authenticate, async (req, res) => {
|
||||
});
|
||||
} catch (e) {
|
||||
return res.send(
|
||||
{code: server_constants.RIS_CODE_ERR, msg: nummsg + ` Msg ${msgcosa} !`});
|
||||
{ code: server_constants.RIS_CODE_ERR, msg: nummsg + ` Msg ${msgcosa} !` });
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -89,7 +89,7 @@ async function delNotif(res, idapp, username, id, username_call) {
|
||||
try {
|
||||
if (username === username_call) {
|
||||
|
||||
await SendNotif.findOneAndRemove({ idapp, _id: id });
|
||||
await SendNotif.findOneAndDelete({ idapp, _id: id });
|
||||
return res.send(true);
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
@@ -61,29 +61,32 @@ router.post('/', authenticate, async (req, res) => {
|
||||
myitem.createDate = new Date();
|
||||
}
|
||||
|
||||
return await myitem.save((err, subscription) => {
|
||||
if (err) {
|
||||
console.error(`Error occurred while saving subscription. Err: ${err}`);
|
||||
return res.status(500).json({
|
||||
error: 'Technical error occurred',
|
||||
});
|
||||
} else {
|
||||
// Send 201 - resource created
|
||||
// res.status(201).json({ data: 'Subscription saved.' });
|
||||
try {
|
||||
const subscription = await myitem.save();
|
||||
|
||||
// console.log('New Subscription id=', subscriptionModel.userId);
|
||||
// Send 201 - resource created
|
||||
// res.status(201).json({ data: 'Subscription saved.' });
|
||||
|
||||
// console.log('req.body', req.body)
|
||||
// console.log('New Subscription id=', subscriptionModel.userId);
|
||||
|
||||
if (req.body.options !== null) {
|
||||
tools.sendBackNotif(subscription, req.body.options);
|
||||
}
|
||||
// console.log('Subscription saved... ')
|
||||
return res.send({ data: 'Subscription saved.' });
|
||||
// console.log('req.body', req.body)
|
||||
|
||||
if (req.body.options !== null) {
|
||||
tools.sendBackNotif(subscription, req.body.options);
|
||||
}
|
||||
});
|
||||
});
|
||||
// console.log('Subscription saved... ')
|
||||
return res.send({ data: 'Subscription saved.' });
|
||||
|
||||
return subscription;
|
||||
|
||||
} catch (err) {
|
||||
console.error(`Error occurred while saving subscription. Err: ${err}`);
|
||||
return res.status(500).json({
|
||||
error: 'Technical error occurred',
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
router.delete('/del', authenticate, (req, res) => {
|
||||
@@ -92,14 +95,14 @@ router.delete('/del', authenticate, (req, res) => {
|
||||
|
||||
|
||||
const browser = req.get('User-Agent');
|
||||
Subscription.findOneAndRemove(
|
||||
Subscription.findOneAndDelete(
|
||||
{ userId: req.user._id, access: req.access, browser }).then(() => {
|
||||
res.status(200).send();
|
||||
}, () => {
|
||||
res.status(400).send();
|
||||
});
|
||||
} catch (e) {
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ const _ = require('lodash');
|
||||
const { ObjectId } = require('mongodb');
|
||||
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
router.get('/', async (req, res) => {
|
||||
|
||||
const todo = {
|
||||
// category: "personal",
|
||||
@@ -52,14 +52,12 @@ router.get('/', (req, res) => {
|
||||
newrec._id = new ObjectId();
|
||||
newrec.idapp = '8';
|
||||
|
||||
newrec.save((err, rec) => {
|
||||
if (err)
|
||||
console.log('ERROR: ', err);
|
||||
if (rec) {
|
||||
console.log('SAVED? ', rec);
|
||||
}
|
||||
|
||||
});
|
||||
const rec = await newrec.save();
|
||||
if (err)
|
||||
console.log('ERROR: ', err);
|
||||
if (rec) {
|
||||
console.log('SAVED? ', rec);
|
||||
}
|
||||
|
||||
res.send({});
|
||||
|
||||
|
||||
@@ -1102,237 +1102,6 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
||||
|
||||
await CatProd.deleteMany({ idapp });
|
||||
await SubCatProd.deleteMany({ idapp });
|
||||
} else if (mydata.dbop === 'visuStat') {
|
||||
// ris = await User.visuUtentiNonInNavi(idapp);
|
||||
//} else if (mydata.dbop === 'creaNavi') {
|
||||
// const num = await Nave.generaNave(idapp, mydata, false);
|
||||
// ris = { num };
|
||||
//} else if (mydata.dbop === 'CreaNaviPersistenti') {
|
||||
// const num = await Nave.generaNave(idapp, mydata, true);
|
||||
// ris = { num };
|
||||
/*} else if (mydata.dbop === 'delNavi') {
|
||||
await Nave.setRiga(idapp, 1);
|
||||
await Nave.setCol(idapp, 1);
|
||||
const num = await Nave.deleteOne({ idapp });
|
||||
ris = { num };
|
||||
// } else if (mydata.dbop === 'delNaviNoStarted') {
|
||||
// await Nave.setRiga(idapp, 1);
|
||||
// await Nave.setCol(idapp, 1);
|
||||
// const num = await Nave.remove({ idapp, date_start: { $gte: tools.IncDateNow(-1000 * 60 * 60 * 24 * 3) } });
|
||||
// ris = { num };
|
||||
|
||||
} else if (mydata.dbop === 'delNaviProvvisorie') {
|
||||
|
||||
ris = await Nave.delNaviProvvisorie(idapp);
|
||||
|
||||
} else if (mydata.dbop === 'visuListaNave') {
|
||||
mystr = await Nave.showListaOrd(idapp);
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'pulisciNonPresenzeInNave') {
|
||||
mystr = await Nave.pulisciNonPresenzeInNave(idapp);
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'checkInserimentiUtentiInNave') {
|
||||
mystr = await Nave.checkIfDevoAggiungereInNave(idapp);
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'visuListaIngresso') {
|
||||
mystr = await ListaIngresso.showListaOrd(idapp, false);
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'visuListaIngressoNuovi') {
|
||||
mystr = await ListaIngresso.showListaOrd(idapp, true);
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'GeneraGraduatoria') {
|
||||
mystr = await ListaIngresso.GeneraGraduatoria(idapp, true);
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'AggiornaIndiceGraduatoria') {
|
||||
mystr = await Graduatoria.AggiornaIndiceGraduatoria(idapp);
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'visuNaviUtentiEliminati') {
|
||||
ris = await Nave.visuNaviUtentiEliminati(idapp);
|
||||
} else if (mydata.dbop === 'convSubAccount') {
|
||||
ris = await User.convSubAccount(idapp);
|
||||
} else if (mydata.dbop === 'flagUtentiNaviNonPresenti') {
|
||||
ris = await User.flagUtentiNaviNonPresenti(idapp);
|
||||
} else if (mydata.dbop === 'generaFlotte') {
|
||||
ris = await NavePersistente.generaFlotte(idapp);
|
||||
} else if (mydata.dbop === 'mettiSognoePaypal') {
|
||||
ris = await User.mettiSognoePaypal(idapp, true);
|
||||
} else if (mydata.dbop === 'mettiSognoePaypalView') {
|
||||
ris = await User.mettiSognoePaypal(idapp, false);
|
||||
} else if (mydata.dbop === 'addNavePerUtentiNaviNonPresenti') {
|
||||
ris = await User.addNavePerUtentiNaviNonPresenti(idapp);
|
||||
} else if (mydata.dbop === 'creaTessituraeConv') {
|
||||
ris = await ListaIngresso.creaTessituraeConv(idapp);
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'eliminaListeIngressoNascoste') {
|
||||
ris = await ListaIngresso.eliminaListeIngressoNascoste(idapp);
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'RendiVisibileIrecordNascosti') {
|
||||
ris = await ListaIngresso.RendiVisibileIrecordNascosti(idapp);
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'convNaviTessinListaIngressoRec') {
|
||||
let num = 0;
|
||||
|
||||
|
||||
const arrnavitess = await Nave.find({ idapp, num_tess: { $gte: 3 } });
|
||||
|
||||
for (const recnave of arrnavitess) {
|
||||
if (recnave.num_tess === 3 || recnave.num_tess === 5 || recnave.num_tess === 7) {
|
||||
const ind_order = recnave.ind_order;
|
||||
|
||||
// Prima controlla se ho già 2 record dello stesso ind_order, allora non lo faccio:
|
||||
const arringr = await ListaIngresso.find({ idapp, ind_order });
|
||||
let dafare = true;
|
||||
if (arringr.length > 0) {
|
||||
const arringrtest = await ListaIngresso.find({ idapp, ind_order }).distinct('num_tess');
|
||||
if (arringr.length !== arringrtest.length) {
|
||||
dafare = false; // Ci sono 2 o piu record! pertanto probabilmente l'ho già fatto!
|
||||
}
|
||||
}
|
||||
if (dafare) {
|
||||
// const user = await User.findByOldOrder(idapp, ind_order);
|
||||
const user = await User.findByIndOrder(idapp, ind_order);
|
||||
|
||||
if (!!user) {
|
||||
//let note = recnave.num_tess;
|
||||
// Crea record ListaIngresso
|
||||
const newrecingr = await ListaIngresso.addUserInListaIngresso(idapp, user.username, user.username, user.lang, false, true, recnave.created, '', true);
|
||||
|
||||
const fieldsvalue = {
|
||||
ind_order: newrecingr.ind_order,
|
||||
num_tess: 1,
|
||||
};
|
||||
|
||||
// Aggiorna la nave con l'Ind_order nuovo e il num_tess a 1
|
||||
await Nave.findOneAndUpdate({ _id: recnave._id }, { $set: fieldsvalue }, { new: false });
|
||||
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const arrnavitess2 = await Nave.find({ idapp, num_tess: 2 });
|
||||
|
||||
for (const recnave of arrnavitess2) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
ris = { num };
|
||||
|
||||
} else if (mydata.dbop === 'initListaIngresso') {
|
||||
// const aaa = await User.updateMany({ idapp }, { $set: { 'profile.nationality': 'IT' } });
|
||||
|
||||
const num = await ListaIngresso.updateMany({ idapp }, { $set: { added: false } });
|
||||
|
||||
ris = { num };
|
||||
} else if (mydata.dbop === 'ImpostaATuttiPaypal') {
|
||||
const listautenti = await User.find({ idapp });
|
||||
let num = 0;
|
||||
for (let rec of listautenti) {
|
||||
if (!rec._doc.profile.paymenttypes.includes('paypal')) {
|
||||
rec._doc.profile.paymenttypes = [...rec._doc.profile.paymenttypes, 'paypal'];
|
||||
const user = await User.findOneAndUpdate({ _id: rec._id }, { $set: { 'profile.paymenttypes': rec._doc.profile.paymenttypes } });
|
||||
// await rec.save();
|
||||
num++;
|
||||
}
|
||||
// const num = await User.f({ idapp }, { $set: { 'profile: false } });
|
||||
}
|
||||
|
||||
|
||||
ris = { num };
|
||||
} else if (mydata.dbop === 'numtessUno') {
|
||||
const listanavi = await ListaIngresso.find({ idapp });
|
||||
let num = 0;
|
||||
for (let rec of listanavi) {
|
||||
if (!rec._doc.num_tess) {
|
||||
rec._doc.num_tess = 1;
|
||||
const risu = await ListaIngresso.findOneAndUpdate({ _id: rec._id }, { $set: { num_tess: rec._doc.num_tess } }, { new: false });
|
||||
// await rec.save();
|
||||
if (!!risu)
|
||||
num++;
|
||||
}
|
||||
// const num = await User.f({ idapp }, { $set: { 'profile: false } });
|
||||
}
|
||||
|
||||
|
||||
ris = { num };
|
||||
|
||||
} else if (mydata.dbop === 'Corregginumtess') {
|
||||
const listanavi = await Nave.find({ idapp });
|
||||
let num = 0;
|
||||
for (let rec of listanavi) {
|
||||
const myarrrec = await Nave.find({ idapp, ind_order: rec.ind_order }).sort({ riga: 1, col: 1 });
|
||||
let indextess = 1;
|
||||
for (let ind = 0; ind < myarrrec.length; ind++) {
|
||||
if (myarrrec[ind].num_tess !== indextess && myarrrec[ind].num_tess === 1) {
|
||||
myarrrec[ind].num_tess = indextess;
|
||||
const risu = await Nave.findOneAndUpdate({ _id: myarrrec[ind]._id }, { $set: { num_tess: myarrrec[ind].num_tess } }, { new: false });
|
||||
num++;
|
||||
}
|
||||
indextess++;
|
||||
}
|
||||
}
|
||||
|
||||
ris = { num };
|
||||
*/
|
||||
/*
|
||||
}
|
||||
|
||||
else if (mydata.dbop === 'CreaNaviPersistenti') {
|
||||
const listanavi = await Nave.find({ idapp }).sort({riga: 1, col: 1});
|
||||
|
||||
let params = {
|
||||
idapp
|
||||
};
|
||||
|
||||
let num = 0;
|
||||
for (let rec of listanavi) {
|
||||
let mypos = {
|
||||
idapp,
|
||||
riga: rec.riga,
|
||||
col: rec.col,
|
||||
numup: 3
|
||||
};
|
||||
tools.getRigaColByPosUp(mypos);
|
||||
let persistente = await NavePersistente.findByRigaCol(idapp, mypos.riga, mypos.col, 0);
|
||||
if (!persistente) {
|
||||
|
||||
params.date_start = rec.date_start;
|
||||
params.date_gift_chat_open = rec.date_gift_chat_open;
|
||||
params.riga = mypos.riga;
|
||||
params.col = mypos.col;
|
||||
if (rec.riga > 3) {
|
||||
params.riga1don = rec.riga;
|
||||
params.col1don = rec.col;
|
||||
} else {
|
||||
params.riga1don = rec.riga;
|
||||
params.col1don = rec.col;
|
||||
}
|
||||
if (params.riga > 0) {
|
||||
await NavePersistente.addRecordNavePersistenteByParams(params);
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ris = { num }; */
|
||||
/*} else if (mydata.dbop === 'CorreggiDataGiftChat') {
|
||||
const listanavi = await NavePersistente.find({ idapp });
|
||||
let num = 0;
|
||||
for (let rec of listanavi) {
|
||||
const fieldsvalue = {
|
||||
date_gift_chat_open: tools.AddDate(rec.date_start, -7)
|
||||
};
|
||||
const risu = await NavePersistente.findOneAndUpdate({ _id: rec._id }, { $set: fieldsvalue }, { new: false });
|
||||
if (!!risu) {
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
ris = { num };
|
||||
*/
|
||||
} else if (mydata.dbop === 'creaUtentiTest') {
|
||||
|
||||
let num = 0;
|
||||
@@ -1655,8 +1424,8 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
||||
const { City } = require('../models/city');
|
||||
const { Province } = require('../models/province');
|
||||
|
||||
await City.remove({});
|
||||
await Province.remove({});
|
||||
await City.deleteMany({});
|
||||
await Province.deleteMany({});
|
||||
|
||||
} else if (mydata.dbop === 'ConvTablesFromIntToString') {
|
||||
|
||||
@@ -1840,19 +1609,16 @@ async function ConvertiDaIntAStr(mytable) {
|
||||
myrec._doc.date_created = myrec._doc.date_updated;
|
||||
myrec._doc._id = idint + '';
|
||||
|
||||
let ris = await myrec.save((async function (err, doc) {
|
||||
if (doc) {
|
||||
ind++;
|
||||
//await mytable.findOneAndRemove({ _id: parseInt(doc._id, 10) });
|
||||
console.log('++Add (', ind, ')', doc._id);
|
||||
} else {
|
||||
const myid = parseInt(err.keyValue._id, 10) + 0;
|
||||
const canc = await mytable.findOneAndRemove({ _id: myid });
|
||||
if (canc)
|
||||
console.log('err', err.message, 'canc', canc._doc._id);
|
||||
}
|
||||
|
||||
}));
|
||||
try {
|
||||
const doc = await myrec.save();
|
||||
ind++;
|
||||
console.log('++Add (', ind, ')', doc._id);
|
||||
} catch (err) {
|
||||
const myid = parseInt(err.keyValue._id, 10) + 0;
|
||||
const canc = await mytable.findOneAndDelete({ _id: myid });
|
||||
if (canc)
|
||||
console.log('err', err.message, 'canc', canc._doc._id);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user