Lista Doni Navi

This commit is contained in:
Paolo Arena
2020-03-21 10:28:26 +01:00
parent fbc85ce06a
commit b2696d1898
139 changed files with 463 additions and 80 deletions

255
src/server/models/nave.js Normal file → Executable file
View File

@@ -45,6 +45,9 @@ const NaveSchema = new mongoose.Schema({
date_start: {
type: Date
},
date_gift_chat_open: {
type: Date
},
link_chat: {
type: String,
},
@@ -72,6 +75,9 @@ const NaveSchema = new mongoose.Schema({
num_tess: { // numero di tessitura
type: Number,
default: 1
},
provvisoria: {
type: Boolean
}
});
@@ -121,7 +127,8 @@ NaveSchema.statics.findByIndPrimario = function (idapp, indprimario) {
NaveSchema.statics.getFieldsForSearch = function () {
return ['username', 'name', 'surname', 'ind_order']
return [{ field: 'ind_order', type: tools.FieldType.number },
{ field: 'col', type: tools.FieldType.number }]
};
NaveSchema.statics.executeQueryTable = function (idapp, params) {
@@ -187,13 +194,16 @@ function getIndColonneByNave(navemediatore) {
let col = navemediatore.col;
let col_ini = calcval(riga, col, 8) + 1;
let col_fine = col_ini + 8;
let col_fine = col_ini + 7;
return { riga: riga + 3, col_ini, col_fine }
}
NaveSchema.statics.getusersByNave = function (idapp, navemediatore) {
if ((!navemediatore.riga) || (!navemediatore.col))
return [];
const obj = getIndColonneByNave(navemediatore);
const miacol_ini = obj.col_ini;
@@ -248,7 +258,8 @@ NaveSchema.statics.findRecByRigaColParent = async function (idapp, riga, col, nu
myrigacol.riga = lastrec.riga;
myrigacol.col = lastrec.col;
} else {
lastrec = await User.findByIndOrder(idapp, 0);
//lastrec = await User.findByIndOrder(idapp, 0);
lastrec = await Nave.findGeneric({ idapp, riga: 0, col: 0 });
break;
}
}
@@ -257,7 +268,8 @@ NaveSchema.statics.findRecByRigaColParent = async function (idapp, riga, col, nu
}
if (!lastrec) {
return await User.findByIndOrder(idapp, 0);
// return await User.findByIndOrder(idapp, 0);
return await Nave.findGeneric({ idapp, riga: 0, col: 0 });
}
return lastrec;
@@ -278,14 +290,6 @@ function getlimiti(mypos) {
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,
@@ -295,7 +299,7 @@ function getRigaColGenerica(idapp, riga, col, numup) {
};
if (idapp === tools.AYNI) {
getRigaColByPosUp(mypos);
tools.getRigaColByPosUp(mypos);
ris = getlimiti(mypos);
}
@@ -395,22 +399,26 @@ NaveSchema.statics.findMediatoreByFuoco = async function (idapp, riga, col, offs
// return Nave.findGeneric(myrigacol);
return await Nave.findRecByRigaColParent(idapp, riga, col, 3 - offset);
};
function getQueryProj(myfilter) {
myobjField = {
_id: 1,
idapp: 1,
lang: 1,
ind_order: 1,
name: 1,
surname: 1,
username: 1,
'profile.paymenttypes': 1,
'profile.email_paypal': 1,
date_start: 1,
date_gift_chat_open: 1,
made_gift: 1,
link_chat: 1,
date_made_gift: 1,
provvisoria: 1,
received_gift: 1,
date_received_gift: 1,
num_tess: 1,
@@ -464,7 +472,11 @@ function getmaxcol(riga) {
}
function getPrimoFuocoByIndCol(col) {
return Math.floor(col - (col % 8)) + 1;
// let ris = Math.ceil(col - (col % 8)) + 1;
let ris = ((Math.ceil(col / 8) - 1) * 8) + 1;
if (ris <= 0)
ris = 1;
return ris
}
async function getusertextbyrec(myrec, symbol, lettera, riga, col, ind) {
@@ -480,12 +492,26 @@ async function getusertextbyrec(myrec, symbol, lettera, riga, col, ind) {
} else {
if (myrec)
return lettera + ind + ' - ' + symbol + '[' + miariga + ',' + miacol + ']' + ' ' + myrec.name + ' ' + myrec.surname + '';
return lettera + ind + ' - ' + symbol + '[' + riga + ',' + col + ']' + ' ' + myrec.name + ' ' + myrec.surname + '';
else
return lettera + ind + ' - ' + symbol;
}
}
function checkifNullThenEmpty(rec, riga, col) {
if (rec === null) {
return {
name: '',
surname: '',
username: '',
riga,
col,
}
} else {
return rec;
}
}
NaveSchema.statics.getPlaccaGenerica = async function (idapp, riga, col, offset, solorecord) {
const Nave = this;
@@ -526,17 +552,25 @@ NaveSchema.statics.getPlaccaGenerica = async function (idapp, riga, col, offset,
// mystr += '🔥🌏💦💨🔥🌏💦💨' + tools.ACAPO;
let arrdonatori = [];
// let numcol = Math.pow(2, indriga - 1);
primofuoco = getPrimoFuocoByIndCol(col * Math.pow(2, offset));
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);
// indc = calcval(riga, col, 8) + (indcol - primofuoco + 1);
if (offset === 0)
indc = indcol;
else
indc = indcol;
// miacol = calcval(riga, col, 8) + (indfuoco);
let recfuoco = await Nave.findByRigaCol(idapp, indr, indc, true);
recfuoco = checkifNullThenEmpty(recfuoco, indr, indc);
arrdonatori.push(recfuoco);
mystr += await getusertextbyrec(recfuoco, symb.icona, symb.car, indr, indc, ind) + tools.ACAPO;
ind++;
@@ -560,14 +594,63 @@ NaveSchema.statics.getPlaccaGenerica = async function (idapp, riga, col, offset,
};
NaveSchema.statics.getPlaccaPerDonatore = async function (idapp, riga, col, solorecord) {
NaveSchema.statics.getPlaccaPerDonatore = async function (idapp, riga, col, solorecord, rec) {
const Nave = this;
return Nave.getPlaccaGenerica(idapp, riga, col, tools.Placca.SONOFUOCO, solorecord);
if (solorecord) {
rec.donatore = await Nave.getPlaccaGenerica(idapp, riga, col, tools.Placca.SONOFUOCO, solorecord);
newcol = Math.ceil(col / (Math.pow(2, 3)));
rec.donatore.arrterra = await Nave.getArrTerra(idapp, riga - 3, newcol);
rec.donatore.arraria = await Nave.getArrAria(idapp, riga - 3, newcol);
return rec;
} else {
return await Nave.getPlaccaGenerica(idapp, riga, col, tools.Placca.SONOFUOCO, solorecord);
}
};
NaveSchema.statics.getPlaccaPerMediatore = async function (idapp, riga, col, solorecord) {
NaveSchema.statics.getPlaccaPerMediatore = async function (idapp, riga, col, solorecord, rec) {
const Nave = this;
return Nave.getPlaccaGenerica(idapp, riga, col, tools.Placca.SONOACQUA, solorecord);
rec.mediatore = await Nave.getPlaccaGenerica(idapp, riga, col, tools.Placca.SONOACQUA, solorecord);
rec.mediatore.arrterra = await Nave.getArrTerra(idapp, riga, col);
rec.mediatore.arraria = await Nave.getArrAria(idapp, riga, col);
return rec;
};
NaveSchema.statics.getArrTerra = async function (idapp, riga, col) {
const Nave = this;
let arrterra = [];
for (let indterra = 1; indterra <= 2; indterra++) {
miacol = calcval(riga, col, 2) + (indterra);
miariga = riga + 1;
let rec = await Nave.findByRigaCol(idapp, miariga, miacol, true);
rec = checkifNullThenEmpty(rec, miariga, miacol);
arrterra.push(rec);
}
return arrterra;
};
NaveSchema.statics.getArrAria = async function (idapp, riga, col) {
const Nave = this;
let arraria = [];
for (let indaria = 1; indaria <= 4; indaria++) {
miacol = calcval(riga, col, 4) + (indaria);
miariga = riga + 2;
let rec = await Nave.findByRigaCol(idapp, miariga, miacol, true);
rec = checkifNullThenEmpty(rec, miariga, miacol);
arraria.push(rec);
}
return arraria;
};
function calcval(riga, col, quanti) {
@@ -624,12 +707,21 @@ NaveSchema.statics.getNavePos = async function (idapp, riga, col, solorecord) {
}
let data = "";
if (primofuoco)
data = "Partenza il " + tools.getstrDateLong(primofuoco.date_start) + tools.ACAPO;
else
let mystrtemp = '';
if (primofuoco) {
data = '💬 Giorno di Apertura GIFT CHAT: ' + tools.getstrDateLong(primofuoco.date_gift_chat_open) + tools.ACAPO;
data += "🎁 Giorno in cui Inviare il DONO : " + tools.getstrDateLong(primofuoco.date_start) + tools.ACAPO;
data += tools.ACAPO;
data += 'Il Mediatore sarà contattato 1 giorno prima dal Tutor' + tools.ACAPO;
if (primofuoco.provvisoria)
mystrtemp = 'TEMPORANEA ';
} else
data = "";
mystr = tools.ACAPO + 'NAVE (' + riga + '.' + col + ') ' + tools.ACAPO + data + tools.ACAPO + mystr;
mystr = tools.ACAPO + 'NAVE ' + '[' + riga + '.' + col + '] ' + mystrtemp + tools.ACAPO + data + tools.ACAPO + mystr;
return mystr;
} catch (e) {
@@ -679,7 +771,7 @@ NaveSchema.statics.getArrPosizioniByIndOrder = async function (idapp, ind_order)
NaveSchema.statics.getPrimaNaveByRiga = async function (idapp, riga) {
const Nave = this;
nave = await Nave.find({ 'idapp': idapp, riga: (riga + 3), col: 1 });
nave = await Nave.findOne({ 'idapp': idapp, riga: (riga + 3), col: 1 });
return nave;
};
@@ -702,12 +794,20 @@ NaveSchema.statics.showListaOrd = async function (idapp) {
return mystr;
};
NaveSchema.statics.getLastRigaCol = async function (idapp) {
return Nave.findOne({ idapp }).sort({ _id: -1 });
};
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 });
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 });
@@ -724,7 +824,9 @@ async function addRecordNaveByParams(params, siRitesse) {
riga: params.riga,
col: params.col,
date_start: params.date_start,
date_gift_chat_open: params.date_gift_chat_open,
num_tess: params.num_tess,
provvisoria: params.provvisoria,
});
myNave.created = new Date();
@@ -834,10 +936,13 @@ NaveSchema.statics.addUserFromListaIngresso_IntoNave = async function (init, ida
let recmediatore = await Nave.findMediatoreByFuoco(idapp, myriga, mycol, 0);
if (!!recmediatore) {
const ris = await Nave.checkifDeveRitessersi(recmediatore);
if (ris.num_tess > 2) {
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);
//++Todo: TESSITURA????
//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, ']');
@@ -883,6 +988,7 @@ NaveSchema.statics.generaNave = async function (idapp, mydata) {
riga: await Nave.getRiga(idapp),
col: await Nave.getCol(idapp),
date_start: mydata.date_start,
date_gift_chat_open: tools.AddDate(mydata.date_start, -7),
numpersone: mydata.numpersone,
};
@@ -912,6 +1018,7 @@ NaveSchema.statics.generaNave = async function (idapp, mydata) {
params.ind_order = reclista.ind_order;
params.id = reclista._id;
params.num_tess = reclista.num_tess;
params.provvisoria = mydata.provvisoria;
await Nave.addUserFromListaIngresso_IntoNave(index === 0, idapp, params, false);
index++;
@@ -932,6 +1039,7 @@ async function addUserToNave(idapp, rec) {
params.ind_order = rec.ind_order;
params.id = rec._id;
params.num_tess = rec.num_tess;
params.provvisoria = false;
return await Nave.addUserFromListaIngresso_IntoNave(true, idapp, params, true);
@@ -952,16 +1060,48 @@ NaveSchema.statics.checkIfDevoAggiungereInNave = async function (idapp) {
};
NaveSchema.statics.pulisciNonPresenzeInNave = async function (idapp) {
const Nave = this;
let numrec = 0;
const { ListaIngresso } = require('./listaingresso');
const myquery = getQueryProj({
idapp,
ind_order: { $gt: 0 },
added: true,
deleted: false,
});
arrrec = await ListaIngresso.aggregate(myquery)
.then(async (arrlista) => {
for (const rec of arrlista) {
const trovato = await Nave.findByIndOrder(idapp, rec.ind_order);
if (!trovato) {
let fields_to_update = { added: false };
await ListaIngresso.findOneAndUpdate({ _id: rec._id }, { $set: fields_to_update }, { new: false });
numrec++;
}
}
});
return numrec;
};
NaveSchema.statics.getNaveByUser = async function (idapp, ind_order, lang, fuoco) {
const Nave = this;
let mystr = '';
let rec = {};
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);
mystr += await Nave.getPlaccaPerDonatore(idapp, pos.riga, pos.col, false, rec);
mystr += await Nave.getPlaccaPerMediatore(idapp, pos.riga, pos.col, false, rec);
}
}
@@ -972,20 +1112,65 @@ NaveSchema.statics.getNaveByUser = async function (idapp, ind_order, lang, fuoco
return mystr;
};
NaveSchema.statics.getNaveByRigaCol = async function (idapp, riga, col) {
NaveSchema.statics.getNaveByRigaCol = async function (idapp, riganave, colnave) {
const Nave = this;
const rigaprec = riganave;
rec = {};
rec.donatore = await Nave.getPlaccaPerDonatore(idapp, riga, col, true);
rec.mediatore = await Nave.getPlaccaPerMediatore(idapp, riga, col, true);
rec = await Nave.getPlaccaPerMediatore(idapp, riganave, colnave, true, rec);
if (riganave < 4) {
riganave = 4;
colnave = 1;
}
rec = await Nave.getPlaccaPerDonatore(idapp, riganave, colnave, true, rec);
return rec;
};
NaveSchema.statics.getDonatoridelSognatore = async function (idapp, riganave, colnave) {
const Nave = this;
coldonatoreIni = calcval(riganave, colnave, 8) + (1);
coldonatoreFine = calcval(riganave, colnave, 8) + (64);
const myquery = getQueryProj({
idapp,
riga: riganave + 6,
col: { $gte: coldonatoreIni, $lte: coldonatoreFine }
});
const arrnaviout = [];
const arrnavi = await Nave.aggregate(myquery);
for (const nave of arrnavi) {
// Se è il mediatore, allora non includerlo nei Donatori!
mypos = {
riga: nave.riga,
col: nave.col,
numup: 3,
};
tools.getRigaColByPosUp(mypos);
const navemediatore = await Nave.findByRigaCol(idapp, mypos.riga, mypos.col, true);
if (!!navemediatore) {
if (navemediatore.ind_order !== nave.ind_order) {
arrnaviout.push(nave);
}
} else {
arrnaviout.push(nave);
}
}
return arrnaviout;
};
const Nave = mongoose.model('Nave', NaveSchema);
module.exports = { Nave };