- Billettera

- Lista Ingressi
 - Send a Tutti la propria Lavagna.
This commit is contained in:
Paolo Arena
2020-02-19 16:09:16 +01:00
parent eccb5bbb57
commit 26715cda44
23 changed files with 1740 additions and 226 deletions

View File

@@ -0,0 +1,412 @@
const mongoose = require('mongoose');
const _ = require('lodash');
const tools = require('../tools/general');
const { ListaIngresso } = require('./listaingresso');
const { Settings } = require('./settings');
const { User } = require('./user');
const { ObjectID } = require('mongodb');
const telegrambot = require('../telegram/telegrambot');
const shared_consts = require('../tools/shared_nodejs');
mongoose.Promise = global.Promise;
mongoose.level = "F";
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
mongoose.set('debug', process.env.DEBUG);
const BilletteraSchema = new mongoose.Schema({
idapp: {
type: String,
required: true,
},
riga: {
type: Number,
},
col: {
type: Number,
},
indprimario: {
type: Number,
},
parent_indprimario: {
type: Number,
},
date_start: {
type: Date
},
made_gift: {
type: Boolean,
default: false,
},
received_gift: {
type: Boolean,
default: false,
},
created: {
type: Date,
},
num_tess: { // numero di tessitura
type: Boolean,
default: 1
}
});
BilletteraSchema.statics.getTotInLista = async function (idapp) {
const Billettera = this;
const myfind = { idapp };
return await Billettera.count(myfind);
};
BilletteraSchema.statics.findByIndOrder = function (idapp, ind_order) {
const User = this;
try {
return User.findOne({
'idapp': idapp,
'ind_order': ind_order,
});
} catch (e) {
}
};
BilletteraSchema.statics.getFieldsForSearch = function () {
return ['username', 'name', 'surname', 'ind_order']
};
BilletteraSchema.statics.executeQueryTable = function (idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, idapp, params);
};
BilletteraSchema.statics.findAllIdApp = function (idapp) {
const Billettera = this;
const myfind = { idapp };
return Billettera.find(myfind, (err, arrrec) => {
return arrrec
});
};
BilletteraSchema.statics.findByRigaCol = function (idapp, riga, col) {
const Billettera = this;
const myfind = { idapp, riga, col };
return Billettera.findOne(myfind, (err, arrrec) => {
return arrrec
});
};
BilletteraSchema.statics.findRecByRigaColParent = async function (idapp, riga, col, numparentUp) {
const Billettera = this;
const myfind = { idapp, riga, col };
let parentup = 0;
let myrec = null;
while (parentup < numparentUp) {
myrec = await Billettera.findOne(myfind);
if (myrec.parent_indprimario === 0)
break;
}
return myrec;
};
function getlimiti(mypos) {
if (mypos.col < 0) {
mypos.col = 0;
}
if (mypos.riga < 0) {
mypos.riga = 0;
mypos.col = 0;
}
return mypos;
}
function getRigaColByPosUp(mypos) {
riga = riga - mypos.numup;
col = Math.ceil(col / (Math.pow(2, mypos.numup)));
if ((col % 2) !== 0)
col++;
}
function getRigaColGenerica(idapp, riga, col, numup) {
mypos = {
riga,
col,
numup
};
if (idapp === tools.AYNI) {
this.getRigaColByPosUp(mypos);
ris = this.getlimiti(mypos);
riga = ris.riga;
col = ris.col;
}
return { riga, col };
}
function getRigaColSognatoreByFuoco(idapp, riga, col) {
return this.getRigaColGenerica(idapp, riga, col, 6);
}
function getRigaColMediatoreByFuoco(idapp, riga, col) {
return this.getRigaColGenerica(idapp, riga, col, 3);
}
BilletteraSchema.statics.findMediatoreByFuoco = function (idapp, riga, col) {
const Billettera = this;
const myrigacol = getRigaColMediatoreByFuoco(idapp, riga, col);
const myfind = { idapp, riga: myrigacol.riga, col: myrigacol.col };
return Billettera.findOne(myfind, (err, arrrec) => {
return arrrec
});
};
function getQueryProj(myfilter) {
const query = [
{ $match: myfilter },
{
$lookup: {
from: "users",
localField: "ind_order",
foreignField: "ind_order", // field in the user collection
as: "user"
}
},
{
$replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$user", 0] }, "$$ROOT"] } }
},
];
return query;
}
BilletteraSchema.statics.findSognatoreByFuoco = function (idapp, riga, col) {
const Billettera = this;
const myrigacol = getRigaColSognatoreByFuoco(idapp, riga, col);
const myquery = this.getQueryProj({ idapp, riga: myrigacol.riga, col: myrigacol.col });
return Billettera.find(myquery, (err, arrrec) => {
return arrrec
});
};
BilletteraSchema.statics.setRiga = async function (idapp, riga) {
const newrec = new Settings({ key: 'riga' });
newrec._id = new ObjectID();
newrec.idapp = idapp;
newrec.type = tools.FieldType.number;
newrec.value_num = riga;
await newrec.save();
};
BilletteraSchema.statics.getRiga = async function (idapp) {
const ret = await Settings.findOne({ key: 'riga', idapp });
if (!!ret) {
return ret.value_num;
} else {
return 1;
}
};
BilletteraSchema.statics.setCol = async function (idapp, col) {
const newrec = new Settings({ key: 'col' });
newrec._id = new ObjectID();
newrec.idapp = idapp;
newrec.type = tools.FieldType.number;
newrec.value_num = col;
await newrec.save();
};
BilletteraSchema.statics.getCol = async function (idapp) {
const ret = await Settings.findOne({ key: 'col', idapp });
if (!!ret) {
return ret.value_num;
} else {
return 1;
}
};
function getmaxcol(riga) {
let maxcol = 1;
if (riga === 1) {
maxcol = 1;
} else if (riga === 2) {
maxcol = 2;
} else {
maxcol = Math.pow(riga - 1, 2);
}
return maxcol;
}
function getPrimoFuocoByIndCol(col) {
return Math.ceil(col / 8) + (col % 8);
}
function getusertextbyrec(myrec, symbol) {
return symbol + ' ' + recfuoco.ind_order + ' (' + recfuoco.name + ' ' + recfuoco.surname + ')';
}
BilletteraSchema.statics.getPlaccaByFuoco = async function (idapp, riga, col) {
const Billettera = this;
try {
let recsognatore = await Billettera.findSognatoreByFuoco(idapp, riga, col);
let recmediatore = await Billettera.findMediatoreByFuoco(idapp, riga, col);
let primofuoco = this.getPrimoFuocoByIndCol(col);
mystr = '🌈 Dreamer ' + this.getusertextbyrec(recsognatore, '🔥') + tools.ACAPO;
mystr = '🌈 Mediator ' + this.getusertextbyrec(recmediatore, '🔥') + tools.ACAPO;
mystr = '🔥🌏💦💨🔥🌏💦💨' + tools.ACAPO;
for (let indcol = primofuoco; indcol < primofuoco + 8; indcol++) {
let recfuoco = await Billettera.findByRigaCol(idapp, riga, indcol);
mystr += this.getusertextbyrec(recfuoco, '🔥') + tools.ACAPO;
}
} catch (e) {
console.error(e);
}
}
function Fuochi8Completati(idapp, riga, col) {
// Inviare un msg al Mediatore che può aprire la Chat con gli 8 fuochi
// Inviare un msg a questi 8 Fuochi, che la loro placca è Pronta !
txt = '';
// Inviare la placca a Managers
telegrambot.sendMsgTelegramToTheManagers(idapp, txt);
}
BilletteraSchema.statics.generaBillettera = async function (idapp) {
const Billettera = this;
let riga = await Billettera.getRiga(idapp);
let col = await Billettera.getCol(idapp);
let primavolta = (riga === 1) && (col === 1);
primavolta = false;
const recfindFondo = await Billettera.findByRigaCol(idapp, 0, 0);
if (!recfindFondo) {
billettera = new Billettera({ idapp, indprimario: 0, riga: 0, col: 0 });
billettera.created = new Date();
await billettera.save();
const UserFondo = await User.findByIndOrder(idapp, 0);
if (!UserFondo) {
telegrambot.sendMsgTelegramToTheAdmin(idapp, 'Devi creare l\'utente FONDO , con ind_order = 0 ! ');
}
}
let maxcol = getmaxcol(riga);
// Identifica il prossimo d'aggiungere
arrlistaingresso = await ListaIngresso.find({ 'idapp': idapp, added: false }).sort({ indprimario: 1 });
let conta = 0;
let colparent = Math.ceil(col / 2);
let rigaparent = riga - 1;
for (const reclista of arrlistaingresso) {
billettera = new Billettera({ idapp, indprimario: reclista.indprimario, riga, col });
billettera.created = new Date();
const recfind = await Billettera.findByRigaCol(idapp, rigaparent, colparent);
if (!!recfind) {
billettera.parent_indprimario = recfind.indprimario;
} else {
billettera.parent_indprimario = 0;
}
await billettera.save()
.then(async (result) => {
let fields_to_update = { added: true };
const ris = await ListaIngresso.findOneAndUpdate({ _id: reclista._id.toString() }, { $set: fields_to_update }, { new: false });
await Billettera.setRiga(idapp, riga);
await Billettera.getCol(idapp, col);
conta++;
// Check if Billetera has Completed
if (idapp === tools.AYNI) {
if ((col % 8) === 0) {
// Completed 8 people
let text = 'Completata Billettera [riga=' + riga + ',col=' + col + ']';
tools.writeBilletteraLog(text);
if (!primavolta) {
telegrambot.sendMsgTelegramToTheManagers(idapp, text);
this.Fuochi8Completati(idapp, riga, col);
}
}
}
// Next
if (col === maxcol) {
riga++;
rigaparent = riga - 1;
col = 1;
maxcol = getmaxcol(riga);
} else {
col++;
}
if ((col % 2) !== 0)
colparent++;
});
}
};
const Billettera = mongoose.model('Billettera', BilletteraSchema);
module.exports = { Billettera };

View File

@@ -53,7 +53,7 @@ CalZoomSchema.statics.findAllIdApp = async function (idapp) {
const myfind = { idapp, date_start: { $gt: tools.IncDateNow(-1000 * 60 * 60 * 3) } };
return await CalZoom.find(myfind).sort({ date_start: 1 });
return await CalZoom.find(myfind).sort({ date_start: 1 }).limit(4);
};
CalZoomSchema.statics.getNextZoom = async function (idapp) {

View File

@@ -145,10 +145,10 @@ ExtraListSchema.statics.findByCellAndNameSurname = function (idapp, cell_complet
};
ExtraListSchema.statics.findByIndOrder = function (idapp, ind_order) {
const User = this;
const ExtraList = this;
try {
return User.findOne({
return ExtraList.findOne({
'idapp': idapp,
'ind_order': ind_order,
});
@@ -321,13 +321,6 @@ ExtraListSchema.statics.ImportData = async function (locale, idapp, strdata) {
};
if (tools.INITDB_FIRSTIME) {
console.log(' createIndex User Index...');
// ExtraListSchema.index({ username: 'text', name: 'text', surname: 'text', email: 'text' });
// ExtraListSchema.index({ name: 'name' });
// ExtraListSchema.index({ name: 1 });
// ExtraListSchema.index({ surname: 1 });
}
const ExtraList = mongoose.model('ExtraList', ExtraListSchema);

View File

@@ -0,0 +1,137 @@
var bcrypt = require('bcryptjs');
const mongoose = require('mongoose');
const validator = require('validator');
const jwt = require('jsonwebtoken');
const _ = require('lodash');
const tools = require('../tools/general');
const shared_consts = require('../tools/shared_nodejs');
const queryclass = require('../classes/queryclass');
mongoose.Promise = global.Promise;
mongoose.level = "F";
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
mongoose.set('debug', process.env.DEBUG);
const ListaIngressoSchema = new mongoose.Schema({
idapp: {
type: String,
required: true,
},
indprimario: {
type: Number,
},
ind_order: {
type: Number,
},
username: {
type: String,
},
name: {
type: String,
},
surname: {
type: String,
},
added: { // Added into Programmation (Billettera)
type: Boolean,
default: false,
}
});
ListaIngressoSchema.pre('save', async function (next) {
if (this.isNew) {
const myrec = await ListaIngresso.findOne().limit(1).sort({indprimario:-1});
if (!!myrec) {
if (myrec._doc.indprimario === 0)
this.indprimario = 1;
else
this.indprimario = myrec._doc.indprimario + 10;
} else {
this.indprimario = 10;
}
}
next();
});
// ListaIngressoSchema.methods.toJSON = function () {
// const ListaIngresso = this;
// const userObject = ListaIngresso.toObject();
//
// return _.pick(userObject, ['_id', ...shared_consts.fieldsUserToChange()]);
// };
//
ListaIngressoSchema.statics.findByUsername = function (idapp, username) {
const ListaIngresso = this;
return ListaIngresso.findOne({
'idapp': idapp,
'username': username,
});
};
ListaIngressoSchema.statics.getTotInLista = async function (idapp) {
const ListaIngresso = this;
const myfind = { idapp };
return await ListaIngresso.count(myfind);
};
ListaIngressoSchema.statics.getOrderedList = function (idapp) {
const ListaIngresso = this;
return ListaIngresso.findOne({ idapp }).sort({ indprimario: -1 })
};
ListaIngressoSchema.statics.findByIndOrder = function (idapp, ind_order) {
const ListaIngresso = this;
try {
return ListaIngresso.findOne({
'idapp': idapp,
'ind_order': ind_order,
});
} catch (e) {
}
};
ListaIngressoSchema.statics.getFieldsForSearch = function () {
return ['username', 'name', 'surname', 'ind_order']
};
ListaIngressoSchema.statics.executeQueryTable = function (idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, idapp, params);
};
ListaIngressoSchema.statics.findAllIdApp = function (idapp) {
const ListaIngresso = this;
const myfind = { idapp };
return ListaIngresso.find(myfind, (err, arrrec) => {
return arrrec
});
};
const ListaIngresso = mongoose.model('ListaIngresso', ListaIngressoSchema);
module.exports = { ListaIngresso };

View File

@@ -7,8 +7,12 @@ const _ = require('lodash');
const tools = require('../tools/general');
const { Settings } = require('../models/settings');
const { ListaIngresso } = require('../models/listaingresso');
const { Billettera } = require('./billettera');
const { ExtraList } = require('../models/extralist');
const { ObjectID } = require('mongodb');
const shared_consts = require('../tools/shared_nodejs');
const queryclass = require('../classes/queryclass');
@@ -160,6 +164,9 @@ const UserSchema = new mongoose.Schema({
teleg_id: {
type: Number
},
teleg_id_old: {
type: Number
},
teleg_checkcode: {
type: Number
},
@@ -178,6 +185,9 @@ const UserSchema = new mongoose.Schema({
saw_zoom_presentation: {
type: Boolean
},
special_req: {
type: Boolean
},
sex: {
type: Number,
},
@@ -316,14 +326,24 @@ UserSchema.statics.findByCredentials = function (idapp, username, password) {
};
UserSchema.statics.findByUsername = function (idapp, username) {
UserSchema.statics.findByUsername = async function (idapp, username, alsoemail) {
const User = this;
// /^bar$/i
const regexusername = new RegExp(["^", username, "$"].join(""), "i");
return User.findOne({
return await User.findOne({
'idapp': idapp,
'username': username,
'username': regexusername,
}).then(async (ris) => {
if ((!ris) && (alsoemail)) {
regexemail = new RegExp(["^", username.toLowerCase(), "$"].join(""), "i");
return await User.findOne({
'idapp': idapp,
'email': regexemail,
});
}
return ris;
});
};
@@ -360,6 +380,7 @@ UserSchema.statics.getUserShortDataByUsername = async function (idapp, username)
});
if (myrec) {
myrec.qualified = await User.isUserQualified7(idapp, myrec.username);
myrec.numinvitati = await User.getnumInvitati(idapp, myrec.username);
myrec.numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, myrec.username);
}
@@ -395,6 +416,7 @@ UserSchema.statics.getDownlineByUsername = async function (idapp, username) {
if (!!arrrec) {
for (const rec of arrrec) {
rec._doc.qualified = await User.isUserQualified7(idapp, rec.username);
rec._doc.numinvitati = await User.getnumInvitati(idapp, rec.username);
rec._doc.numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, rec.username);
}
@@ -411,9 +433,55 @@ UserSchema.statics.getnumInvitatiAttivi = function (idapp, username) {
return User.count({
idapp,
aportador_solidario: username,
verified_email: true,
'profile.teleg_id': { $gt: 1 },
'profile.saw_and_accepted': shared_consts.ALL_SAW_AND_ACCEPTED,
'profile.saw_zoom_presentation': true,
'profile.saw_and_accepted': true,
'profile.my_dream': { $exists: true },
$and: [
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.my_dream" }, 10] } },
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.email_paypal" }, 6] } }
],
$where: "this.profile.paymenttypes.length >= 1",
'profile.email_paypal': { $exists: true },
});
};
UserSchema.statics.isUserQualified7 = async function (idapp, username) {
const User = this;
const myrec = await User.findOne({
'idapp': idapp,
'username': username,
$or: [
{
special_req: true
},
{
verified_email: true,
'profile.teleg_id': { $gt: 1 },
'profile.saw_and_accepted': shared_consts.ALL_SAW_AND_ACCEPTED,
'profile.saw_zoom_presentation': true,
'profile.my_dream': { $exists: true },
'profile.email_paypal': { $exists: true },
$and: [
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.my_dream" }, 10] } },
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.email_paypal" }, 6] } }
],
$where: "this.profile.paymenttypes.length >= 1",
}]
});
return !!myrec;
};
UserSchema.statics.getnumPaymentOk = function (idapp) {
const User = this;
return User.count({
idapp,
$where: "this.profile.paymenttypes.length >= 1",
'profile.email_paypal': { $exists: true },
});
};
@@ -488,6 +556,21 @@ UserSchema.statics.getLastUser = function (idapp) {
return User.findOne({ idapp }).sort({ ind_order: -1 })
};
UserSchema.statics.findByIndOrder = function (idapp, ind_order) {
const User = this;
try {
return User.findOne({
'idapp': idapp,
'ind_order': ind_order,
});
} catch (e) {
}
};
UserSchema.pre('save', function (next) {
const user = this;
@@ -561,7 +644,7 @@ UserSchema.statics.TelegIdByUsername = async function (idapp, username) {
});
};
UserSchema.statics.SetTelegramCheckCode = async function (idapp, username, teleg_checkcode) {
UserSchema.statics.SetTelegramCheckCode = async function (idapp, id, teleg_checkcode) {
const User = this;
const fields_to_update = {
@@ -569,25 +652,42 @@ UserSchema.statics.SetTelegramCheckCode = async function (idapp, username, teleg
};
return await User.findOneAndUpdate({
idapp,
username
_id: id
}, { $set: fields_to_update }, { new: false }).then((record) => {
return !!record;
});
};
UserSchema.statics.SetTelegramIdSuccess = async function (idapp, username, teleg_id) {
UserSchema.statics.SetTelegramIdSuccess = async function (idapp, id, teleg_id) {
const User = this;
const fields_to_update = {
'profile.teleg_id': teleg_id,
'profile.teleg_id_old': 0,
'profile.teleg_checkcode': 0
};
return await User.findOneAndUpdate({
idapp,
username
_id: id
}, { $set: fields_to_update }, { new: false }).then((record) => {
return record;
});
};
UserSchema.statics.SetTelegramWasBlocked = async function (idapp, teleg_id) {
const User = this;
const fields_to_update = {
'profile.teleg_id_old': teleg_id,
'profile.teleg_id': 0,
};
const ris = await User.findOneAndUpdate({
idapp,
'profile.teleg_id': teleg_id
}, { $set: fields_to_update }, { new: false }).then((record) => {
return record;
});
@@ -609,7 +709,7 @@ UserSchema.statics.getNameSurnameByUsername = async function (idapp, username) {
UserSchema.statics.getusersManagers = async function (idapp) {
const User = this;
return await User.find({ idapp, 'profile.manage_telegram': true }, { 'profile.teleg_id': 1 })
return await User.find({ idapp, 'profile.manage_telegram': true }, { 'profile.teleg_id': 1, perm: 1 })
.then((arrrec) => {
return (!!arrrec) ? arrrec : null;
}).catch((e) => {
@@ -620,11 +720,11 @@ UserSchema.statics.getusersManagers = async function (idapp) {
UserSchema.statics.getUsersTelegALL = async function (idapp) {
const User = this;
return await User.find({ idapp, 'profile.teleg_id': { $gt: 0 } }, { 'profile.teleg_id': 1, perm: 1 })
return await User.find({ idapp, 'profile.teleg_id': { $gt: 0 } })
.then((arrrec) => {
return (!!arrrec) ? arrrec : null;
}).catch((e) => {
console.error('getusersManagers', e);
console.error('getUsersTelegALL', e);
});
};
@@ -813,6 +913,58 @@ UserSchema.statics.getUsersRegistered = async function (idapp) {
return await User.count(myfind);
};
UserSchema.statics.getUsersQualified = async function (idapp, numinvitati) {
const User = this;
const arrusers = await User.find({
idapp,
$or: [
{
special_req: true
},
{
verified_email: true,
'profile.teleg_id': { $gt: 0 },
$where: "this.profile.paymenttypes.length >= 1",
'profile.saw_and_accepted': shared_consts.ALL_SAW_AND_ACCEPTED,
'profile.saw_zoom_presentation': true,
'profile.my_dream': { $exists: true },
$and: [
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.my_dream" }, 10] } },
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.email_paypal" }, 6] } }
],
}]
}, {
'username': 1,
});
if (numinvitati === 0)
return arrusers; // PRENDI TUTTI
let arrris = [];
for (const rec of arrusers) {
rec.numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, rec.username);
if (rec.numinvitatiattivi >= numinvitati) {
arrris.push(rec);
}
}
return arrris
};
UserSchema.statics.getNumUsersQualified = async function (idapp, numinvitati) {
arrrec = await this.getUsersQualified(idapp, numinvitati);
return arrrec.length
};
UserSchema.statics.getEmailNotVerified = async function (idapp) {
const User = this;
@@ -964,6 +1116,47 @@ if (tools.INITDB_FIRSTIME) {
// UserSchema.index({ surname: 1 });
}
async function addUtentiInLista(idapp, mode) {
let num = 0;
for (const rec of arrusers) {
let ok = false;
let qualified = await User.isUserQualified7(idapp, rec.username);
let numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, rec.username);
if (mode === 1) {
// 9 punti qualificati
ok = qualified && (numinvitatiattivi >= 2);
} else if (mode === 2) {
// 7 punti qualificati
ok = qualified;
} else {
ok = true;
// // almeno telegram ID
// ok = user.profile.teleg_id > 0;
// } else {
// ok = true;
}
if (ok) {
if (!await ListaIngresso.findByUsername(idapp, rec.username)) {
let listaingresso = new ListaIngresso({
username: rec.username,
ind_order: rec.ind_order,
name: rec.name,
surname: rec.surname,
idapp,
_id: new ObjectID()
});
await listaingresso.save();
num++;
}
}
}
return num;
}
UserSchema.statics.DbOp = async function (idapp, mydata) {
const User = this;
try {
@@ -971,14 +1164,52 @@ UserSchema.statics.DbOp = async function (idapp, mydata) {
arrusers = await User.find({ 'idapp': idapp });
let num = 0;
for (const rec of arrusers) {
let mycell = tools.removespaces(rec.profile.intcode_cell + rec.profile.cell);
await User.findOneAndUpdate({ _id: rec._id }, { $set: { 'profile.cell': mycell } })
num++;
// DISATTIVATO: ORA NON MI SERVE PIU
if (false) {
let mycell = tools.removespaces(rec.profile.intcode_cell + rec.profile.cell);
await User.findOneAndUpdate({ _id: rec._id }, { $set: { 'profile.cell': mycell } });
num++;
}
}
return { num };
// return await User.updateMany({ idapp }, { $set: { 'profile.cell': { $concat: ["$profile.intcode_cell", "$profile.cell"] } } })
} else if (mydata.dbop === 'changeEmailLowerCase') {
arrusers = await User.find({ 'idapp': idapp });
let num = 0;
for (const rec of arrusers) {
let myemail = rec.email.toLowerCase();
if (myemail !== rec.email) {
await User.findOneAndUpdate({ _id: rec._id }, { $set: { 'email': myemail } });
num++;
}
}
return { num };
} else if (mydata.dbop === 'creaLista') {
await ListaIngresso.remove({ idapp });
arrusers = await User.find({ 'idapp': idapp }).sort({ ind_order: 1 });
let num = 0;
num += await addUtentiInLista(idapp, 1);
num += await addUtentiInLista(idapp, 2);
// num += await addUtentiInLista(idapp, 3);
// num += await addUtentiInLista(idapp, 4);
return { num };
} else if (mydata.dbop === 'creaBillettera') {
const num = await Billettera.generaBillettera(idapp);
return { num };
} else if (mydata.dbop === 'visuPlacca') {
const placca = await Billettera.getPlaccaByFuoco(idapp, riga, col);
return { placca };
}
} catch (e) {
console.error(e);
@@ -987,6 +1218,7 @@ UserSchema.statics.DbOp = async function (idapp, mydata) {
};
const User = mongoose.model('User', UserSchema);