Sistemazioni...

This commit is contained in:
Paolo Arena
2020-07-02 22:00:58 +02:00
parent c939be279e
commit e2cdee1baa
13 changed files with 454 additions and 171 deletions

View File

@@ -78,6 +78,9 @@ const FlottaSchema = new mongoose.Schema({
email_paypal: {
type: String,
},
revolut: {
type: String,
},
note_payment: {
type: String,
},
@@ -111,6 +114,7 @@ function getQueryProj(myfilter) {
username: 1,
'profile.paymenttypes': 1,
'profile.email_paypal': 1,
'profile.revolut': 1,
'profile.cell': 1,
made_gift: 1,
commento_al_sognatore: 1,
@@ -317,6 +321,31 @@ FlottaSchema.statics.getFlottaByNavePersistente = async function (idapp, naveper
return myflotta;
};
FlottaSchema.statics.getStrFlotta = function (flotta) {
return `Flotta ${flotta.riga}.${Math.ceil(flotta.col_prima / 8)} - ${flotta.riga}.${Math.ceil(flotta.col_ultima / 8)}: Sognatore: ${flotta.sognatore_nomecognome}`;
};
FlottaSchema.statics.getFlottaByRigaColDonatore = async function (idapp, riga, col) {
const Flotta = this;
let mypos = {
idapp,
riga,
col,
numup: 3
};
tools.getRigaColByPosUp(mypos);
const myflotta = await Flotta.findOne({ idapp, riga: mypos.riga,
$and: [
{ col_prima: { $lte: col } },
{ col_ultima: { $gte: col } } ]
});
return myflotta;
};
const Flotta = mongoose.model('Flotta', FlottaSchema);

View File

@@ -11,6 +11,8 @@ const { ObjectID } = require('mongodb');
const { Nave } = require('./nave');
const { Graduatoria } = require('./graduatoria');
const actions = require('../router/api/actions');
const shared_consts = require('../tools/shared_nodejs');
const queryclass = require('../classes/queryclass');
@@ -929,6 +931,79 @@ ListaIngressoSchema.statics.getListaTessByUsername = function (idapp, username)
};
ListaIngressoSchema.statics.eliminaListaIngresso = async function (idapp, ind_order, req, num_tess) {
const ListaIngresso = this;
const telegrambot = require('../telegram/telegrambot');
const myrec = await ListaIngresso.getIngrEUserByFilter(idapp, {
idapp,
ind_order
});
let filtro = { idapp, ind_order };
// if (!!num_tess) {
// filtro.num_tess = num_tess;
// }
// Controlla se ci sono piu navi
const arrnavi = await Nave.find(filtro);
const eliminaveramente = false;
let nasc = '';
let receliminato = false;
let risdel = false;
if (arrnavi.length === 1) {
if (!arrnavi[0].made_gift) {
// SE NON E' STATO CONFERMATO CHE HA FATTO IL DONO!
// Solo 1 nave da cancellare, quindi cancello anche l'ingresso
let filtrocanc = { idapp, ind_order };
if (!!num_tess)
filtrocanc.num_tess = num_tess;
let recdel = null;
if (eliminaveramente) {
recdel = await ListaIngresso.deleteOne(filtrocanc);
} else {
nasc = '(nascosto)';
let fieldsvalue = {
date_deleted: new Date(),
deleted: true
};
recdel = await ListaIngresso.findOneAndUpdate(filtrocanc, { $set: fieldsvalue }, { new: false });
}
risdel = !!recdel;
receliminato = !!recdel;
}
} else {
// non cancellare la listaingresso (perchè con lo stesso ind_order ho piu navi !
risdel = true;
receliminato = false;
}
let msg = '';
if (risdel) {
if (receliminato) {
msg = 'Eliminato RECORD in Lista Imbarco ' + nasc + ' di ' + myrec.name + ' ' + myrec.surname + ' (ind_order=' + myrec.ind_order + ', num_tess=' + myrec.num_tess + ') [Num = ' + myrec.index + `] (da ${req.user.name} ${req.user.surname} )`;
}
await actions.doOtherThingsAfterDeleted('listaingressos', myrec, false, req)
} else {
msg = 'ATTENZIONE: il RECORD non è stato Eliminato perchè gia c\'era in altra NAVE -> di ' + myrec.name + ' ' + myrec.surname + ' (ind_order=' + myrec.ind_order + ', num_tess=' + myrec.num_tess + ') [Num = ' + myrec.index + `] (da ${req.user.name} ${req.user.surname} )`;
}
if (!!msg) {
await telegrambot.sendMsgTelegramToTheManagers(myrec.idapp, msg);
tools.writeSostituzioniLog(msg);
}
return risdel;
};
ListaIngressoSchema.statics.getarray = async function (idapp, filtri, myobjField) {
const ListaIngresso = this;

View File

@@ -445,7 +445,9 @@ function getQueryProj(myfilter) {
sospeso: 1,
'profile.paymenttypes': 1,
'profile.teleg_id': 1,
'profile.nationality': 1,
'profile.email_paypal': 1,
'profile.revolut': 1,
'profile.link_payment': 1,
'profile.note_payment': 1,
'profile.cell': 1,
@@ -1498,6 +1500,7 @@ NaveSchema.statics.getFlotta = async function (idapp, riga, col_prima, col_ultim
if (!!usersognatore) {
flotta.link_payment = usersognatore.profile.link_payment;
flotta.email_paypal = usersognatore.profile.email_paypal;
flotta.revolut = usersognatore.profile.revolut;
flotta.note_payment = usersognatore.profile.note_payment;
}
@@ -1505,6 +1508,8 @@ NaveSchema.statics.getFlotta = async function (idapp, riga, col_prima, col_ultim
const arrnavi = await Nave.aggregate(myquery);
const arrmediatori = [];
for (const nave of arrnavi) {
// Se è il mediatore, allora non includerlo nei Donatori!
mypos = {
@@ -1519,6 +1524,8 @@ NaveSchema.statics.getFlotta = async function (idapp, riga, col_prima, col_ultim
if (!!navemediatore) {
if (navemediatore.ind_order !== nave.ind_order) {
arrnaviout.push(nave);
} else {
arrmediatori.push(nave);
}
} else {
arrnaviout.push(nave);
@@ -1527,7 +1534,7 @@ NaveSchema.statics.getFlotta = async function (idapp, riga, col_prima, col_ultim
flotta._doc.log_attivita = tools.readFlottaLog(idapp, flotta.riga, flotta.col_prima);
return { arrdonatori: arrnaviout, flotta };
return { arrdonatori: arrnaviout, flotta, arrmediatori };
};
@@ -1650,11 +1657,9 @@ NaveSchema.statics.checkIfMadeGift = async function (idapp, username) {
const arrlistaingr = await ListaIngresso.find({ idapp, username });
for (const ingr of arrlistaingr) {
let mynave = await Nave.findOne({ idapp, ind_order: ingr.ind_order });
let mynave = await Nave.findOne({ idapp, ind_order: ingr.ind_order, made_gift: true });
if (!!mynave) {
if (mynave.made_gift) {
return true;
}
return true;
}
}

View File

@@ -94,6 +94,7 @@ function getQueryProj(myfilter) {
username: 1,
'profile.paymenttypes': 1,
'profile.email_paypal': 1,
'profile.revolut': 1,
'profile.link_payment': 1,
'profile.note_payment': 1,
'profile.cell': 1,
@@ -357,7 +358,9 @@ NavePersistenteSchema.statics.changeField = async function (idapp, flotta, field
let myval = {};
if ('date_close' in fieldvalue) {
myval['date_gift_chat_open'] = fieldvalue['date_close'];
myval['date_start'] = fieldvalue['date_close'];
} else if ('date_start' in fieldvalue) {
myval['date_gift_chat_open'] = fieldvalue['date_start'];
} else {
myval = fieldvalue;
}
@@ -378,6 +381,8 @@ NavePersistenteSchema.statics.aggiornaFlottaByNavePersistente = async function (
const { Nave } = require('../models/nave');
const { User } = require('./user');
const { Flotta } = require('./flotta');
let num = 0;
@@ -387,7 +392,7 @@ NavePersistenteSchema.statics.aggiornaFlottaByNavePersistente = async function (
indcolflottaprima = tools.getPrimaColFlotta(naveinput.col1don + 7);
console.log(num, ' -> [', naveinput.riga, '.', naveinput.col, '] indcolflottaprima=', indcolflottaprima);
console.log(num, ' -> [', naveinput.riga, '.', naveinput.col1don, '] indcolflottaprima=', indcolflottaprima);
let ini = Math.ceil(indcolflottaprima / 8);
let fine = ini + 7;
@@ -431,8 +436,8 @@ NavePersistenteSchema.statics.aggiornaFlottaByNavePersistente = async function (
myflotta.msg_inviato = false;
}
myflotta.date_start = navepers.date_start;
myflotta.date_close = navepers.date_gift_chat_open;
myflotta.date_start = navepers.date_gift_chat_open;
myflotta.date_close = navepers.date_start;
let sognatore = await Nave.getSognatoreByRigaColMediatore(idapp, { riga: navepers.riga, col: navepers.col });
if (myflotta.sognatore_nomecognome === '') {
@@ -443,10 +448,12 @@ NavePersistenteSchema.statics.aggiornaFlottaByNavePersistente = async function (
if (nuovo) {
myflotta.email_paypal = '';
myflotta.revolut = '';
myflotta.link_payment = '';
myflotta.note_payment = '';
if (!!sognatore) {
myflotta.email_paypal = sognatore.profile.email_paypal;
myflotta.revolut = sognatore.profile.revolut;
myflotta.link_payment = sognatore.profile.link_payment;
myflotta.note_payment = sognatore.profile.note_payment;
}
@@ -455,6 +462,8 @@ NavePersistenteSchema.statics.aggiornaFlottaByNavePersistente = async function (
if (!!sognatore) {
if (!myflotta.email_paypal)
myflotta.email_paypal = sognatore.profile.email_paypal;
if (!myflotta.revolut)
myflotta.revolut = sognatore.profile.revolut;
if (!myflotta.link_payment)
myflotta.link_payment = sognatore.profile.link_payment;
if (!myflotta.note_payment)

View File

@@ -185,6 +185,9 @@ const UserSchema = new mongoose.Schema({
email_paypal: {
type: String
},
revolut: {
type: String
},
link_payment: {
type: String
},
@@ -455,6 +458,7 @@ UserSchema.statics.getUserShortDataByUsername = async function (idapp, username)
'profile.qualified_2invitati': 1,
'profile.saw_and_accepted': 1,
'profile.email_paypal': 1,
'profile.revolut': 1,
'profile.link_payment': 1,
'profile.note_payment': 1,
'profile.my_dream': 1,
@@ -505,6 +509,7 @@ UserSchema.statics.getDownlineByUsername = async function (idapp, username, incl
'profile.qualified_2invitati': 1,
'profile.saw_and_accepted': 1,
'profile.email_paypal': 1,
'profile.revolut': 1,
'profile.link_payment': 1,
'profile.note_payment': 1,
'profile.my_dream': 1,
@@ -583,11 +588,14 @@ UserSchema.statics.getQueryQualified = function () {
'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 },
'profile.paymenttypes': { "$in": ['paypal'] },
$or: [
{ 'profile.email_paypal': { $exists: true } },
{ 'profile.revolut': { $exists: true } },
],
// 'profile.paymenttypes': { "$in": ['paypal'] },
$and: [
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.my_dream" }, 10] } },
{ "$expr": { "$gt": [{ "$strLenCP": "$profile.email_paypal" }, 6] } }
// { "$expr": { "$gt": [{ "$strLenCP": "$profile.email_paypal" }, 6] } }
],
// $where: "this.profile.paymenttypes.length >= 1",
}]
@@ -658,7 +666,7 @@ UserSchema.statics.setUserQualified = async function (idapp, username) {
'username': username,
};
const myrec = await User.findOneAndUpdate(myquery, { $set: { 'profile.qualified': true } }, { new: false } );
const myrec = await User.findOneAndUpdate(myquery, { $set: { 'profile.qualified': true } }, { new: false });
return !!myrec;
};
@@ -674,7 +682,7 @@ UserSchema.statics.setUserQualified_2Invitati = async function (idapp, username)
'username': username,
};
const myrec = await User.findOneAndUpdate(myquery, { $set: { 'profile.qualified_2invitati': true } }, { new: false } );
const myrec = await User.findOneAndUpdate(myquery, { $set: { 'profile.qualified_2invitati': true } }, { new: false });
return !!myrec;
};
@@ -697,10 +705,18 @@ UserSchema.statics.getnumPaymentOk = function (idapp) {
return User.count({
idapp,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
'profile.paymenttypes': { "$in": ['paypal'] },
$where: "this.profile.paymenttypes.length >= 1",
'profile.email_paypal': { $exists: true },
$and: [
{
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
'profile.paymenttypes': { "$in": ['paypal'] },
},
{
$or: [
{ 'profile.email_paypal': { $exists: true } },
{ 'profile.revolut': { $exists: true } },
]
}
]
});
};
@@ -1132,6 +1148,7 @@ UserSchema.statics.getRecByIndOrder = async function (idapp, ind_order) {
surname: 1,
'profile.teleg_id': 1,
'profile.email_paypal': 1,
'profile.revolut': 1,
'profile.link_payment': 1,
'profile.note_payment': 1,
'profile.paymenttypes': 1,
@@ -1285,6 +1302,7 @@ UserSchema.statics.getFieldsForSearch = function () {
{ field: 'email', type: tools.FieldType.string },
{ field: 'profile.cell', type: tools.FieldType.string },
{ field: 'profile.email_paypal', type: tools.FieldType.string },
{ field: 'profile.revolut', type: tools.FieldType.string },
{ field: 'profile.link_payment', type: tools.FieldType.string },
{ field: 'profile.teleg_id', type: tools.FieldType.number },
{ field: 'profile.username_telegram', type: tools.FieldType.string },
@@ -2187,26 +2205,26 @@ UserSchema.statics.DbOp = async function (idapp, mydata) {
return { num };
} else if (mydata.dbop === 'creaLista') {
/*} else if (mydata.dbop === 'creaLista') {
await ListaIngresso.deleteMany({ idapp, added: false });
await ListaIngresso.deleteMany({ idapp, added: false });
arrusers = await User.find({
'idapp': idapp,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
}).sort({ date_added: 1 });
let num = 0;
arrusers = await User.find({
'idapp': idapp,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
}).sort({ date_added: 1 });
let num = 0;
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 };
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 };
*/
}
} catch (e) {
console.error(e.message);