- MyProfile

- Immagine profilo e small
This commit is contained in:
paoloar77
2022-01-03 21:53:50 +01:00
parent b587b5e0a7
commit 181af3c895
7 changed files with 447 additions and 326 deletions

View File

@@ -1,18 +1,18 @@
const express = require('express');
const router = express.Router();
const { User } = require('../models/user');
const {User} = require('../models/user');
// const { Nave } = require('../models/nave');
const Hours = require('../models/hours');
//const { NavePersistente } = require('../models/navepersistente');
//const { ListaIngresso } = require('../models/listaingresso');
//const { Graduatoria } = require('../models/graduatoria');
// const { ExtraList } = require('../models/extralist');
const { ObjectID } = require('mongodb');
const {ObjectID} = require('mongodb');
const sendemail = require('../sendemail');
const { Settings } = require('../models/settings');
const {Settings} = require('../models/settings');
const tools = require('../tools/general');
const shared_consts = require('../tools/shared_nodejs');
@@ -25,25 +25,23 @@ const _ = require('lodash');
const reg = require('../reg/registration');
const { authenticate } = require('../middleware/authenticate');
const {authenticate} = require('../middleware/authenticate');
const Cart = require('../models/cart');
const CartClass = require('../modules/Cart')
const Product = require('../models/product')
const Variant = require('../models/variant')
const TypedError = require('../modules/ErrorHandler')
const CartClass = require('../modules/Cart');
const Product = require('../models/product');
const Variant = require('../models/variant');
const TypedError = require('../modules/ErrorHandler');
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', false);
const Subscription = mongoose.model('subscribers');
function existSubScribe(userId, access, browser) {
return Subscription.findOne({ userId, access, browser })
.then(itemsub => {
return itemsub
})
.catch(err => {
return null
})
return Subscription.findOne({userId, access, browser}).then(itemsub => {
return itemsub;
}).catch(err => {
return null;
});
}
@@ -53,8 +51,9 @@ function getMobileComplete(user) {
// str = str.replace(/.+/g, '');
// str = str.replace(/-+/g, '');
return str
return str;
}
router.post('/test1', async (req, res) => {
const user = await User.findOne({
@@ -65,13 +64,22 @@ router.post('/test1', async (req, res) => {
await sendemail.sendEmail_Registration(user.lang, user.email, user,
user.idapp, user.linkreg);
})
});
// POST /users
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']);
tools.mylog('POST /users');
const body = _.pick(req.body, [
'email',
'password',
'username',
'name',
'surname',
'idapp',
'keyappid',
'lang',
'profile',
'aportador_solidario']);
body.email = body.email.toLowerCase();
const user = new User(body);
@@ -79,19 +87,21 @@ router.post('/', async (req, res) => {
// tools.mylog("LANG PASSATO = " + user.lang, "IDAPP", user.idapp);
if (!tools.isAlphaNumeric(body.username) || body.email.length < 6 || body.username.length < 6 || body.password.length < 6) {
if (!tools.isAlphaNumeric(body.username) || body.email.length < 6 ||
body.username.length < 6 || body.password.length < 6) {
await tools.snooze(5000);
res.status(400).send({ code: server_constants.RIS_CODE_USERNAME_NOT_VALID, msg: '' });
res.status(400).
send({code: server_constants.RIS_CODE_USERNAME_NOT_VALID, msg: ''});
return 1;
}
if (tools.blockwords(body.username) || tools.blockwords(body.name) || tools.blockwords(body.surname)) {
if (tools.blockwords(body.username) || tools.blockwords(body.name) ||
tools.blockwords(body.surname)) {
// tools.writeIPToBan(user.ipaddr + ': [' + user.username + '] ' + user.name + ' ' + user.surname);
await tools.snooze(5000);
return res.status(404).send();
}
user.linkreg = reg.getlinkregByEmail(body.idapp, body.email, body.username);
user.verified_email = false;
user.lasttimeonline = new Date();
@@ -104,15 +114,18 @@ router.post('/', async (req, res) => {
// Controlla se anche l'ultimo record era dallo stesso IP:
const lastrec = await User.getLastRec(body.idapp);
if (!!lastrec) {
if (process.env.LOCALE !== "1") {
if (process.env.LOCALE !== '1') {
if (lastrec.ipaddr === user.ipaddr) {
// Se l'ha fatto troppo ravvicinato
if (lastrec.date_reg) {
let ris = tools.isdiffSecDateLess(lastrec.date_reg, 120);
if (ris) {
tools.writeIPToBan(user.ipaddr + ': [' + user.username + '] ' + user.name + ' ' + user.surname);
tools.writeIPToBan(
user.ipaddr + ': [' + user.username + '] ' + user.name + ' ' +
user.surname);
await tools.snooze(10000);
res.status(400).send({ code: server_constants.RIS_CODE_BANIP, msg: '' });
res.status(400).
send({code: server_constants.RIS_CODE_BANIP, msg: ''});
return 1;
}
}
@@ -133,37 +146,48 @@ router.post('/', async (req, res) => {
let exit;
// Check if already esist email or username
exit = await User.findByUsername(user.idapp, user.username).then((useralreadyexist) => {
if (useralreadyexist) {
res.status(400).send({ code: server_constants.RIS_CODE_USERNAME_ALREADY_EXIST, msg: '' });
return 1;
}
exit = await User.findByUsername(user.idapp, user.username).
then((useralreadyexist) => {
if (useralreadyexist) {
res.status(400).
send({
code: server_constants.RIS_CODE_USERNAME_ALREADY_EXIST,
msg: '',
});
return 1;
}
});
});
if (exit === 1)
return;
exit = await User.findByEmail(user.idapp, user.email)
.then((useralreadyexist) => {
if (useralreadyexist) {
res.status(400).send({ code: server_constants.RIS_CODE_EMAIL_ALREADY_EXIST, msg: '' });
return 1;
}
exit = await User.findByEmail(user.idapp, user.email).
then((useralreadyexist) => {
if (useralreadyexist) {
res.status(400).
send({
code: server_constants.RIS_CODE_EMAIL_ALREADY_EXIST,
msg: '',
});
return 1;
}
});
});
if (exit === 1)
return;
let recuser = null;
recuser = await User.findByCellAndNameSurname(user.idapp, user.profile.cell, user.name, user.surname);
recuser = await User.findByCellAndNameSurname(user.idapp, user.profile.cell,
user.name, user.surname);
if (recuser) {
console.log('UTENTE GIA ESISTENTE:\n');
console.log(user);
// User already registered!
res.status(400).send({ code: server_constants.RIS_CODE_USER_ALREADY_EXIST, msg: '' });
res.status(400).
send({code: server_constants.RIS_CODE_USER_ALREADY_EXIST, msg: ''});
return 1;
}
@@ -190,8 +214,8 @@ router.post('/', async (req, res) => {
return 1;
}*/
let already_registered = (recextra || user.aportador_solidario === tools.APORTADOR_NONE) && (user.idapp === tools.AYNI);
let already_registered = (recextra || user.aportador_solidario ===
tools.APORTADOR_NONE) && (user.idapp === tools.AYNI);
// Check if is an other people aportador_solidario
@@ -207,10 +231,9 @@ router.post('/', async (req, res) => {
return 1;
} */
return user.save()
.then(async () => {
return User.findByUsername(user.idapp, user.username, false)
.then((usertrovato) => {
return user.save().then(async () => {
return User.findByUsername(user.idapp, user.username, false).
then((usertrovato) => {
// tools.mylog("TROVATO USERNAME ? ", user.username, usertrovato);
if (usertrovato !== null) {
@@ -219,8 +242,8 @@ router.post('/', async (req, res) => {
res.status(400).send();
return 0;
}
})
.then(async (token) => {
}).
then(async (token) => {
// tools.mylog("passo il TOKEN: ", token);
if (recextra) {
@@ -231,23 +254,24 @@ router.post('/', async (req, res) => {
// await User.fixUsername(user.idapp, user.ind_order, user.username);
}
return token;
})
.then(async (token) => {
}).
then(async (token) => {
// tools.mylog("LINKREG = " + user.linkreg);
// Invia un'email all'utente
// tools.mylog('process.env.TESTING_ON', process.env.TESTING_ON);
console.log('res.locale', res.locale);
// if (!tools.testing()) {
await sendemail.sendEmail_Registration(user.lang, user.email, user, user.idapp, user.linkreg);
await sendemail.sendEmail_Registration(user.lang, user.email, user,
user.idapp, user.linkreg);
// }
res.header('x-auth', token).send(user);
return true;
});
}).catch((e) => {
console.error(e.message);
res.status(400).send(e);
})
}).catch((e) => {
console.error(e.message);
res.status(400).send(e);
});
});
router.get('/:idapp/:username', async (req, res) => {
@@ -277,26 +301,43 @@ router.patch('/:id', authenticate, (req, res) => {
if (!User.isAdmin(req.user.perm)) {
// If without permissions, exit
return res.status(404).send({ code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: '' });
return res.status(404).
send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
}
User.findByIdAndUpdate(id, { $set: body }).then((user) => {
User.findByIdAndUpdate(id, {$set: body}).then((user) => {
tools.mylogshow(' USER TO MODIFY: ', user);
if (!user) {
return res.status(404).send();
} else {
res.send({ code: server_constants.RIS_CODE_OK, msg: '' });
res.send({code: server_constants.RIS_CODE_OK, msg: ''});
}
}).catch((e) => {
tools.mylogserr('Error patch USER: ', e);
res.status(400).send();
})
});
});
router.post('/profile', (req, res) => {
const username = req.body['username'];
idapp = req.body.idapp;
locale = req.body.locale;
//++Todo: controlla che tipo di dati ha il permesso di leggere
return User.getUserProfileByUsername(idapp, username).then((ris) => {
res.send(ris);
}).catch((e) => {
tools.mylog('ERRORE IN Profile: ' + e.message);
res.status(400).send();
});
});
router.post('/login', (req, res) => {
var body = _.pick(req.body, ['username', 'password', 'idapp', 'keyappid', 'lang']);
var body = _.pick(req.body,
['username', 'password', 'idapp', 'keyappid', 'lang']);
var user = new User(body);
// const subs = _.pick(req.body, ['subs']);
@@ -309,57 +350,70 @@ router.post('/login', (req, res) => {
let resalreadysent = false;
User.findByCredentials(user.idapp, user.username, user.password)
.then(async (user) => {
// tools.mylog("CREDENZIALI ! ");
if (!user) {
await tools.snooze(3000);
const msg = "Tentativo di Login ERRATO [" + body.username + ' , ' + body.password + ']\n' + '[IP: ' + tools.getiPAddressUser(req) + ']';
tools.mylogshow(msg);
// telegrambot.sendMsgTelegramToTheManagers(body.idapp, msg);
res.status(404).send({ code: server_constants.RIS_CODE_LOGIN_ERR });
} else if (!!user.subaccount && user.subaccount) {
await tools.snooze(1000);
// const msg = "Tentativo di Login ERRATO [" + body.username + ' , ' + body.password + ']\n' + '[IP: ' + tools.getiPAddressUser(req) + ']';
// tools.mylogshow(msg);
// telegrambot.sendMsgTelegramToTheManagers(body.idapp, msg);
res.status(404).send({ code: server_constants.RIS_CODE_LOGIN_ERR_SUBACCOUNT });
return null;
}
return user
})
.then(user => {
if (user) {
return user.generateAuthToken(req).then((token) => {
var usertosend = new User();
User.findByCredentials(user.idapp, user.username, user.password).
then(async (user) => {
// tools.mylog("CREDENZIALI ! ");
if (!user) {
await tools.snooze(3000);
const msg = 'Tentativo di Login ERRATO [' + body.username + ' , ' +
body.password + ']\n' + '[IP: ' + tools.getiPAddressUser(req) +
']';
tools.mylogshow(msg);
// telegrambot.sendMsgTelegramToTheManagers(body.idapp, msg);
res.status(404).send({code: server_constants.RIS_CODE_LOGIN_ERR});
} else if (!!user.subaccount && user.subaccount) {
await tools.snooze(1000);
// const msg = "Tentativo di Login ERRATO [" + body.username + ' , ' + body.password + ']\n' + '[IP: ' + tools.getiPAddressUser(req) + ']';
// tools.mylogshow(msg);
// telegrambot.sendMsgTelegramToTheManagers(body.idapp, msg);
res.status(404).
send({code: server_constants.RIS_CODE_LOGIN_ERR_SUBACCOUNT});
return null;
}
return user;
}).
then(user => {
if (user) {
return user.generateAuthToken(req).then((token) => {
var usertosend = new User();
shared_consts.fieldsUserToChange().forEach((field) => {
usertosend[field] = user[field]
});
shared_consts.fieldsUserToChange().forEach((field) => {
usertosend[field] = user[field];
});
// usertosend._id = user._id.toHexString();
// if (!User.isAdmin(req.user)) {
// usertosend.ipaddr = user.ipaddr;
// }
// usertosend._id = user._id.toHexString();
// if (!User.isAdmin(req.user)) {
// usertosend.ipaddr = user.ipaddr;
// }
// tools.mylog("user.verified_email:" + user.verified_email);
// tools.mylog("usertosend.userId", usertosend.userId);
// tools.mylog("user.verified_email:" + user.verified_email);
// tools.mylog("usertosend.userId", usertosend.userId);
return { usertosend, token }
return {usertosend, token};
})
.then((myris) => {
}).then((myris) => {
const access = 'auth';
const browser = req.get('User-Agent');
// Check if already exist Subscribe
return existSubScribe(myris.usertosend._id, access, browser).then(subscribe => {
return (subscribe !== null)
}).then(subsExistonDb => {
return { usertosend: myris.usertosend, token: myris.token, subsExistonDb }
}).catch(err => {
return { usertosend: myris.usertosend, token: myris.token, subsExistonDb: false }
})
return existSubScribe(myris.usertosend._id, access, browser).
then(subscribe => {
return (subscribe !== null);
}).
then(subsExistonDb => {
return {
usertosend: myris.usertosend,
token: myris.token,
subsExistonDb,
};
}).
catch(err => {
return {
usertosend: myris.usertosend,
token: myris.token,
subsExistonDb: false,
};
});
}).then(myris => {
// console.log('res', myris.token, myris.usertosend);
@@ -367,20 +421,21 @@ router.post('/login', (req, res) => {
res.header('x-auth', myris.token).send({
usertosend: myris.usertosend,
code: server_constants.RIS_CODE_OK,
subsExistonDb: myris.subsExistonDb
subsExistonDb: myris.subsExistonDb,
});
// tools.mylog("TROVATOOO!");
// tools.mylog('FINE LOGIN')
});
}
})
.catch((e) => {
tools.mylog("ERRORE IN LOGIN: " + e.message);
if (!resalreadysent)
res.status(400).send({ code: server_constants.RIS_CODE_LOGIN_ERR_GENERIC });
});
}
}).
catch((e) => {
tools.mylog('ERRORE IN LOGIN: ' + e.message);
if (!resalreadysent)
res.status(400).
send({code: server_constants.RIS_CODE_LOGIN_ERR_GENERIC});
});
});
router.delete('/me/token', authenticate, (req, res) => {
@@ -394,7 +449,7 @@ router.delete('/me/token', authenticate, (req, res) => {
router.post('/setperm', authenticate, (req, res) => {
const body = _.pick(req.body, ['idapp', 'username', 'perm']);
tools.mylog("SETPERM = " + req.token);
tools.mylog('SETPERM = ' + req.token);
User.setPermissionsById(res.user._id, body).then(() => {
res.status(200).send();
@@ -425,183 +480,183 @@ async function eseguiDbOp(idapp, mydata, locale) {
if (mydata.dbop === '') {
// } else if (mydata.dbop === 'rigeneraTutto') {
// } else if (mydata.dbop === 'rigeneraTutto') {
// await ListaIngresso.Esegui_CronTab(idapp, mydata);
} else if (mydata.dbop === 'visuStat') {
ris = await User.visuUtentiNonInNavi(idapp);
//} else if (mydata.dbop === 'creaNavi') {
//} 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 === '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') {
} else if (mydata.dbop === 'delNaviProvvisorie') {
ris = await Nave.delNaviProvvisorie(idapp);
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;
} 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 } });
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;
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!
// 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++;
}
}
}
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,
};
const arrnavitess2 = await Nave.find({ idapp, num_tess: 2 });
// Aggiorna la nave con l'Ind_order nuovo e il num_tess a 1
await Nave.findOneAndUpdate({ _id: recnave._id }, { $set: fieldsvalue }, { new: false });
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++;
}
}
}
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 };
*/
ris = { num };
*/
/*
}
@@ -643,24 +698,25 @@ async function eseguiDbOp(idapp, mydata, locale) {
}
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++;
/*} 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') {
ris = { num };
*/
} else if (mydata.dbop === 'creaUtentiTest') {
let num = 0;
lastrec = await User.find({ idapp }).sort({ _id: -1 }).limit(1);
lastrec = await User.find({idapp}).sort({_id: -1}).limit(1);
let last = 1;
if (lastrec) {
last = lastrec[0].index;
@@ -674,46 +730,46 @@ async function eseguiDbOp(idapp, mydata, locale) {
myuser._id = new ObjectID();
myuser.index = last + ind + 1;
myuser.idapp = idapp;
myuser.password = "$2a$12$DEaX1h5saTUVC43f7kubyOAlah1xHDgqQTfSIux0.RFDT9WGbyCaG";
myuser.password = '$2a$12$DEaX1h5saTUVC43f7kubyOAlah1xHDgqQTfSIux0.RFDT9WGbyCaG';
myuser.lang = 'it';
myuser.email = "miaemail@email.it";
myuser.email = 'miaemail@email.it';
myuser.name = 'U' + myuser.index;
myuser.surname = 'Ar' + myuser.index;
myuser.verified_email = true;
myuser.verified_by_aportador = true;
if (myuser.index < 2)
myuser.perm = "3";
myuser.username = "Userna_" + myuser.name;
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') {
ris = {num};
/*} else if (mydata.dbop === 'visuPlacca') {
mystr = '✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨\n' +
'NAVI CHE SALPANO DALLA ' + mydata.riga + '.' + mydata.col + ' ALLA ' + mydata.riga + '.' + (parseInt(mydata.col) + 7) + '\n' +
'AUGURI ALLA NUOVA SOGNATRICE !!!\n' +
'✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨';
mystr = '✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨\n' +
'NAVI CHE SALPANO DALLA ' + mydata.riga + '.' + mydata.col + ' ALLA ' + mydata.riga + '.' + (parseInt(mydata.col) + 7) + '\n' +
'AUGURI ALLA NUOVA SOGNATRICE !!!\n' +
'✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨';
const visu_nave_Bot = await Settings.getValDbSettings(idapp, 'VISU_NAVE_BOT');
const visu_nave_Bot = await Settings.getValDbSettings(idapp, 'VISU_NAVE_BOT');
for (let ind = 0; ind < 8; ind++) {
mystr += await Nave.getNavePos(idapp, parseInt(mydata.riga), parseInt(mydata.col) + ind, false);
mystr += tools.ACAPO;
if (visu_nave_Bot && ind === 3) {
await telegrambot.sendMsgTelegramToTheAdmin(idapp, mystr, true);
mystr = '';
for (let ind = 0; ind < 8; ind++) {
mystr += await Nave.getNavePos(idapp, parseInt(mydata.riga), parseInt(mydata.col) + ind, false);
mystr += tools.ACAPO;
if (visu_nave_Bot && ind === 3) {
await telegrambot.sendMsgTelegramToTheAdmin(idapp, mystr, true);
mystr = '';
}
}
}
if (visu_nave_Bot)
await telegrambot.sendMsgTelegramToTheAdmin(idapp, mystr, true);
if (visu_nave_Bot)
await telegrambot.sendMsgTelegramToTheAdmin(idapp, mystr, true);
ris = { mystr };
*/
ris = { mystr };
*/
} else if (mydata.dbop === 'CorreggiTabHours') {
await Hours.correggiHours(idapp);
@@ -722,34 +778,33 @@ async function eseguiDbOp(idapp, mydata, locale) {
await User.setVerifiedByAportadorToALL();
/*} else if (mydata.dbop === 'visuNave') {
mystr = await Nave.getNavePos(idapp, parseInt(mydata.riga), parseInt(mydata.col));
/*} else if (mydata.dbop === 'visuNave') {
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);
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') {
ris = { mystr };
} else if (mydata.dbop === 'getnavibyuser') {
let arrnavi = null;
let arrnavi = null;
const user = await User.getUserShortDataByUsername(idapp, mydata.username);
if (user) {
arrnavi = await Nave.getArrPosizioniByUsername(idapp, user.username);
const user = await User.getUserShortDataByUsername(idapp, mydata.username);
if (user) {
arrnavi = await Nave.getArrPosizioniByUsername(idapp, user.username);
for (let mynave of arrnavi) {
mynave._doc.rec = await Nave.getNaveByRigaCol(idapp, mynave.riga, mynave.col);
}
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);
return ris;
@@ -771,5 +826,4 @@ router.post('/dbop', authenticate, async (req, res) => {
});
module.exports = router;