- Nave
- Requirements - Send Msg to Passeggeri
This commit is contained in:
@@ -1,412 +0,0 @@
|
||||
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 };
|
||||
|
||||
|
||||
@@ -6,6 +6,10 @@ const _ = require('lodash');
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
const { Nave } = require('./nave');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
const queryclass = require('../classes/queryclass');
|
||||
|
||||
@@ -30,16 +34,17 @@ const ListaIngressoSchema = new mongoose.Schema({
|
||||
ind_order: {
|
||||
type: Number,
|
||||
},
|
||||
username: {
|
||||
type: String,
|
||||
date_added: {
|
||||
type: Date,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
added: { // Added into Programmation (Nave)
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
surname: {
|
||||
type: String,
|
||||
num_tess: {
|
||||
type: Number,
|
||||
},
|
||||
added: { // Added into Programmation (Billettera)
|
||||
deleted: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
}
|
||||
@@ -48,7 +53,7 @@ const ListaIngressoSchema = new mongoose.Schema({
|
||||
|
||||
ListaIngressoSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
const myrec = await ListaIngresso.findOne().limit(1).sort({indprimario:-1});
|
||||
const myrec = await ListaIngresso.findOne().limit(1).sort({ indprimario: -1 });
|
||||
if (!!myrec) {
|
||||
if (myrec._doc.indprimario === 0)
|
||||
this.indprimario = 1;
|
||||
@@ -108,9 +113,123 @@ ListaIngressoSchema.statics.findByIndOrder = function (idapp, ind_order) {
|
||||
}
|
||||
};
|
||||
|
||||
ListaIngressoSchema.statics.findByIndOrderETess = function (idapp, ind_order, num_tess) {
|
||||
const ListaIngresso = this;
|
||||
|
||||
try {
|
||||
return ListaIngresso.findOne({
|
||||
'idapp': idapp,
|
||||
'ind_order': ind_order,
|
||||
num_tess,
|
||||
});
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
ListaIngressoSchema.statics.deleteUserInListaIngresso = async function (idapp, ind_order) {
|
||||
const ListaIngresso = this;
|
||||
|
||||
return ListaIngresso.findOneAndUpdate({
|
||||
idapp,
|
||||
ind_order,
|
||||
}, { $set: { deleted: true } }, { new: false })
|
||||
|
||||
};
|
||||
|
||||
ListaIngressoSchema.statics.addUserInListaIngresso = async function (idapp, ind_order, lang, addednowreal, num_tess) {
|
||||
const ListaIngresso = this;
|
||||
|
||||
const { User } = require('./user');
|
||||
const telegrambot = require('../telegram/telegrambot');
|
||||
|
||||
try {
|
||||
let listaingresso = null;
|
||||
if (!await ListaIngresso.findByIndOrderETess(idapp, ind_order, num_tess)) {
|
||||
listaingresso = new ListaIngresso({
|
||||
ind_order: ind_order,
|
||||
idapp,
|
||||
num_tess,
|
||||
date_added: new Date(),
|
||||
_id: new ObjectID()
|
||||
});
|
||||
|
||||
if (listaingresso) {
|
||||
return await listaingresso.save().then(async (ris) => {
|
||||
if (addednowreal) {
|
||||
if (!!ris) {
|
||||
msgtext = tools.gettranslate('ADDED_TOLISTAINGRESSO', lang);
|
||||
const username = await User.getUsernameByIndOrder(idapp, ind_order);
|
||||
await telegrambot.sendMsgTelegram(idapp, username, msgtext, true); // Anche a STAFF
|
||||
}
|
||||
}
|
||||
return ris;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const giapresente = await Nave.findOne({ idapp, ind_order: num_tess });
|
||||
if (!!giapresente) {
|
||||
// Era stato già aggiunto!
|
||||
let fields_to_update = { added: true };
|
||||
await ListaIngresso.findOneAndUpdate({ _id: params.id.toString() }, { $set: fields_to_update }, { new: false });
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
ListaIngressoSchema.statics.showListaOrd = async function (idapp) {
|
||||
const ListaIngresso = this;
|
||||
|
||||
const myquery = getQueryProj({ idapp });
|
||||
|
||||
arrrec = await ListaIngresso.aggregate(myquery).sort({ indprimario: 1 });
|
||||
|
||||
let mystr = '';
|
||||
let conta = 1;
|
||||
for (const rec of arrrec) {
|
||||
mystr += '[' + conta + '] ' + rec.ind_order + ' (' + rec.ind_order + ') ' + rec.name + ' ' + rec.surname;
|
||||
if (rec.added)
|
||||
mystr += ' (ADDED ++)';
|
||||
|
||||
mystr += '\n';
|
||||
conta++;
|
||||
}
|
||||
|
||||
return mystr;
|
||||
};
|
||||
|
||||
|
||||
ListaIngressoSchema.statics.getFieldsForSearch = function () {
|
||||
return ['username', 'name', 'surname', 'ind_order']
|
||||
return ['ind_order']
|
||||
};
|
||||
|
||||
ListaIngressoSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
@@ -128,6 +247,45 @@ ListaIngressoSchema.statics.findAllIdApp = function (idapp) {
|
||||
});
|
||||
};
|
||||
|
||||
function sortRec(rec) {
|
||||
return rec.sort(function (reca, recb) {
|
||||
return recb.numinvitatiattivi - reca.numinvitatiattivi
|
||||
});
|
||||
}
|
||||
|
||||
ListaIngressoSchema.statics.getProssimiInLista = async function (idapp, tutti) {
|
||||
const ListaIngresso = this;
|
||||
|
||||
const myquery = getQueryProj({
|
||||
'idapp': idapp,
|
||||
ind_order: { $gt: 0 },
|
||||
added: false,
|
||||
deleted: false,
|
||||
});
|
||||
|
||||
arrrec = await ListaIngresso.aggregate(myquery).sort({ indprimario: 1 })
|
||||
.then(async (arrlista) => {
|
||||
|
||||
const { User } = require('../models/user');
|
||||
|
||||
for (const rec of arrlista) {
|
||||
rec.numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, rec.username);
|
||||
if (rec.numinvitatiattivi > 2)
|
||||
rec.numinvitatiattivi = 2;
|
||||
}
|
||||
if (arrlista) {
|
||||
arrlista = sortRec(arrlista);
|
||||
// arrlista.reverse();
|
||||
}
|
||||
|
||||
return arrlista;
|
||||
}).catch((e) => {
|
||||
console.error(e);
|
||||
return null
|
||||
});
|
||||
|
||||
return arrrec;
|
||||
};
|
||||
|
||||
const ListaIngresso = mongoose.model('ListaIngresso', ListaIngressoSchema);
|
||||
|
||||
|
||||
991
src/server/models/nave.js
Normal file
991
src/server/models/nave.js
Normal file
@@ -0,0 +1,991 @@
|
||||
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 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 NaveSchema = new mongoose.Schema({
|
||||
idapp: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
riga: {
|
||||
type: Number,
|
||||
},
|
||||
col: {
|
||||
type: Number,
|
||||
},
|
||||
indprimario: {
|
||||
type: Number,
|
||||
},
|
||||
ind_order: {
|
||||
type: Number,
|
||||
},
|
||||
parent_id: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
},
|
||||
date_start: {
|
||||
type: Date
|
||||
},
|
||||
link_chat: {
|
||||
type: String,
|
||||
},
|
||||
sent_msg_howto_make_gift: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
made_gift: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
date_made_gift: {
|
||||
type: Date,
|
||||
},
|
||||
received_gift: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
date_received_gift: {
|
||||
type: Date,
|
||||
},
|
||||
created: {
|
||||
type: Date,
|
||||
},
|
||||
num_tess: { // numero di tessitura
|
||||
type: Number,
|
||||
default: 1
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
NaveSchema.statics.getTotInLista = async function (idapp) {
|
||||
const Nave = this;
|
||||
|
||||
const myfind = { idapp };
|
||||
|
||||
return await Nave.count(myfind);
|
||||
};
|
||||
|
||||
NaveSchema.statics.findByIndOrder = function (idapp, ind_order) {
|
||||
const Nave = this;
|
||||
|
||||
try {
|
||||
return Nave.findOne({
|
||||
'idapp': idapp,
|
||||
'ind_order': ind_order,
|
||||
});
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
NaveSchema.statics.findById = function (idapp, id) {
|
||||
const Nave = this;
|
||||
|
||||
const myquery = getQueryProj({ idapp, '_id': ObjectID(id) });
|
||||
|
||||
return Nave.aggregate(myquery);
|
||||
|
||||
};
|
||||
|
||||
NaveSchema.statics.findByIndPrimario = function (idapp, indprimario) {
|
||||
const Nave = this;
|
||||
|
||||
try {
|
||||
return Nave.findOne({
|
||||
idapp,
|
||||
indprimario,
|
||||
});
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
NaveSchema.statics.getFieldsForSearch = function () {
|
||||
return ['username', 'name', 'surname', 'ind_order']
|
||||
};
|
||||
|
||||
NaveSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
NaveSchema.statics.findAllIdApp = function (idapp) {
|
||||
const Nave = this;
|
||||
|
||||
const myfind = { idapp };
|
||||
|
||||
return Nave.find(myfind, (err, arrrec) => {
|
||||
return arrrec
|
||||
});
|
||||
};
|
||||
|
||||
NaveSchema.statics.findByRigaCol = function (idapp, riga, col, nullifnotexist) {
|
||||
const Nave = this;
|
||||
|
||||
myrigacol = {
|
||||
idapp,
|
||||
riga,
|
||||
col,
|
||||
nullifnotexist
|
||||
};
|
||||
|
||||
return Nave.findGeneric(myrigacol);
|
||||
|
||||
};
|
||||
|
||||
NaveSchema.statics.findDonatoreByNave = function (idapp, nave) {
|
||||
try {
|
||||
|
||||
const arrrigacol = nave.split(".");
|
||||
if (arrrigacol.length <= 0)
|
||||
return;
|
||||
|
||||
let riganave = parseInt(arrrigacol[0]);
|
||||
let colnave = parseInt(arrrigacol[1]);
|
||||
|
||||
let rigadonatore = riganave + 3;
|
||||
if (rigadonatore < 1)
|
||||
rigadonatore = 1;
|
||||
|
||||
coldonatoreIni = calcval(riganave, colnave, 8) + (1);
|
||||
coldonatoreFine = calcval(riganave, colnave, 8) + (8);
|
||||
|
||||
const miaquery = {
|
||||
idapp,
|
||||
riga: rigadonatore,
|
||||
$and: [{ col: { $gte: { coldonatoreIni } } }, { col: { $lte: { coldonatoreFine } } }]
|
||||
};
|
||||
|
||||
return Nave.findOne(miaquery);
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
function getIndColonneByNave(navemediatore) {
|
||||
let riga = navemediatore.riga;
|
||||
let col = navemediatore.col;
|
||||
|
||||
let col_ini = calcval(riga, col, 8) + 1;
|
||||
let col_fine = col_ini + 8;
|
||||
|
||||
return { riga: riga + 3, col_ini, col_fine }
|
||||
}
|
||||
|
||||
NaveSchema.statics.getusersByNave = function (idapp, navemediatore) {
|
||||
|
||||
const obj = getIndColonneByNave(navemediatore);
|
||||
|
||||
const miacol_ini = obj.col_ini;
|
||||
const miacol_fine = obj.col_fine;
|
||||
|
||||
const miaquery = {
|
||||
idapp,
|
||||
riga: obj.riga,
|
||||
$and: [
|
||||
{ col: { $gte: miacol_ini } },
|
||||
{ col: { $lte: miacol_fine } }
|
||||
],
|
||||
};
|
||||
|
||||
return Nave.find(miaquery);
|
||||
|
||||
};
|
||||
|
||||
|
||||
NaveSchema.statics.findRecByRigaColParent = async function (idapp, riga, col, numparentUp) {
|
||||
const Nave = this;
|
||||
|
||||
const { User } = require('./user');
|
||||
|
||||
const myrigacol = {
|
||||
idapp,
|
||||
riga,
|
||||
col
|
||||
};
|
||||
|
||||
if (numparentUp === 0) {
|
||||
return await Nave.findGeneric(myrigacol);
|
||||
}
|
||||
|
||||
let parentup = 0;
|
||||
let myrec = null;
|
||||
let lastrec = null;
|
||||
|
||||
while (parentup < numparentUp) {
|
||||
|
||||
myrec = await Nave.findGeneric(myrigacol);
|
||||
if (!!myrec) {
|
||||
if (myrec.parent_id === "0") {
|
||||
break;
|
||||
}
|
||||
|
||||
recfind = await Nave.findById(idapp, myrec.parent_id);
|
||||
if (!!recfind) {
|
||||
if (recfind.length > 0) {
|
||||
recfind = recfind[0];
|
||||
lastrec = recfind;
|
||||
myrigacol.riga = lastrec.riga;
|
||||
myrigacol.col = lastrec.col;
|
||||
} else {
|
||||
lastrec = await User.findByIndOrder(idapp, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
parentup++;
|
||||
}
|
||||
|
||||
if (!lastrec) {
|
||||
return await User.findByIndOrder(idapp, 0);
|
||||
}
|
||||
|
||||
return lastrec;
|
||||
|
||||
};
|
||||
|
||||
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) {
|
||||
mypos.riga = mypos.riga - mypos.numup;
|
||||
mypos.col = Math.floor(mypos.col / (Math.pow(2, mypos.numup)));
|
||||
// if ((mypos.col % 2) !== 0)
|
||||
// mypos.col++;
|
||||
|
||||
}
|
||||
|
||||
function getRigaColGenerica(idapp, riga, col, numup) {
|
||||
mypos = {
|
||||
idapp,
|
||||
riga,
|
||||
col,
|
||||
numup
|
||||
};
|
||||
|
||||
if (idapp === tools.AYNI) {
|
||||
getRigaColByPosUp(mypos);
|
||||
ris = getlimiti(mypos);
|
||||
}
|
||||
|
||||
return ris;
|
||||
}
|
||||
|
||||
function getRigaColSognatoreByFuoco(idapp, riga, col) {
|
||||
return getRigaColGenerica(idapp, riga, col, 6);
|
||||
}
|
||||
|
||||
function getRigaColMediatoreByFuoco(idapp, riga, col) {
|
||||
return getRigaColGenerica(idapp, riga, col, 3);
|
||||
}
|
||||
|
||||
NaveSchema.statics.findGeneric = function (myrigacol) {
|
||||
|
||||
const { ListaIngresso } = require('./listaingresso');
|
||||
|
||||
const myquery = getQueryProj({ idapp: myrigacol.idapp, riga: myrigacol.riga, col: myrigacol.col });
|
||||
|
||||
return Nave.aggregate(myquery)
|
||||
.then(async (rec) => {
|
||||
if (!rec || rec.length === 0) {
|
||||
if (myrigacol.nullifnotexist)
|
||||
return null;
|
||||
|
||||
const ris = await ListaIngresso.findByIndOrder(myrigacol.idapp, 0);
|
||||
const arr = [];
|
||||
arr.push(ris);
|
||||
return arr;
|
||||
}
|
||||
else {
|
||||
return rec;
|
||||
}
|
||||
}
|
||||
).then(async (rec) => {
|
||||
|
||||
const { User } = require('./user');
|
||||
|
||||
if (!!rec) {
|
||||
if (rec.length > 0) {
|
||||
// console.log('rec', rec);
|
||||
// console.table('myrigacol', myrigacol);
|
||||
if (!!rec[0]) {
|
||||
const newrec = await User.getSmallRecByIndOrder(myrigacol.idapp, rec[0].ind_order);
|
||||
if (!!newrec) {
|
||||
let myarr = {};
|
||||
if (rec[0]._doc === undefined)
|
||||
myarr = { ...newrec._doc, ...rec[0] };
|
||||
else
|
||||
myarr = { ...newrec._doc, ...rec[0]._doc };
|
||||
return myarr;
|
||||
} else {
|
||||
let myarr = null;
|
||||
if (rec[0]._doc === undefined)
|
||||
myarr = { ...newrec._doc, ...rec[0] };
|
||||
else
|
||||
myarr = { ...newrec._doc, ...rec[0]._doc };
|
||||
|
||||
return myarr;
|
||||
}
|
||||
} else {
|
||||
const ris = await ListaIngresso.findByIndOrder(myrigacol.idapp, 0);
|
||||
if (!!ris)
|
||||
return ris[0]
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}).catch((e) => {
|
||||
console.error(e);
|
||||
});
|
||||
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
NaveSchema.statics.findSognatoriByFuoco = async function (idapp, riga, col, offset) {
|
||||
const Nave = this;
|
||||
|
||||
// const myrigacol = getRigaColSognatoreByFuoco(idapp, riga, col);
|
||||
|
||||
// return Nave.findGeneric(myrigacol);
|
||||
|
||||
return [await Nave.findRecByRigaColParent(idapp, riga, col, 6 - offset),
|
||||
await Nave.findRecByRigaColParent(idapp, riga, col, 5 - offset),
|
||||
await Nave.findRecByRigaColParent(idapp, riga, col, 4 - offset)
|
||||
]
|
||||
|
||||
};
|
||||
|
||||
|
||||
NaveSchema.statics.findMediatoreByFuoco = async function (idapp, riga, col, offset) {
|
||||
const Nave = this;
|
||||
|
||||
// const myrigacol = getRigaColMediatoreByFuoco(idapp, riga, col);
|
||||
// return Nave.findGeneric(myrigacol);
|
||||
return await Nave.findRecByRigaColParent(idapp, riga, col, 3 - offset);
|
||||
|
||||
|
||||
};
|
||||
|
||||
function getQueryProj(myfilter) {
|
||||
|
||||
myobjField = {
|
||||
_id: 1,
|
||||
lang: 1,
|
||||
ind_order: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
username: 1,
|
||||
date_start: 1,
|
||||
made_gift: 1,
|
||||
link_chat: 1,
|
||||
date_made_gift: 1,
|
||||
received_gift: 1,
|
||||
date_received_gift: 1,
|
||||
num_tess: 1,
|
||||
indprimario: 1,
|
||||
parent_id: 1,
|
||||
riga: 1,
|
||||
col: 1,
|
||||
created: 1,
|
||||
};
|
||||
|
||||
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"] } }
|
||||
// $replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$user", 0] },] } }
|
||||
},
|
||||
{ $project: myobjField }
|
||||
];
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
|
||||
NaveSchema.statics.setRiga = function (idapp, riga) {
|
||||
return Settings.setKeyNum(idapp, 'riga', riga);
|
||||
};
|
||||
|
||||
NaveSchema.statics.getRiga = function (idapp) {
|
||||
return Settings.getKeyNum(idapp, 'riga', 1);
|
||||
};
|
||||
|
||||
NaveSchema.statics.setCol = function (idapp, col) {
|
||||
return Settings.setKeyNum(idapp, 'col', col);
|
||||
};
|
||||
|
||||
NaveSchema.statics.getCol = function (idapp) {
|
||||
return Settings.getKeyNum(idapp, 'col', 1);
|
||||
};
|
||||
|
||||
function getmaxcol(riga) {
|
||||
|
||||
return Math.pow(2, riga - 1);
|
||||
}
|
||||
|
||||
function getPrimoFuocoByIndCol(col) {
|
||||
return Math.floor(col - (col % 8)) + 1;
|
||||
}
|
||||
|
||||
async function getusertextbyrec(myrec, symbol, lettera, riga, col, ind) {
|
||||
let visu_test = false;
|
||||
if (!!myrec)
|
||||
visu_test = await Settings.getValDbSettings(myrec.idapp, 'VISU_TEST');
|
||||
|
||||
if (!visu_test) {
|
||||
if (myrec)
|
||||
return lettera + ind + ' - ' + symbol + ' ' + myrec.name + ' ' + tools.getFirst2Car(myrec.surname) + ' (' + myrec.username + ')';
|
||||
else
|
||||
return lettera + ind + ' - ' + symbol;
|
||||
|
||||
} else {
|
||||
if (myrec)
|
||||
return lettera + ind + ' - ' + symbol + '[' + miariga + ',' + miacol + ']' + ' ' + myrec.name + ' ' + myrec.surname + '';
|
||||
else
|
||||
return lettera + ind + ' - ' + symbol;
|
||||
}
|
||||
}
|
||||
|
||||
NaveSchema.statics.getPlaccaGenerica = async function (idapp, riga, col, offset, solorecord) {
|
||||
const Nave = this;
|
||||
|
||||
try {
|
||||
let recsognatori = await Nave.findSognatoriByFuoco(idapp, riga, col, offset);
|
||||
let recmediatore = await Nave.findMediatoreByFuoco(idapp, riga, col, offset);
|
||||
|
||||
let primofuoco = getPrimoFuocoByIndCol(col);
|
||||
|
||||
mystr = tools.ACAPO;
|
||||
|
||||
mystr += 'GIFTING CHAT (' + riga + '.' + col + ') ' + tools.ACAPO + tools.ACAPO;
|
||||
|
||||
if (offset === tools.Placca.SONOFUOCO) {
|
||||
mystr += tools.Placca.SOGNATORE + tools.Placca.STR_SOGNATORE + ': ' + await getusertextbyrec(recsognatori[0], '', '', riga, col, '') + tools.ACAPO + tools.ACAPO;
|
||||
mystr += tools.Placca.MEDIATORE + tools.Placca.STR_MEDIATORE + ': ' + await getusertextbyrec(recmediatore, '', '', riga, col, '') + tools.ACAPO + tools.ACAPO;
|
||||
}
|
||||
|
||||
if (offset === tools.Placca.SONOACQUA) {
|
||||
mystr += tools.Placca.SOGNATORE + tools.Placca.STR_SOGNATORE + ': ' + await getusertextbyrec(recmediatore, '', '', riga, col, '') + tools.ACAPO + tools.ACAPO;
|
||||
}
|
||||
|
||||
let symb = {
|
||||
car: 'D',
|
||||
icona: '🔥'
|
||||
};
|
||||
|
||||
if (offset === tools.Placca.SONOFUOCO) {
|
||||
mystr += tools.Placca.STR_DONATORI + ':' + tools.ACAPO;
|
||||
} else if (offset === tools.Placca.SONOACQUA) {
|
||||
mystr += tools.Placca.STR_MEDIATORI + ':' + tools.ACAPO;
|
||||
symb = {
|
||||
car: 'A',
|
||||
icona: '💦'
|
||||
};
|
||||
}
|
||||
|
||||
// mystr += '🔥🌏💦💨🔥🌏💦💨' + tools.ACAPO;
|
||||
|
||||
let arrdonatori = [];
|
||||
let ind = 1;
|
||||
for (let indcol = primofuoco; indcol < primofuoco + 8; indcol++) {
|
||||
let indr = riga + offset;
|
||||
let indc = indcol + (offset * indr);
|
||||
|
||||
indr = riga + offset;
|
||||
indc = calcval(riga, col, 8) + (indcol - primofuoco + 1);
|
||||
// miacol = calcval(riga, col, 8) + (indfuoco);
|
||||
|
||||
|
||||
let recfuoco = await Nave.findByRigaCol(idapp, indr, indc, true);
|
||||
arrdonatori.push(recfuoco);
|
||||
mystr += await getusertextbyrec(recfuoco, symb.icona, symb.car, indr, indc, ind) + tools.ACAPO;
|
||||
ind++;
|
||||
}
|
||||
|
||||
if (solorecord) {
|
||||
res = {
|
||||
recsognatori,
|
||||
recmediatore,
|
||||
arrdonatori
|
||||
};
|
||||
|
||||
return res;
|
||||
} else {
|
||||
return mystr;
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
NaveSchema.statics.getPlaccaPerDonatore = async function (idapp, riga, col, solorecord) {
|
||||
const Nave = this;
|
||||
return Nave.getPlaccaGenerica(idapp, riga, col, tools.Placca.SONOFUOCO, solorecord);
|
||||
};
|
||||
|
||||
NaveSchema.statics.getPlaccaPerMediatore = async function (idapp, riga, col, solorecord) {
|
||||
const Nave = this;
|
||||
return Nave.getPlaccaGenerica(idapp, riga, col, tools.Placca.SONOACQUA, solorecord);
|
||||
};
|
||||
|
||||
function calcval(riga, col, quanti) {
|
||||
return (quanti * (col - 1));
|
||||
}
|
||||
|
||||
NaveSchema.statics.getNavePos = async function (idapp, riga, col, solorecord) {
|
||||
const Nave = this;
|
||||
|
||||
try {
|
||||
let recsognatori = [await Nave.findRecByRigaColParent(idapp, riga, col, 3),
|
||||
await Nave.findRecByRigaColParent(idapp, riga, col, 2),
|
||||
await Nave.findRecByRigaColParent(idapp, riga, col, 1)];
|
||||
|
||||
let recmediatore = await Nave.findByRigaCol(idapp, riga, col, true);
|
||||
|
||||
|
||||
mystr = '🌈SOGNATORE: ';
|
||||
for (let indsogn = 0; indsogn < recsognatori.length; indsogn++) {
|
||||
mystr += 'A' + (3 - indsogn) + await getusertextbyrec(recsognatori[indsogn], '', '', riga, col, '') + tools.ACAPO;
|
||||
}
|
||||
|
||||
mystr += tools.ACAPO + '🌀 MEDIATORE:' + await getusertextbyrec(recmediatore, '', '', riga, col, '') + tools.ACAPO + tools.ACAPO;
|
||||
|
||||
for (let indterra = 1; indterra <= 2; indterra++) {
|
||||
miacol = calcval(riga, col, 2) + (indterra);
|
||||
miariga = riga + 1;
|
||||
let recterra = await Nave.findByRigaCol(idapp, miariga, miacol, true);
|
||||
mystr += await getusertextbyrec(recterra, '', 'B', miariga, miacol, indterra) + tools.ACAPO;
|
||||
}
|
||||
|
||||
mystr += tools.ACAPO;
|
||||
|
||||
for (let indaria = 1; indaria <= 4; indaria++) {
|
||||
miacol = calcval(riga, col, 4) + (indaria);
|
||||
miariga = riga + 2;
|
||||
let recaria = await Nave.findByRigaCol(idapp, miariga, miacol, true);
|
||||
mystr += await getusertextbyrec(recaria, '', 'C', miariga, miacol, indaria) + tools.ACAPO;
|
||||
}
|
||||
|
||||
mystr += tools.ACAPO;
|
||||
|
||||
let primofuoco = null;
|
||||
|
||||
mystr += '🎁 DONATORI:' + tools.ACAPO;
|
||||
for (let indfuoco = 1; indfuoco <= 8; indfuoco++) {
|
||||
miacol = calcval(riga, col, 8) + (indfuoco);
|
||||
miariga = riga + 3;
|
||||
// miariga = riga + 2;
|
||||
let recfuoco = await Nave.findByRigaCol(idapp, miariga, miacol, true);
|
||||
if (indfuoco === 1)
|
||||
primofuoco = recfuoco;
|
||||
mystr += await getusertextbyrec(recfuoco, '', 'D', miariga, miacol, indfuoco) + tools.ACAPO;
|
||||
}
|
||||
|
||||
let data = "";
|
||||
if (primofuoco)
|
||||
data = "Partenza il " + tools.getstrDateLong(primofuoco.date_start) + tools.ACAPO;
|
||||
else
|
||||
data = "";
|
||||
|
||||
mystr = tools.ACAPO + 'NAVE (' + riga + '.' + col + ') ' + tools.ACAPO + data + tools.ACAPO + mystr;
|
||||
|
||||
return mystr;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
async function Fuochi8Completati(idapp, params) {
|
||||
// Inviare un msg al Mediatore che può aprire la Chat con gli 8 fuochi
|
||||
const telegrambot = require('../telegram/telegrambot');
|
||||
|
||||
let text = '\nCompletata NAVE [riga=' + params.riga + ',col=' + params.col + ', ind_order=' + params.ind_order + ']';
|
||||
console.log(text);
|
||||
tools.writeNaveLog(text);
|
||||
|
||||
const { User } = require('./user');
|
||||
|
||||
const rec = await User.findByIndOrder(idapp, params.ind_order);
|
||||
|
||||
text = await Nave.getNaveByUser(idapp, params.ind_order, rec.lang, true);
|
||||
|
||||
// Inviare un msg a questi 8 Fuochi, che la loro placca è Pronta !
|
||||
|
||||
if (tools.isAbilitaNave(idapp)) {
|
||||
// .............
|
||||
}
|
||||
|
||||
if (false) {
|
||||
await telegrambot.sendMsgTelegram(idapp, rec.username, text, true);
|
||||
} else {
|
||||
await telegrambot.sendMsgTelegramToTheAdmin(idapp, text);
|
||||
}
|
||||
|
||||
// Inviare la placca a Managers
|
||||
// await telegrambot.sendMsgTelegramToTheManagers(idapp, txt);
|
||||
}
|
||||
|
||||
NaveSchema.statics.getArrPosizioniByIndOrder = async function (idapp, ind_order) {
|
||||
const Nave = this;
|
||||
|
||||
arrposizioni = await Nave.find({ 'idapp': idapp, ind_order }).sort({ riga: 1, col: 1 });
|
||||
|
||||
return arrposizioni;
|
||||
};
|
||||
|
||||
NaveSchema.statics.getPrimaNaveByRiga = async function (idapp, riga) {
|
||||
const Nave = this;
|
||||
|
||||
nave = await Nave.find({ 'idapp': idapp, riga: (riga + 3), col: 1 });
|
||||
|
||||
return nave;
|
||||
};
|
||||
|
||||
NaveSchema.statics.showListaOrd = async function (idapp) {
|
||||
const Nave = this;
|
||||
|
||||
const myquery = getQueryProj({ idapp });
|
||||
|
||||
arrrec = await Nave.aggregate(myquery).sort({ riga: 1, col: 1 });
|
||||
|
||||
let mystr = '';
|
||||
let conta = 1;
|
||||
for (const rec of arrrec) {
|
||||
mystr += '[' + conta + '] [' + rec.riga + '.' + rec.col + '] ' + rec.ind_order + ' ' + rec.name + ' ' + rec.surname + ' (' + tools.getstrDateShort(rec.date_start) + ')\n';
|
||||
conta++;
|
||||
}
|
||||
|
||||
|
||||
return mystr;
|
||||
};
|
||||
|
||||
async function addRecordNaveByParams(params, siRitesse) {
|
||||
const { ListaIngresso } = require('./listaingresso');
|
||||
|
||||
if (!siRitesse) {
|
||||
// Check if Exist:
|
||||
const giapresente = await Nave.findOne({ idapp: params.idapp, ind_order: params.ind_order, num_tess: params.num_tess });
|
||||
if (!!giapresente) {
|
||||
let fields_to_update = { added: true };
|
||||
await ListaIngresso.findOneAndUpdate({ _id: params.id.toString() }, { $set: fields_to_update }, { new: false });
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let myNave = new Nave({
|
||||
idapp: params.idapp,
|
||||
indprimario: params.indprimario,
|
||||
ind_order: params.ind_order,
|
||||
riga: params.riga,
|
||||
col: params.col,
|
||||
date_start: params.date_start,
|
||||
num_tess: params.num_tess,
|
||||
});
|
||||
myNave.created = new Date();
|
||||
|
||||
console.log('[' + params.riga + ',' + params.col + ']');
|
||||
|
||||
const recfindparent = await Nave.findByRigaCol(idapp, params.rigaparent, params.colparent, false);
|
||||
if (!!recfindparent) {
|
||||
myNave.parent_id = recfindparent._id;
|
||||
} else {
|
||||
myNave.parent_id = "0";
|
||||
}
|
||||
|
||||
console.log('addRecordNaveByParams (' + myNave.parent_id + ')');
|
||||
|
||||
return await myNave.save()
|
||||
.then(async (result) => {
|
||||
|
||||
if (!!result) {
|
||||
|
||||
let fields_to_update = { added: true };
|
||||
await ListaIngresso.findOneAndUpdate({ _id: params.id.toString() }, { $set: fields_to_update }, { new: false });
|
||||
|
||||
params.conta++;
|
||||
|
||||
// Check if the Ship has Completed
|
||||
if (idapp === tools.AYNI) {
|
||||
if ((params.col % 8) === 0) {
|
||||
// Completed 8 people
|
||||
if (!params.primavolta) {
|
||||
await Fuochi8Completati(idapp, params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Next
|
||||
if (params.col === params.maxcol) {
|
||||
params.riga++;
|
||||
params.rigaparent = params.riga - 1;
|
||||
params.col = 1;
|
||||
params.maxcol = getmaxcol(params.riga);
|
||||
} else {
|
||||
params.col++;
|
||||
}
|
||||
|
||||
if (params.riga === 2)
|
||||
params.colparent = 1;
|
||||
else
|
||||
params.colparent = Math.ceil(params.col / 2);
|
||||
|
||||
await Nave.setRiga(idapp, params.riga);
|
||||
await Nave.setCol(idapp, params.col);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}).catch((e) => {
|
||||
console.error(e);
|
||||
});
|
||||
}
|
||||
|
||||
NaveSchema.statics.checkifDeveRitessersi = async function (recuser) {
|
||||
const Nave = this;
|
||||
|
||||
let deveritessersi = true;
|
||||
|
||||
arrrec = await Nave.find({ idapp: recuser.idapp, ind_order: recuser.ind_order });
|
||||
|
||||
if (!!arrrec) {
|
||||
if (arrrec.length > 2) {
|
||||
// deveritessersi = await User.deveRitessersi(recuser.idapp, recuser.ind_order)
|
||||
deveritessersi = false;
|
||||
}
|
||||
}
|
||||
|
||||
return { deveritessersi, num_tess: arrrec.length };
|
||||
|
||||
};
|
||||
|
||||
|
||||
NaveSchema.statics.addUserFromListaIngresso_IntoNave = async function (init, idapp, params, addednowreal) {
|
||||
const Nave = this;
|
||||
|
||||
const { User } = require('./user');
|
||||
|
||||
if (init) {
|
||||
params.idapp = idapp;
|
||||
params.conta = 0;
|
||||
}
|
||||
|
||||
params.primavolta = (params.riga === 1) && (params.col === 1);
|
||||
params.riga = await Nave.getRiga(idapp);
|
||||
params.col = await Nave.getCol(idapp);
|
||||
params.maxcol = getmaxcol(params.riga);
|
||||
params.colparent = Math.ceil(params.col / 2);
|
||||
params.rigaparent = params.riga - 1;
|
||||
|
||||
myriga = params.riga;
|
||||
mycol = params.col;
|
||||
|
||||
const inserito = await addRecordNaveByParams(params, false);
|
||||
if (inserito) {
|
||||
if (idapp === tools.AYNI) {
|
||||
if (((params.col) % 8) === 0) {
|
||||
// Trova se la persona di 3 livelli sopra, si deve ritessere
|
||||
let recmediatore = await Nave.findMediatoreByFuoco(idapp, myriga, mycol, 0);
|
||||
if (!!recmediatore) {
|
||||
const ris = await Nave.checkifDeveRitessersi(recmediatore);
|
||||
if (ris.num_tess > 2) {
|
||||
console.log('E\' arrivato alla TERZA RITESSITURA, PERTANTO LO METTIAMO IN CODA... [riga=', params.riga, 'col', params.col, '] indorder=' + recmediatore.ind_order);
|
||||
// E' arrivato alla TERZA RITESSITURA, PERTANTO LO METTIAMO IN CODA...
|
||||
const risultato = await ListaIngresso.addUserInListaIngresso(idapp, recmediatore.ind_order, rec.lang, false, ris.num_tess);
|
||||
|
||||
} else {
|
||||
console.log('Si deve ritessere: [riga=', params.riga, 'col', params.col, ']');
|
||||
if (ris.deveritessersi) {
|
||||
params.indprimario = recmediatore.indprimario;
|
||||
params.ind_order = recmediatore.ind_order;
|
||||
params.id = recmediatore._id;
|
||||
params.num_tess = ris.num_tess;
|
||||
|
||||
await addRecordNaveByParams(params, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((params.riga === 4 + 3) && (params.col === (8 * 2) + 3)) {
|
||||
// Si ritesse il Fondo AYNI nella Nave 3.3
|
||||
const userFondo = await User.findByIndOrder(idapp, 0);
|
||||
params.indprimario = userFondo.indprimario;
|
||||
params.ind_order = userFondo.ind_order;
|
||||
params.id = userFondo._id;
|
||||
params.num_tess = userFondo.num_tess;
|
||||
|
||||
await addRecordNaveByParams(params, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Se ho completato 8 persone, allora
|
||||
if (addednowreal) {
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
NaveSchema.statics.generaNave = async function (idapp, mydata) {
|
||||
const Nave = this;
|
||||
|
||||
const { User } = require('./user');
|
||||
const { ListaIngresso } = require('./listaingresso');
|
||||
|
||||
let params = {
|
||||
idapp,
|
||||
riga: await Nave.getRiga(idapp),
|
||||
col: await Nave.getCol(idapp),
|
||||
date_start: mydata.date_start,
|
||||
numpersone: mydata.numpersone,
|
||||
};
|
||||
|
||||
params.primavolta = (params.riga === 1) && (params.col === 1);
|
||||
// params.primavolta = false;
|
||||
|
||||
const recfindFondo = await Nave.findByRigaCol(params.idapp, 0, 0, true);
|
||||
if (!recfindFondo) {
|
||||
let myNave = new Nave({ idapp, indprimario: 0, ind_order: 0, riga: 0, col: 0 });
|
||||
myNave.created = new Date();
|
||||
myNave.parent_id = ObjectID("5e592aecbfd0b75f3021d9c9");
|
||||
myNave.date_start = params.date_start;
|
||||
await myNave.save();
|
||||
|
||||
const userFondo = await User.findByIndOrder(idapp, 0);
|
||||
if (!userFondo || userFondo === undefined) {
|
||||
await telegrambot.sendMsgTelegramToTheAdmin(idapp, 'Devi creare l\'utente FONDO , con ind_order = 0 ! ');
|
||||
}
|
||||
}
|
||||
|
||||
const arrlistaingresso = await ListaIngresso.getProssimiInLista(idapp, true);
|
||||
|
||||
let index = 0;
|
||||
for (const reclista of arrlistaingresso) {
|
||||
|
||||
params.indprimario = reclista.indprimario;
|
||||
params.ind_order = reclista.ind_order;
|
||||
params.id = reclista._id;
|
||||
params.num_tess = reclista.num_tess;
|
||||
|
||||
await Nave.addUserFromListaIngresso_IntoNave(index === 0, idapp, params, false);
|
||||
index++;
|
||||
|
||||
if (index >= params.numpersone)
|
||||
break;
|
||||
}
|
||||
|
||||
return params.conta;
|
||||
|
||||
};
|
||||
|
||||
async function addUserToNave(idapp, rec) {
|
||||
|
||||
let params = {};
|
||||
|
||||
params.indprimario = rec.indprimario;
|
||||
params.ind_order = rec.ind_order;
|
||||
params.id = rec._id;
|
||||
params.num_tess = rec.num_tess;
|
||||
|
||||
return await Nave.addUserFromListaIngresso_IntoNave(true, idapp, params, true);
|
||||
|
||||
}
|
||||
|
||||
NaveSchema.statics.checkIfDevoAggiungereInNave = async function (idapp) {
|
||||
|
||||
const { ListaIngresso } = require('./listaingresso');
|
||||
|
||||
// Ottieni la lista Ordinata in base al numero d'invitati
|
||||
arrlista = await ListaIngresso.getProssimiInLista(idapp, false);
|
||||
|
||||
for (const rec of arrlista) {
|
||||
if (rec.numinvitatiattivi >= 2) {
|
||||
await addUserToNave(idapp, rec);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
NaveSchema.statics.getNaveByUser = async function (idapp, ind_order, lang, fuoco) {
|
||||
const Nave = this;
|
||||
|
||||
let mystr = '';
|
||||
const arrposiz = await Nave.getArrPosizioniByIndOrder(idapp, ind_order);
|
||||
if (!!arrposiz) {
|
||||
for (const pos of arrposiz) {
|
||||
mystr += await Nave.getNavePos(idapp, pos.riga - 3, Math.floor(pos.col / (2 * 4)), false);
|
||||
mystr += await Nave.getPlaccaPerDonatore(idapp, pos.riga, pos.col, false);
|
||||
mystr += await Nave.getPlaccaPerMediatore(idapp, pos.riga, pos.col, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (mystr === '') {
|
||||
mystr = tools.gettranslate('NO_PROG', lang);
|
||||
}
|
||||
|
||||
return mystr;
|
||||
};
|
||||
|
||||
NaveSchema.statics.getNaveByRigaCol = async function (idapp, riga, col) {
|
||||
const Nave = this;
|
||||
|
||||
rec = {};
|
||||
rec.donatore = await Nave.getPlaccaPerDonatore(idapp, riga, col, true);
|
||||
rec.mediatore = await Nave.getPlaccaPerMediatore(idapp, riga, col, true);
|
||||
|
||||
return rec;
|
||||
};
|
||||
|
||||
|
||||
const Nave = mongoose.model('Nave', NaveSchema);
|
||||
|
||||
|
||||
module.exports = { Nave };
|
||||
|
||||
|
||||
@@ -95,7 +95,37 @@ SettingsSchema.statics.findAllIdApp = function (idapp, serv) {
|
||||
});
|
||||
};
|
||||
|
||||
SettingsSchema.statics.setKeyNum = async function (idapp, key, value) {
|
||||
const Settings = this;
|
||||
|
||||
const Settings = mongoose.model('Settings', SettingsSchema);
|
||||
let myrec = await Settings.findOne({ idapp, key });
|
||||
if (!myrec) {
|
||||
myrec = new Settings({ key });
|
||||
myrec._id = new ObjectID();
|
||||
myrec.idapp = idapp;
|
||||
myrec.type = tools.FieldType.number;
|
||||
myrec.value_num = value;
|
||||
|
||||
return await myrec.save();
|
||||
} else {
|
||||
myrec = await Settings.findOneAndUpdate({ idapp, key }, { $set: { value_num: value } }, { new: false});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
SettingsSchema.statics.getKeyNum = async function (idapp, key, mydefault) {
|
||||
const Settings = this;
|
||||
|
||||
const ret = await Settings.findOne({ idapp, key});
|
||||
if (!!ret) {
|
||||
return ret.value_num;
|
||||
} else {
|
||||
return mydefault;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const Settings = mongoose.model('Settings', SettingsSchema);
|
||||
|
||||
module.exports = { Settings };
|
||||
|
||||
@@ -8,7 +8,7 @@ const tools = require('../tools/general');
|
||||
|
||||
const { Settings } = require('../models/settings');
|
||||
const { ListaIngresso } = require('../models/listaingresso');
|
||||
const { Billettera } = require('./billettera');
|
||||
const { Nave } = require('../models/nave');
|
||||
const { ExtraList } = require('../models/extralist');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
@@ -126,6 +126,9 @@ const UserSchema = new mongoose.Schema({
|
||||
aportador_solidario: {
|
||||
type: String,
|
||||
},
|
||||
aportador_iniziale: {
|
||||
type: String,
|
||||
},
|
||||
aportador_solidario_nome_completo: {
|
||||
type: String,
|
||||
},
|
||||
@@ -188,6 +191,9 @@ const UserSchema = new mongoose.Schema({
|
||||
special_req: {
|
||||
type: Boolean
|
||||
},
|
||||
vuole_ritessersi: {
|
||||
type: Boolean
|
||||
},
|
||||
sex: {
|
||||
type: Number,
|
||||
},
|
||||
@@ -338,7 +344,7 @@ UserSchema.statics.findByUsername = async function (idapp, username, alsoemail)
|
||||
if ((!ris) && (alsoemail)) {
|
||||
regexemail = new RegExp(["^", username.toLowerCase(), "$"].join(""), "i");
|
||||
|
||||
return await User.findOne({
|
||||
return User.findOne({
|
||||
'idapp': idapp,
|
||||
'email': regexemail,
|
||||
});
|
||||
@@ -365,6 +371,7 @@ UserSchema.statics.getUserShortDataByUsername = async function (idapp, username)
|
||||
'profile.email_paypal': 1,
|
||||
'profile.my_dream': 1,
|
||||
'profile.paymenttypes': 1,
|
||||
'profile.cell': 1,
|
||||
made_gift: 1,
|
||||
email: 1,
|
||||
date_reg: 1,
|
||||
@@ -389,6 +396,9 @@ UserSchema.statics.getUserShortDataByUsername = async function (idapp, username)
|
||||
};
|
||||
|
||||
UserSchema.statics.getDownlineByUsername = async function (idapp, username) {
|
||||
if (username === undefined)
|
||||
return null;
|
||||
|
||||
const User = this;
|
||||
const arrrec = await User.find({
|
||||
'idapp': idapp,
|
||||
@@ -406,6 +416,7 @@ UserSchema.statics.getDownlineByUsername = async function (idapp, username) {
|
||||
'profile.email_paypal': 1,
|
||||
'profile.my_dream': 1,
|
||||
'profile.paymenttypes': 1,
|
||||
'profile.cell': 1,
|
||||
made_gift: 1,
|
||||
email: 1,
|
||||
date_reg: 1,
|
||||
@@ -430,32 +441,45 @@ UserSchema.statics.getDownlineByUsername = async function (idapp, username) {
|
||||
UserSchema.statics.getnumInvitatiAttivi = function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
return User.count({
|
||||
if (username === undefined)
|
||||
return 0;
|
||||
|
||||
// return User.count({
|
||||
return User.countDocuments({
|
||||
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.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 },
|
||||
$or: [
|
||||
{
|
||||
'profile.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.paymenttypes': { "$in": ['paypal'] },
|
||||
$and: [
|
||||
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.my_dream" }, 10] } },
|
||||
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.email_paypal" }, 6] } }
|
||||
],
|
||||
}]
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.isUserQualified7 = async function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
const myrec = await User.findOne({
|
||||
if (username === undefined)
|
||||
return false;
|
||||
|
||||
const myquery = {
|
||||
'idapp': idapp,
|
||||
'username': username,
|
||||
$or: [
|
||||
{
|
||||
special_req: true
|
||||
'profile.special_req': true
|
||||
},
|
||||
{
|
||||
verified_email: true,
|
||||
@@ -464,22 +488,39 @@ UserSchema.statics.isUserQualified7 = async function (idapp, username) {
|
||||
'profile.saw_zoom_presentation': true,
|
||||
'profile.my_dream': { $exists: true },
|
||||
'profile.email_paypal': { $exists: true },
|
||||
'profile.paymenttypes': { "$in": ['paypal'] },
|
||||
$and: [
|
||||
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.my_dream" }, 10] } },
|
||||
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.email_paypal" }, 6] } }
|
||||
],
|
||||
$where: "this.profile.paymenttypes.length >= 1",
|
||||
}]
|
||||
});
|
||||
};
|
||||
|
||||
const myrec = await User.findOne(myquery);
|
||||
|
||||
return !!myrec;
|
||||
};
|
||||
|
||||
UserSchema.statics.isUserQualified9 = async function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
if (username === undefined)
|
||||
return false;
|
||||
|
||||
qualified = await User.isUserQualified7(idapp, username);
|
||||
numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, username);
|
||||
|
||||
return qualified && (numinvitatiattivi >= 2);
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.getnumPaymentOk = function (idapp) {
|
||||
const User = this;
|
||||
|
||||
return User.count({
|
||||
idapp,
|
||||
'profile.paymenttypes': { "$in": ['paypal'] },
|
||||
$where: "this.profile.paymenttypes.length >= 1",
|
||||
'profile.email_paypal': { $exists: true },
|
||||
});
|
||||
@@ -529,6 +570,21 @@ UserSchema.statics.findByLinkreg = function (idapp, linkreg) {
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.AportadorOrig = function (idapp, id) {
|
||||
const User = this;
|
||||
|
||||
return User.findOne({
|
||||
'_id': id,
|
||||
'idapp': idapp,
|
||||
}).then((rec) => {
|
||||
if (rec)
|
||||
return rec.aportador_iniziale;
|
||||
else
|
||||
return '';
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
UserSchema.statics.findByLinkTokenforgot = function (idapp, email, tokenforgot) {
|
||||
const User = this;
|
||||
|
||||
@@ -560,17 +616,17 @@ UserSchema.statics.findByIndOrder = function (idapp, ind_order) {
|
||||
const User = this;
|
||||
|
||||
try {
|
||||
// ++Todo: non mettere tutti i campi !!
|
||||
return User.findOne({
|
||||
'idapp': idapp,
|
||||
'ind_order': ind_order,
|
||||
idapp,
|
||||
ind_order,
|
||||
});
|
||||
} catch (e) {
|
||||
|
||||
console.error(e);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
UserSchema.pre('save', function (next) {
|
||||
const user = this;
|
||||
|
||||
@@ -611,6 +667,29 @@ UserSchema.statics.getEmailByUsername = async function (idapp, username) {
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsernameById = async function (idapp, id) {
|
||||
const User = this;
|
||||
|
||||
return await User.findOne({ idapp, _id: id }, { username: 1 })
|
||||
.then((myuser) => {
|
||||
return ((myuser) ? myuser.username : '');
|
||||
}).catch((e) => {
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getUserById = function (idapp, id) {
|
||||
const User = this;
|
||||
|
||||
return User.findOne({ idapp, _id: id })
|
||||
};
|
||||
|
||||
UserSchema.statics.getUserByAportador = function (idapp, aportador_solidario) {
|
||||
const User = this;
|
||||
|
||||
return User.findOne({ idapp, aportador_solidario })
|
||||
};
|
||||
|
||||
UserSchema.statics.getAportadorSolidarioByUsername = async function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
@@ -633,6 +712,17 @@ UserSchema.statics.UserByIdTelegram = async function (idapp, teleg_id) {
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.UsersByIdTelegram = async function (idapp, teleg_id) {
|
||||
const User = this;
|
||||
|
||||
return await User.find({ idapp, 'profile.teleg_id': teleg_id })
|
||||
.then((rec) => {
|
||||
return (!!rec) ? rec._doc : null;
|
||||
}).catch((e) => {
|
||||
console.error('UserExistByIdTelegram', e);
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.TelegIdByUsername = async function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
@@ -705,6 +795,24 @@ UserSchema.statics.getNameSurnameByUsername = async function (idapp, username) {
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getSmallRecByIndOrder = async function (idapp, ind_order) {
|
||||
const User = this;
|
||||
|
||||
return await User.findOne({ idapp, ind_order },
|
||||
{
|
||||
ind_order: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1
|
||||
}
|
||||
)
|
||||
.then((rec) => {
|
||||
return rec;
|
||||
}).catch((e) => {
|
||||
console.error('getSmallRecByIndOrder', e);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
UserSchema.statics.getusersManagers = async function (idapp) {
|
||||
const User = this;
|
||||
@@ -717,15 +825,25 @@ UserSchema.statics.getusersManagers = async function (idapp) {
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsersTelegALL = async function (idapp) {
|
||||
UserSchema.statics.getUsersTelegALL = async function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
return await User.find({ idapp, 'profile.teleg_id': { $gt: 0 } })
|
||||
.then((arrrec) => {
|
||||
return (!!arrrec) ? arrrec : null;
|
||||
}).catch((e) => {
|
||||
console.error('getUsersTelegALL', e);
|
||||
});
|
||||
if (!!username) {
|
||||
return await User.find({ idapp, username, 'profile.teleg_id': { $gt: 0 } })
|
||||
.then((arrrec) => {
|
||||
return (!!arrrec) ? arrrec : null;
|
||||
}).catch((e) => {
|
||||
console.error('getUsersTelegALL', e);
|
||||
});
|
||||
} else {
|
||||
return await User.find({ idapp, 'profile.teleg_id': { $gt: 0 } })
|
||||
.then((arrrec) => {
|
||||
return (!!arrrec) ? arrrec : null;
|
||||
}).catch((e) => {
|
||||
console.error('getUsersTelegALL', e);
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.isManagerByIdTeleg = async function (idapp, idtelegram) {
|
||||
@@ -851,13 +969,15 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
|
||||
dashboard.aportador = await ExtraList.getUserNotRegisteredByNameSurname(idapp, aportador_solidario_nome_completo);
|
||||
}
|
||||
|
||||
dashboard.downline = [];
|
||||
|
||||
// Data of my Downline
|
||||
const arrap = await User.getDownlineByUsername(idapp, aportador_solidario);
|
||||
dashboard.numpeople_aportador = arrap.length;
|
||||
if (!!arrap)
|
||||
dashboard.numpeople_aportador = arrap.length;
|
||||
|
||||
dashboard.downline = await User.getDownlineByUsername(idapp, username);
|
||||
dashboard.downnotreg = await ExtraList.getDownlineNotRegisteredByNameSurname(idapp, dashboard.myself.name + ' ' + dashboard.myself.surname);
|
||||
// dashboard.downnotreg = await ExtraList.getDownlineNotRegisteredByNameSurname(idapp, dashboard.myself.name + ' ' + dashboard.myself.surname);
|
||||
|
||||
dashboard.downbyuser = {};
|
||||
|
||||
@@ -868,6 +988,18 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
|
||||
dashboard.downbyuser[down2.username] = await User.getDownlineByUsername(idapp, down2.username);
|
||||
}
|
||||
}
|
||||
|
||||
dashboard.arrnavi = await Nave.getArrPosizioniByIndOrder(idapp, dashboard.myself.ind_order);
|
||||
|
||||
dashboard.navi_partenza = [];
|
||||
for (let indriga = 0; indriga < 10; indriga++) {
|
||||
dashboard.navi_partenza.push(await Nave.getPrimaNaveByRiga(idapp, indriga));
|
||||
}
|
||||
|
||||
for (let mynave of dashboard.arrnavi) {
|
||||
mynave._doc.rec = await Nave.getNaveByRigaCol(idapp, mynave.riga, mynave.col);
|
||||
}
|
||||
|
||||
return dashboard;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
@@ -920,12 +1052,12 @@ UserSchema.statics.getUsersQualified = async function (idapp, numinvitati) {
|
||||
idapp,
|
||||
$or: [
|
||||
{
|
||||
special_req: true
|
||||
'profile.special_req': true
|
||||
},
|
||||
{
|
||||
verified_email: true,
|
||||
'profile.teleg_id': { $gt: 0 },
|
||||
$where: "this.profile.paymenttypes.length >= 1",
|
||||
'profile.paymenttypes': { "$in": ['paypal'] },
|
||||
'profile.saw_and_accepted': shared_consts.ALL_SAW_AND_ACCEPTED,
|
||||
'profile.saw_zoom_presentation': true,
|
||||
'profile.my_dream': { $exists: true },
|
||||
@@ -1022,7 +1154,15 @@ UserSchema.statics.getLastUsers = async function (idapp) {
|
||||
|
||||
const lastn = await Settings.getValDbSettings(idapp, 'SHOW_LAST_N_USERS', 5);
|
||||
|
||||
return await User.find({ idapp }).sort({ date_temp_reg: -1 }).limit(lastn).then((arr) => {
|
||||
return await User.find({ idapp }, {
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
date_temp_reg: 1,
|
||||
date_reg: 1,
|
||||
ind_order: 1,
|
||||
'profile.nationality': 1,
|
||||
}).sort({ date_temp_reg: -1 }).limit(lastn).then((arr) => {
|
||||
//return JSON.stringify(arr)
|
||||
return arr
|
||||
});
|
||||
@@ -1079,23 +1219,47 @@ UserSchema.statics.findAllDistinctNationality = async function (idapp) {
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsersRegDaily = function (idapp, nrec) {
|
||||
|
||||
const query = [
|
||||
{
|
||||
$match: { idapp }
|
||||
$match: { idapp, date_temp_reg: { $gte: tools.IncDateNow(-(1000 * 60 * 60 * 24 * nrec)) } }
|
||||
},
|
||||
{
|
||||
$group: { _id: { $dateToString: { format: "%Y-%m-%d", date: "$date_temp_reg" } }, count: { $sum: 1 } }
|
||||
},
|
||||
{
|
||||
$sort: { _id: 1 }
|
||||
},
|
||||
{
|
||||
$limit: nrec
|
||||
}
|
||||
];
|
||||
return query
|
||||
};
|
||||
|
||||
UserSchema.statics.getnumRegNDays = function (idapp, nrec) {
|
||||
|
||||
|
||||
const query = [
|
||||
{
|
||||
$match: { idapp, date_temp_reg: { $lt: tools.IncDateNow(-(1000 * 60 * 60 * 24 * nrec)) } }
|
||||
},
|
||||
{
|
||||
$group: { _id: { $dateToString: { format: "%Y-%m-%d", date: "$date_temp_reg" } }, count: { $sum: 1 } }
|
||||
},
|
||||
{
|
||||
$sort: { _id: 1 }
|
||||
}
|
||||
];
|
||||
return query
|
||||
};
|
||||
|
||||
UserSchema.statics.calcnumRegUntilDay = async function (idapp) {
|
||||
const User = this;
|
||||
|
||||
return await User.aggregate(User.getnumRegNDays(idapp, 30))
|
||||
.then((arr) => {
|
||||
return arr.reduce((sum, rec) => sum + rec.count, 0);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.calcRegDaily = async function (idapp) {
|
||||
const User = this;
|
||||
@@ -1116,22 +1280,31 @@ if (tools.INITDB_FIRSTIME) {
|
||||
// UserSchema.index({ surname: 1 });
|
||||
}
|
||||
|
||||
async function addUtentiInLista(idapp, mode) {
|
||||
async function addUtentiInLista(idapp, mode, arrusers) {
|
||||
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);
|
||||
let numinvitati = await User.getnumInvitati(idapp, rec.username);
|
||||
|
||||
if (rec.profile.special_req) {
|
||||
numinvitatiattivi = 2;
|
||||
}
|
||||
|
||||
if (mode === 1) {
|
||||
// 9 punti qualificati
|
||||
ok = qualified && (numinvitatiattivi >= 2);
|
||||
} else if (mode === 2) {
|
||||
// 8 punti qualificati ( 1 Invitato)
|
||||
ok = qualified && (numinvitati === 2);
|
||||
} else if (mode === 3) {
|
||||
ok = qualified && (numinvitatiattivi === 1);
|
||||
} else if (mode === 4) {
|
||||
ok = qualified && (numinvitati === 1);
|
||||
} else if (mode === 5) {
|
||||
// 7 punti qualificati
|
||||
ok = qualified;
|
||||
} else {
|
||||
ok = true;
|
||||
// // almeno telegram ID
|
||||
// ok = user.profile.teleg_id > 0;
|
||||
// } else {
|
||||
@@ -1139,24 +1312,37 @@ async function addUtentiInLista(idapp, mode) {
|
||||
}
|
||||
|
||||
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();
|
||||
ris = await ListaIngresso.addUserInListaIngresso(idapp, rec.ind_order, rec.lang, false, 1);
|
||||
if (!!ris)
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
UserSchema.statics.deveRitessersi = async function (idapp, ind_order) {
|
||||
|
||||
const myrec = await User.findOne({
|
||||
'idapp': idapp,
|
||||
'ind_order': ind_order,
|
||||
"profile.vuole_ritessersi": true
|
||||
});
|
||||
|
||||
return (!!myrec)
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsernameByIndOrder = async function (idapp, ind_order) {
|
||||
|
||||
const myrec = await User.findOne({
|
||||
'idapp': idapp,
|
||||
'ind_order': ind_order,
|
||||
}, { username: 1 });
|
||||
|
||||
return (!!myrec) ? myrec.username : ''
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.DbOp = async function (idapp, mydata) {
|
||||
const User = this;
|
||||
try {
|
||||
@@ -1190,26 +1376,21 @@ UserSchema.statics.DbOp = async function (idapp, mydata) {
|
||||
|
||||
} else if (mydata.dbop === 'creaLista') {
|
||||
|
||||
await ListaIngresso.remove({ idapp });
|
||||
await ListaIngresso.deleteMany({ idapp, added: false });
|
||||
|
||||
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, 1, arrusers);
|
||||
num += await addUtentiInLista(idapp, 2, arrusers);
|
||||
num += await addUtentiInLista(idapp, 3, arrusers);
|
||||
num += await addUtentiInLista(idapp, 4, arrusers);
|
||||
num += await addUtentiInLista(idapp, 5, arrusers);
|
||||
// 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);
|
||||
|
||||
Reference in New Issue
Block a user