- Nuovo Sistema di Flotte per Tutor.
X - Mettere anche la email del sognatore, per chi è abituato ad inviarla in quel modo... X - Controllare che sul sito compaiano le informazioni del Sognatore...
This commit is contained in:
@@ -7,6 +7,8 @@ const { ListaIngresso } = require('./listaingresso');
|
||||
const { Settings } = require('./settings');
|
||||
const { User } = require('./user');
|
||||
|
||||
const { Flotta } = require('./flotta');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
@@ -92,6 +94,8 @@ function getQueryProj(myfilter) {
|
||||
username: 1,
|
||||
'profile.paymenttypes': 1,
|
||||
'profile.email_paypal': 1,
|
||||
'profile.link_payment': 1,
|
||||
'profile.note_payment': 1,
|
||||
'profile.cell': 1,
|
||||
made_gift: 1,
|
||||
sent_msg_howto_make_gift: 1,
|
||||
@@ -125,13 +129,13 @@ function getQueryProj(myfilter) {
|
||||
}
|
||||
},
|
||||
{
|
||||
$replaceRoot: { newRoot: { $mergeObjects: [ { $arrayElemAt: [ "$mylista", 0 ] }, "$$ROOT" ] } }
|
||||
$replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$mylista", 0] }, "$$ROOT"] } }
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
as: "user",
|
||||
let: {username: '$username' },
|
||||
let: { username: '$username' },
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
@@ -209,7 +213,7 @@ NavePersistenteSchema.statics.getListaNavi = function (idapp) {
|
||||
NavePersistenteSchema.statics.getLastNave = function (idapp) {
|
||||
const NavePersistente = this;
|
||||
|
||||
const myfind = { idapp, date_start: { $lte: tools.IncDateNow(0) }, provvisoria: false };
|
||||
const myfind = { idapp, date_start: { $lte: tools.IncDateNow(0) }, provvisoria: false };
|
||||
|
||||
return NavePersistente.findOne(myfind,
|
||||
{
|
||||
@@ -250,10 +254,13 @@ NavePersistenteSchema.statics.findByRigaCol = function (idapp, riga, col) {
|
||||
|
||||
|
||||
NavePersistenteSchema.statics.getLastRigaCol = async function (idapp) {
|
||||
const NavePersistente = this;
|
||||
return NavePersistente.findOne({ idapp }).sort({ riga: -1, col: -1 });
|
||||
};
|
||||
|
||||
NavePersistenteSchema.statics.getLastRigaColDefinitiva = async function (idapp) {
|
||||
const NavePersistente = this;
|
||||
|
||||
return NavePersistente.findOne({ idapp, provvisoria: false }).sort({ riga: -1, col: -1 });
|
||||
};
|
||||
|
||||
@@ -272,7 +279,8 @@ NavePersistenteSchema.pre('save', async function (next) {
|
||||
|
||||
function getNextDayNave(miadata) {
|
||||
|
||||
const dayofweek = [1, 3, 5]; // LUNEDI, MERCOLEDI, VENERDI
|
||||
// const dayofweek = [1, 2, 4, 5]; // LUNEDI, MARTEDI', GIOVEDI, VENERDI
|
||||
const dayofweek = [1, 4]; // LUNEDI, GIOVEDI
|
||||
|
||||
let mydate = tools.AddDate(miadata, 1);
|
||||
|
||||
@@ -285,6 +293,7 @@ function getNextDayNave(miadata) {
|
||||
}
|
||||
|
||||
NavePersistenteSchema.statics.addRecordNavePersistenteByParams = async function (params) {
|
||||
const NavePersistente = this;
|
||||
|
||||
// Check if Exist:
|
||||
const giapresente = await NavePersistente.findOne({
|
||||
@@ -295,7 +304,7 @@ NavePersistenteSchema.statics.addRecordNavePersistenteByParams = async function
|
||||
|
||||
if (!giapresente) {
|
||||
// Prende la nave prima:
|
||||
const lastnave = await NavePersistente.findOne({idapp}).sort({riga: -1, col: -1});
|
||||
const lastnave = await NavePersistente.findOne({ idapp: params.idapp }).sort({ riga: -1, col: -1 });
|
||||
|
||||
let nextgiftchat = null;
|
||||
|
||||
@@ -323,6 +332,160 @@ NavePersistenteSchema.statics.addRecordNavePersistenteByParams = async function
|
||||
return false;
|
||||
};
|
||||
|
||||
NavePersistenteSchema.statics.generaFlotte = async function (idapp) {
|
||||
const NavePersistente = this;
|
||||
|
||||
// await Flotta.deleteMany({ idapp });
|
||||
|
||||
const arrnavi = await NavePersistente.find({ idapp, col: { $mod: [8, 1] } }).sort({ riga: 1, col: 1 });
|
||||
|
||||
let num = 0;
|
||||
|
||||
for (const navepers of arrnavi) {
|
||||
|
||||
const ris = await NavePersistente.aggiornaFlottaByNavePersistente(idapp, navepers);
|
||||
if (ris)
|
||||
num++;
|
||||
}
|
||||
|
||||
return { num }
|
||||
|
||||
};
|
||||
|
||||
NavePersistenteSchema.statics.changeField = async function (idapp, flotta, fieldvalue) {
|
||||
|
||||
let myval = {};
|
||||
|
||||
if ('date_close' in fieldvalue) {
|
||||
myval['date_gift_chat_open'] = fieldvalue['date_close'];
|
||||
} else {
|
||||
myval = fieldvalue;
|
||||
}
|
||||
|
||||
const ris = await NavePersistente.updateMany({
|
||||
idapp,
|
||||
riga: flotta.riga,
|
||||
$and: [
|
||||
{ col1don: { $gte: flotta.col_prima } },
|
||||
{ col1don: { $lte: flotta.col_ultima } },
|
||||
]
|
||||
}, { $set: myval });
|
||||
|
||||
return ris;
|
||||
};
|
||||
|
||||
NavePersistenteSchema.statics.aggiornaFlottaByNavePersistente = async function (idapp, naveinput) {
|
||||
|
||||
const { Nave } = require('../models/nave');
|
||||
const { User } = require('./user');
|
||||
|
||||
let num = 0;
|
||||
|
||||
try {
|
||||
let nuovo = false;
|
||||
// let primacol = false;
|
||||
|
||||
indcolflottaprima = tools.getPrimaColFlotta(naveinput.col1don + 7);
|
||||
|
||||
console.log(num, ' -> [', naveinput.riga, '.', naveinput.col, '] indcolflottaprima=', indcolflottaprima);
|
||||
|
||||
let ini = Math.ceil(indcolflottaprima / 8);
|
||||
let fine = ini + 7;
|
||||
|
||||
const arrnavi = await NavePersistente.find({
|
||||
idapp,
|
||||
riga: naveinput.riga,
|
||||
$and: [{ col: { $gte: ini } }, { col: { $lte: fine } }]
|
||||
}).sort({ riga: 1, col: 1 });
|
||||
|
||||
let primogiro = true;
|
||||
|
||||
let myflotta = await Flotta.findOne({ idapp, riga: naveinput.riga, col_prima: indcolflottaprima });
|
||||
|
||||
if (!myflotta) {
|
||||
myflotta = new Flotta({
|
||||
_id: new ObjectID(),
|
||||
idapp,
|
||||
});
|
||||
nuovo = true;
|
||||
}
|
||||
|
||||
for (const navepers of arrnavi) {
|
||||
|
||||
if (primogiro) {
|
||||
myflotta.DoniAttesaDiConferma = 0;
|
||||
myflotta.DoniMancanti = 0;
|
||||
myflotta.DoniConfermati = 0;
|
||||
myflotta.DoniTotali = 0;
|
||||
primogiro = false;
|
||||
}
|
||||
|
||||
if (nuovo) {
|
||||
myflotta.riga = navepers.riga;
|
||||
myflotta.col_prima = indcolflottaprima;
|
||||
myflotta.col_ultima = indcolflottaprima + 63;
|
||||
|
||||
myflotta.sognatore = '';
|
||||
myflotta.sognatore_nomecognome = '';
|
||||
myflotta.link_superchat = '';
|
||||
myflotta.msg_inviato = false;
|
||||
}
|
||||
|
||||
myflotta.date_start = navepers.date_start;
|
||||
myflotta.date_close = navepers.date_gift_chat_open;
|
||||
|
||||
let sognatore = await Nave.getSognatoreByRigaColMediatore(idapp, { riga: navepers.riga, col: navepers.col });
|
||||
if (myflotta.sognatore_nomecognome === '') {
|
||||
myflotta.sognatore = sognatore.username;
|
||||
if (!!sognatore.username)
|
||||
myflotta.sognatore_nomecognome = await User.getNameSurnameByUsername(idapp, sognatore.username);
|
||||
}
|
||||
|
||||
if (nuovo) {
|
||||
myflotta.email_paypal = '';
|
||||
myflotta.link_payment = '';
|
||||
myflotta.note_payment = '';
|
||||
if (!!sognatore) {
|
||||
myflotta.email_paypal = sognatore.profile.email_paypal;
|
||||
myflotta.link_payment = sognatore.profile.link_payment;
|
||||
myflotta.note_payment = sognatore.profile.note_payment;
|
||||
}
|
||||
}
|
||||
|
||||
if (!!sognatore) {
|
||||
if (!myflotta.email_paypal)
|
||||
myflotta.email_paypal = sognatore.profile.email_paypal;
|
||||
if (!myflotta.link_payment)
|
||||
myflotta.link_payment = sognatore.profile.link_payment;
|
||||
if (!myflotta.note_payment)
|
||||
myflotta.note_payment = sognatore.profile.note_payment;
|
||||
}
|
||||
|
||||
myflotta.provvisoria = navepers.provvisoria;
|
||||
|
||||
if (!!navepers.DoniAttesaDiConferma && !isNaN(navepers.DoniAttesaDiConferma))
|
||||
myflotta.DoniAttesaDiConferma += navepers.DoniAttesaDiConferma;
|
||||
if (!!navepers.DoniMancanti && !isNaN(navepers.DoniMancanti))
|
||||
myflotta.DoniMancanti += navepers.DoniMancanti;
|
||||
if (!!navepers.DoniConfermati && !isNaN(navepers.DoniConfermati))
|
||||
myflotta.DoniConfermati += navepers.DoniConfermati;
|
||||
if (!!navepers.DoniTotali && !isNaN(navepers.DoniTotali))
|
||||
myflotta.DoniTotali += navepers.DoniTotali;
|
||||
|
||||
|
||||
}
|
||||
|
||||
await myflotta.save();
|
||||
|
||||
return true;
|
||||
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
const NavePersistente = mongoose.model('NavePersistente', NavePersistenteSchema);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user