Aggiornamenti

This commit is contained in:
Paolo Arena
2020-04-24 10:29:25 +02:00
parent 4a9fa9cf61
commit 2549d43447
21 changed files with 733 additions and 390 deletions

View File

@@ -34,9 +34,6 @@ const NaveSchema = new mongoose.Schema({
col: {
type: Number,
},
indprimario: {
type: Number,
},
ind_order: {
type: Number,
},
@@ -117,19 +114,6 @@ NaveSchema.statics.findById = function (idapp, id) {
};
NaveSchema.statics.findByIndPrimario = function (idapp, indprimario) {
const Nave = this;
try {
return Nave.findOne({
idapp,
indprimario,
});
} catch (e) {
}
};
NaveSchema.statics.getFieldsForSearch = function () {
return [{ field: 'ind_order', type: tools.FieldType.number },
@@ -419,6 +403,8 @@ function getQueryProj(myfilter) {
name: 1,
surname: 1,
username: 1,
deleted: 1,
sospeso: 1,
'profile.paymenttypes': 1,
'profile.email_paypal': 1,
'profile.cell': 1,
@@ -429,7 +415,6 @@ function getQueryProj(myfilter) {
received_gift: 1,
date_received_gift: 1,
num_tess: 1,
indprimario: 1,
parent_id: 1,
riga: 1,
col: 1,
@@ -458,6 +443,7 @@ function getQueryProj(myfilter) {
$replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$user", 0] }, "$$ROOT"] } }
// $replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$user", 0] },] } }
},
{ $match: { $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }] } },
{ $project: myobjField }
];
@@ -903,7 +889,6 @@ async function addRecordNaveByParams(params, siRitesse) {
let myNave = new Nave({
idapp: params.idapp,
indprimario: params.indprimario,
ind_order: params.ind_order,
riga: params.riga,
col: params.col,
@@ -1026,7 +1011,6 @@ NaveSchema.statics.addUserFromListaIngresso_IntoNave = async function (init, ida
if (ris.deveritessersi) {
console.log('Si deve ritesere: [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 + 1;
@@ -1039,7 +1023,6 @@ NaveSchema.statics.addUserFromListaIngresso_IntoNave = async function (init, ida
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;
@@ -1076,7 +1059,7 @@ NaveSchema.statics.generaNave = async function (idapp, mydata) {
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 });
let myNave = new Nave({ idapp, ind_order: 0, riga: 0, col: 0 });
myNave.created = new Date();
myNave.parent_id = ObjectID("5e592aecbfd0b75f3021d9c9");
await myNave.save();
@@ -1094,7 +1077,6 @@ NaveSchema.statics.generaNave = async function (idapp, mydata) {
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;
@@ -1114,8 +1096,6 @@ 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;
@@ -1181,10 +1161,12 @@ NaveSchema.statics.visuNaviUtentiEliminati = async function (idapp) {
for (const rec of arrrec) {
if (!rec.username) {
let navepersistente = await NavePersistente.findByRigaColByDonatore(idapp, rec.riga, rec.col, 0);
mystr += '[' + conta + '] [NAVI ' + navepersistente.riga + '.' + navepersistente.col + '] [' + rec.riga + '.' + rec.col + '] ' + rec.ind_order;
mystr += ' num_tess = ' + rec.num_tess;
mystr += '\n';
conta++;
if (!!navepersistente) {
mystr += '[' + conta + '] [NAVI ' + navepersistente.riga + '.' + navepersistente.col + '] [' + rec.riga + '.' + rec.col + '] ' + rec.ind_order;
mystr += ' num_tess = ' + rec.num_tess;
mystr += '\n';
conta++;
}
}
}
@@ -1235,7 +1217,7 @@ NaveSchema.statics.getDonatoridelSognatore = async function (idapp, riganave, co
const Nave = this;
coldonatoreIni = ((colnave - 1) * 64) + (1);
coldonatoreFine = coldonatoreIni + (64);
coldonatoreFine = coldonatoreIni + (63);
const myquery = getQueryProj({
idapp,
@@ -1271,6 +1253,61 @@ NaveSchema.statics.getDonatoridelSognatore = async function (idapp, riganave, co
};
NaveSchema.statics.ricalcolaNave = async function (idapp, nave, riga1don, col1don, ricalcola, index) {
const Nave = this;
try {
if (nave === null) {
nave = await NavePersistente.findByRigaColByDonatore(idapp, riga1don, col1don, 0);
}
nave.rec = await Nave.getNaveByRigaCol(idapp, nave.riga1don, nave.col1don);
if (nave.provvisoria || (ricalcola && (nave.DoniConfermati === nave.DoniTotali) && (nave.DoniTotali >= 7) && nave.DoniMancanti === 0 && nave.DoniAttesaDiConferma === 0)) {
// gia fatto
} else {
nave.index = index;
nave.DoniTotali = 0;
nave.DoniAttesaDiConferma = 0;
nave.DoniMancanti = 0;
nave.DoniConfermati = 0;
const { User } = require('./user');
if (!!nave.tutor)
nave.tutor_namesurname = await User.getNameSurnameByUsername(idapp, nave.tutor);
if (!!nave.rec) {
if (!!nave.rec.donatore) {
nave.DoniTotali = nave.rec.donatore.arrdonatori.filter((rec) => (!(rec.ind_order === nave.rec.donatore.recmediatore.ind_order && (rec.num_tess % 2) === 0))).reduce((sum, item) => sum + 1, 0);
nave.DoniAttesaDiConferma = nave.rec.donatore.arrdonatori.filter((rec) => (!!rec.date_made_gift && !rec.made_gift && !(rec.ind_order === nave.rec.donatore.recmediatore.ind_order && (rec.num_tess % 2) === 0))).reduce((sum, item) => sum + 1, 0);
nave.DoniMancanti = nave.rec.donatore.arrdonatori.filter((rec) => (!rec.made_gift && !(rec.ind_order === nave.rec.donatore.recmediatore.ind_order && (rec.num_tess % 2) === 0))).reduce((sum, item) => sum + 1, 0);
nave.DoniConfermati = nave.rec.donatore.arrdonatori.filter((rec) => rec.made_gift && !(rec.ind_order === nave.rec.donatore.recmediatore.ind_order && (rec.num_tess % 2) === 0)).reduce((sum, item) => sum + 1, 0);
}
}
const fieldsvalue = {
DoniAttesaDiConferma: nave.DoniAttesaDiConferma,
DoniTotali: nave.DoniTotali,
DoniMancanti: nave.DoniMancanti,
DoniConfermati: nave.DoniConfermati,
tutor_namesurname: nave.tutor_namesurname,
};
const risu = await NavePersistente.findOneAndUpdate({ _id: nave._id }, { $set: fieldsvalue }, { new: false });
nave._doc.rec = nave.rec;
}
}catch (e) {
console.error(e.message);
}
return nave;
}
const Nave = mongoose.model('Nave', NaveSchema);
module.exports = { Nave };