- Nave
- Requirements - Send Msg to Passeggeri
This commit is contained in:
@@ -2,10 +2,15 @@ const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
const { User } = require('../models/user');
|
||||
const { Nave } = require('../models/nave');
|
||||
const { ListaIngresso } = require('../models/listaingresso');
|
||||
const { ExtraList } = require('../models/extralist');
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
const sendemail = require('../sendemail');
|
||||
|
||||
const { Settings } = require('../models/settings');
|
||||
|
||||
const tools = require('../tools/general');
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
@@ -47,10 +52,10 @@ function getMobileComplete(user) {
|
||||
router.post('/', async (req, res) => {
|
||||
tools.mylog("POST /users");
|
||||
const body = _.pick(req.body, ['email', 'password', 'username', 'name', 'surname', 'idapp', 'keyappid', 'lang', 'profile', 'aportador_solidario']);
|
||||
const user = new User(body);
|
||||
|
||||
body.email = body.email.toLowerCase();
|
||||
|
||||
const user = new User(body);
|
||||
|
||||
// tools.mylog("LANG PASSATO = " + user.lang, "IDAPP", user.idapp);
|
||||
|
||||
user.linkreg = reg.getlinkregByEmail(body.idapp, body.email, body.username);
|
||||
@@ -59,6 +64,10 @@ router.post('/', async (req, res) => {
|
||||
user.lasttimeonline = new Date();
|
||||
user.date_reg = new Date();
|
||||
user.date_temp_reg = new Date();
|
||||
user.aportador_iniziale = user.aportador_solidario;
|
||||
if (user.idapp === tools.AYNI) {
|
||||
user.profile.paymenttypes = ['paypal'];
|
||||
}
|
||||
// user.perm = 3;
|
||||
if (tools.testing()) {
|
||||
user.verified_email = true;
|
||||
@@ -147,7 +156,7 @@ router.post('/', async (req, res) => {
|
||||
msgseconda += 'QUARTA';
|
||||
|
||||
msgseconda += ' UTENZA di ' + recorig.name + ' ' + recorig.surname + ' (' + recorig.username + ') : ' + user.name + ' ' + user.surname + ' (' + user.username + ') ';
|
||||
telegrambot.sendMsgTelegramToTheManagers(user.idapp, msgseconda);
|
||||
await telegrambot.sendMsgTelegramToTheManagers(user.idapp, msgseconda);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +167,7 @@ router.post('/', async (req, res) => {
|
||||
let msg = 'L\'utente ' + user.name + ' ' + user.surname + ' si sta registrando con il link di ' + user.aportador_solidario + ' (' + namesurname_aportador_reg + ') ' +
|
||||
'invece è assegnato a ' + nomeaportador_corretto;
|
||||
|
||||
telegrambot.sendMsgTelegramToTheManagers(user.idapp, msg);
|
||||
await telegrambot.sendMsgTelegramToTheManagers(user.idapp, msg);
|
||||
res.status(400).send({ code: server_constants.RIS_CODE_USER_NOT_THIS_APORTADOR, msg: '' });
|
||||
return 1;
|
||||
}
|
||||
@@ -173,8 +182,11 @@ router.post('/', async (req, res) => {
|
||||
if (!recextra) {
|
||||
const msg = 'Utente non trovato: ' + user.name + ' ' + user.surname + ' ' + user.profile.nationality + ' ' + user.profile.cell + ' email: ' + user.email + ' username: ' + user.username;
|
||||
console.log('Utente non trovato; ', msg);
|
||||
telegrambot.sendMsgTelegramToTheManagers(user.idapp, msg);
|
||||
res.status(400).send({ code: server_constants.RIS_CODE_USER_EXTRALIST_NOTFOUND, msg: 'Controlla se il numero ' + user.profile.cell + ' è corretto.' });
|
||||
await telegrambot.sendMsgTelegramToTheManagers(user.idapp, msg);
|
||||
res.status(400).send({
|
||||
code: server_constants.RIS_CODE_USER_EXTRALIST_NOTFOUND,
|
||||
msg: 'Controlla se il numero ' + user.profile.cell + ' è corretto.'
|
||||
});
|
||||
return 1;
|
||||
} else {
|
||||
user.ind_order = recextra.ind_order;
|
||||
@@ -244,11 +256,11 @@ router.post('/', async (req, res) => {
|
||||
})
|
||||
});
|
||||
|
||||
router.get('/:idapp/:username', (req, res) => {
|
||||
router.get('/:idapp/:username', async (req, res) => {
|
||||
var username = req.params.username;
|
||||
const idapp = req.params.idapp;
|
||||
|
||||
User.findByUsername(idapp, username, false).then((user) => {
|
||||
await User.findByUsername(idapp, username, false).then((user) => {
|
||||
if (!user) {
|
||||
return res.status(404).send();
|
||||
}
|
||||
@@ -397,17 +409,130 @@ router.post('/import_extralist', async (req, res) => {
|
||||
res.send(ris);
|
||||
});
|
||||
|
||||
router.post('/dbop', async (req, res) => {
|
||||
router.post('/dbop', authenticate, async (req, res) => {
|
||||
|
||||
const mydata = req.body.mydata;
|
||||
idapp = req.body.idapp;
|
||||
locale = req.body.locale;
|
||||
const mydata = req.body.mydata;
|
||||
idapp = req.body.idapp;
|
||||
locale = req.body.locale;
|
||||
|
||||
const ris = await User.DbOp(idapp, mydata);
|
||||
console.log('ris', ris);
|
||||
let ris = await User.DbOp(idapp, mydata);
|
||||
|
||||
res.send(ris);
|
||||
});
|
||||
if (mydata.dbop === 'creaNave') {
|
||||
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 === 'visuListaNave') {
|
||||
const mystr = await Nave.showListaOrd(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 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 === 'creaUtentiTest') {
|
||||
|
||||
let num = 0;
|
||||
lastrec = await User.find({ idapp }).sort({ _id: -1 }).limit(1);
|
||||
for (let ind = 0; ind < 1; 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.verified_email = true;
|
||||
if (myuser.ind_order < 2)
|
||||
myuser.perm = "3";
|
||||
myuser.username = "Userna_" + myuser.name;
|
||||
myuser.profile.special_req = true;
|
||||
await myuser.save();
|
||||
num++;
|
||||
}
|
||||
|
||||
ris = { num };
|
||||
} else if (mydata.dbop === 'visuPlacca') {
|
||||
const placca = await Nave.getPlaccaPerDonatore(idapp, parseInt(mydata.riga), parseInt(mydata.col));
|
||||
|
||||
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);
|
||||
|
||||
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 };
|
||||
}
|
||||
|
||||
// console.log('ris', ris);
|
||||
|
||||
res.send(ris);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user