Lista Doni Navi 3
This commit is contained in:
@@ -3,6 +3,7 @@ const router = express.Router();
|
||||
|
||||
const { User } = require('../models/user');
|
||||
const { Nave } = require('../models/nave');
|
||||
const { NavePersistente } = require('../models/navepersistente');
|
||||
const { ListaIngresso } = require('../models/listaingresso');
|
||||
const { ExtraList } = require('../models/extralist');
|
||||
const { ObjectID } = require('mongodb');
|
||||
@@ -417,158 +418,217 @@ router.post('/dbop', authenticate, async (req, res) => {
|
||||
|
||||
let ris = await User.DbOp(idapp, mydata);
|
||||
|
||||
if (mydata.dbop === 'creaNaviProvvisorie') {
|
||||
mydata.provvisoria = true;
|
||||
const num = await Nave.generaNave(idapp, mydata);
|
||||
ris = { num };
|
||||
} else if (mydata.dbop === 'creaNaviDefinitive') {
|
||||
mydata.provvisoria = false;
|
||||
const num = await Nave.generaNave(idapp, mydata);
|
||||
ris = { num };
|
||||
} else if (mydata.dbop === 'delNavi') {
|
||||
await Nave.setRiga(idapp, 1);
|
||||
await Nave.setCol(idapp, 1);
|
||||
const num = await Nave.remove({ 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') {
|
||||
const num = await Nave.remove({ idapp, provvisoria: true });
|
||||
try {
|
||||
|
||||
const data = await Nave.getLastRigaCol(idapp);
|
||||
await Nave.setRiga(idapp, data.riga);
|
||||
await Nave.setCol(idapp, data.col + 1);
|
||||
if (mydata.dbop === 'creaNaviProvvisorie') {
|
||||
mydata.provvisoria = true;
|
||||
const num = await Nave.generaNave(idapp, mydata);
|
||||
ris = { num };
|
||||
} else if (mydata.dbop === 'creaNaviDefinitive') {
|
||||
mydata.provvisoria = false;
|
||||
const num = await Nave.generaNave(idapp, mydata);
|
||||
ris = { num };
|
||||
} else if (mydata.dbop === 'delNavi') {
|
||||
await Nave.setRiga(idapp, 1);
|
||||
await Nave.setCol(idapp, 1);
|
||||
const num = await Nave.remove({ 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') {
|
||||
const num = await Nave.remove({ idapp, provvisoria: true });
|
||||
|
||||
ris = { num };
|
||||
} else if (mydata.dbop === 'visuListaNave') {
|
||||
const mystr = await Nave.showListaOrd(idapp);
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'pulisciNonPresenzeInNave') {
|
||||
const mystr = await Nave.pulisciNonPresenzeInNave(idapp);
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'checkInserimentiUtentiInNave') {
|
||||
const mystr = await Nave.checkIfDevoAggiungereInNave(idapp);
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'visuListaIngresso') {
|
||||
const mystr = await ListaIngresso.showListaOrd(idapp);
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'initListaIngresso') {
|
||||
// const aaa = await User.updateMany({ idapp }, { $set: { 'profile.nationality': 'IT' } });
|
||||
const data = await Nave.getLastRigaCol(idapp);
|
||||
await Nave.setRiga(idapp, data.riga);
|
||||
await Nave.setCol(idapp, data.col + 1);
|
||||
|
||||
const num = await ListaIngresso.updateMany({ idapp }, { $set: { added: false } });
|
||||
ris = { num };
|
||||
} else if (mydata.dbop === 'visuListaNave') {
|
||||
const mystr = await Nave.showListaOrd(idapp);
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'pulisciNonPresenzeInNave') {
|
||||
const mystr = await Nave.pulisciNonPresenzeInNave(idapp);
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'checkInserimentiUtentiInNave') {
|
||||
const mystr = await Nave.checkIfDevoAggiungereInNave(idapp);
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'visuListaIngresso') {
|
||||
const mystr = await ListaIngresso.showListaOrd(idapp);
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'initListaIngresso') {
|
||||
// const aaa = await User.updateMany({ idapp }, { $set: { 'profile.nationality': 'IT' } });
|
||||
|
||||
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 } });
|
||||
}
|
||||
const num = await ListaIngresso.updateMany({ idapp }, { $set: { added: 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 = indextess;
|
||||
const risu = await Nave.findOneAndUpdate({ _id: myarrrec[ind]._id }, { $set: { num_tess: myarrrec[ind].num_tess } }, { new: 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++;
|
||||
}
|
||||
indextess++;
|
||||
}
|
||||
}
|
||||
|
||||
ris = { num };
|
||||
} else if (mydata.dbop === 'creaUtentiTest') {
|
||||
|
||||
let num = 0;
|
||||
lastrec = await User.find({ idapp }).sort({ _id: -1 }).limit(1);
|
||||
for (let ind = 0; ind < 100; ind++) {
|
||||
let myuser = new User();
|
||||
myuser._id = new ObjectID();
|
||||
myuser.ind_order = lastrec[0].ind_order + ind + 1;
|
||||
myuser.idapp = idapp;
|
||||
myuser.password = "$2a$12$DEaX1h5saTUVC43f7kubyOAlah1xHDgqQTfSIux0.RFDT9WGbyCaG";
|
||||
myuser.lang = 'it';
|
||||
myuser.email = "miaemail@email.it";
|
||||
myuser.name = 'U' + myuser.ind_order;
|
||||
myuser.surname = 'Ar' + myuser.ind_order;
|
||||
myuser.verified_email = true;
|
||||
if (myuser.ind_order < 2)
|
||||
myuser.perm = "3";
|
||||
myuser.username = "Userna_" + myuser.name;
|
||||
myuser.profile.special_req = true;
|
||||
myuser.profile.nationality = 'IT';
|
||||
await myuser.save();
|
||||
num++;
|
||||
}
|
||||
|
||||
ris = { num };
|
||||
} else if (mydata.dbop === 'visuPlacca') {
|
||||
const rec = {};
|
||||
const placca = await Nave.getPlaccaPerDonatore(idapp, parseInt(mydata.riga), parseInt(mydata.col), false, rec);
|
||||
|
||||
telegrambot.sendMsgTelegramToTheAdmin(idapp, placca);
|
||||
|
||||
ris = { placca };
|
||||
} else if (mydata.dbop === 'visuNave') {
|
||||
const mystr = await Nave.getNavePos(idapp, parseInt(mydata.riga), parseInt(mydata.col));
|
||||
|
||||
const visu_nave_Bot = await Settings.getValDbSettings(idapp, 'VISU_NAVE_BOT');
|
||||
if (visu_nave_Bot)
|
||||
telegrambot.sendMsgTelegramToTheAdmin(idapp, mystr, true);
|
||||
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'getnavibyuser') {
|
||||
|
||||
let arrnavi = null;
|
||||
|
||||
const user = await User.getUserShortDataByUsername(idapp, mydata.username);
|
||||
if (user) {
|
||||
arrnavi = await Nave.getArrPosizioniByIndOrder(idapp, user.ind_order);
|
||||
|
||||
for (let mynave of arrnavi) {
|
||||
mynave._doc.rec = await Nave.getNaveByRigaCol(idapp, mynave.riga, mynave.col);
|
||||
// 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 = 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.provvisoria = rec.provvisoria;
|
||||
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;
|
||||
lastrec = await User.find({ idapp }).sort({ _id: -1 }).limit(1);
|
||||
for (let ind = 0; ind < 100; ind++) {
|
||||
let myuser = new User();
|
||||
myuser._id = new ObjectID();
|
||||
myuser.ind_order = lastrec[0].ind_order + ind + 1;
|
||||
myuser.idapp = idapp;
|
||||
myuser.password = "$2a$12$DEaX1h5saTUVC43f7kubyOAlah1xHDgqQTfSIux0.RFDT9WGbyCaG";
|
||||
myuser.lang = 'it';
|
||||
myuser.email = "miaemail@email.it";
|
||||
myuser.name = 'U' + myuser.ind_order;
|
||||
myuser.surname = 'Ar' + myuser.ind_order;
|
||||
myuser.verified_email = true;
|
||||
if (myuser.ind_order < 2)
|
||||
myuser.perm = "3";
|
||||
myuser.username = "Userna_" + myuser.name;
|
||||
myuser.profile.special_req = true;
|
||||
myuser.profile.nationality = 'IT';
|
||||
await myuser.save();
|
||||
num++;
|
||||
}
|
||||
|
||||
ris = { num };
|
||||
} else if (mydata.dbop === 'visuPlacca') {
|
||||
const rec = {};
|
||||
const placca = await Nave.getPlaccaPerDonatore(idapp, parseInt(mydata.riga), parseInt(mydata.col), false, rec);
|
||||
|
||||
telegrambot.sendMsgTelegramToTheAdmin(idapp, placca);
|
||||
|
||||
ris = { placca };
|
||||
} else if (mydata.dbop === 'visuNave') {
|
||||
const mystr = await Nave.getNavePos(idapp, parseInt(mydata.riga), parseInt(mydata.col));
|
||||
|
||||
const visu_nave_Bot = await Settings.getValDbSettings(idapp, 'VISU_NAVE_BOT');
|
||||
if (visu_nave_Bot)
|
||||
telegrambot.sendMsgTelegramToTheAdmin(idapp, mystr, true);
|
||||
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'getnavibyuser') {
|
||||
|
||||
let arrnavi = null;
|
||||
|
||||
const user = await User.getUserShortDataByUsername(idapp, mydata.username);
|
||||
if (user) {
|
||||
arrnavi = await Nave.getArrPosizioniByIndOrder(idapp, user.ind_order);
|
||||
|
||||
for (let mynave of arrnavi) {
|
||||
mynave._doc.rec = await Nave.getNaveByRigaCol(idapp, mynave.riga, mynave.col);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ris = { data: arrnavi };
|
||||
}
|
||||
|
||||
ris = { data: arrnavi };
|
||||
|
||||
// console.log('ris', ris);
|
||||
|
||||
res.send(ris);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
// console.log('ris', ris);
|
||||
|
||||
res.send(ris);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user