Lista Doni Navi 3
This commit is contained in:
@@ -4,6 +4,7 @@ const _ = require('lodash');
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const { ListaIngresso } = require('./listaingresso');
|
||||
const { NavePersistente } = require('./navepersistente');
|
||||
const { Settings } = require('./settings');
|
||||
const { User } = require('./user');
|
||||
|
||||
@@ -76,15 +77,21 @@ const NaveSchema = new mongoose.Schema({
|
||||
type: Number,
|
||||
default: 1
|
||||
},
|
||||
note: {
|
||||
type: String
|
||||
},
|
||||
provvisoria: {
|
||||
type: Boolean
|
||||
},
|
||||
note: {
|
||||
/* note_bot: {
|
||||
type: String
|
||||
},
|
||||
note_interne: {
|
||||
type: String
|
||||
}
|
||||
},
|
||||
tutor: {
|
||||
type: String
|
||||
}*/
|
||||
});
|
||||
|
||||
NaveSchema.statics.getTotInLista = async function (idapp) {
|
||||
@@ -419,15 +426,10 @@ function getQueryProj(myfilter) {
|
||||
username: 1,
|
||||
'profile.paymenttypes': 1,
|
||||
'profile.email_paypal': 1,
|
||||
date_start: 1,
|
||||
date_gift_chat_open: 1,
|
||||
made_gift: 1,
|
||||
link_chat: 1,
|
||||
sent_msg_howto_make_gift: 1,
|
||||
date_made_gift: 1,
|
||||
provvisoria: 1,
|
||||
note: 1,
|
||||
note_interne: 1,
|
||||
received_gift: 1,
|
||||
date_received_gift: 1,
|
||||
num_tess: 1,
|
||||
@@ -436,6 +438,14 @@ function getQueryProj(myfilter) {
|
||||
riga: 1,
|
||||
col: 1,
|
||||
created: 1,
|
||||
date_start: 1,
|
||||
date_gift_chat_open: 1,
|
||||
link_chat: 1,
|
||||
provvisoria: 1,
|
||||
note_bot: 1,
|
||||
note_interne: 1,
|
||||
tutor: 1,
|
||||
tutor_namesurname: 1,
|
||||
};
|
||||
|
||||
const query = [
|
||||
@@ -527,8 +537,7 @@ NaveSchema.statics.getPlaccaGenerica = async function (idapp, riga, col, offset,
|
||||
try {
|
||||
let recsognatori = await Nave.findSognatoriByFuoco(idapp, riga, col, offset);
|
||||
let recmediatore = await Nave.findMediatoreByFuoco(idapp, riga, col, offset);
|
||||
|
||||
let primofuoco = getPrimoFuocoByIndCol(col);
|
||||
let navepersistente = await NavePersistente.findByRigaColByDonatore(idapp, riga, col, offset);
|
||||
|
||||
mystr = tools.ACAPO;
|
||||
|
||||
@@ -562,7 +571,7 @@ NaveSchema.statics.getPlaccaGenerica = async function (idapp, riga, col, offset,
|
||||
|
||||
let arrdonatori = [];
|
||||
// let numcol = Math.pow(2, indriga - 1);
|
||||
primofuoco = getPrimoFuocoByIndCol(col * Math.pow(2, offset));
|
||||
let primofuoco = getPrimoFuocoByIndCol(col * Math.pow(2, offset));
|
||||
|
||||
let ind = 1;
|
||||
for (let indcol = primofuoco; indcol < primofuoco + 8; indcol++) {
|
||||
@@ -589,6 +598,7 @@ NaveSchema.statics.getPlaccaGenerica = async function (idapp, riga, col, offset,
|
||||
res = {
|
||||
recsognatori,
|
||||
recmediatore,
|
||||
navepersistente,
|
||||
arrdonatori
|
||||
};
|
||||
|
||||
@@ -624,6 +634,7 @@ NaveSchema.statics.getPlaccaPerDonatore = async function (idapp, riga, col, solo
|
||||
NaveSchema.statics.getPlaccaPerMediatore = async function (idapp, riga, col, solorecord, rec) {
|
||||
const Nave = this;
|
||||
rec.mediatore = await Nave.getPlaccaGenerica(idapp, riga, col, tools.Placca.SONOACQUA, solorecord);
|
||||
rec.mediatore.navepersistente = await NavePersistente.findByRigaColByDonatore(idapp, riga, col, -tools.Placca.SONOACQUA);
|
||||
|
||||
rec.mediatore.arrterra = await Nave.getArrTerra(idapp, riga, col);
|
||||
rec.mediatore.arraria = await Nave.getArrAria(idapp, riga, col);
|
||||
@@ -681,6 +692,7 @@ NaveSchema.statics.getNavePos = async function (idapp, riga, col, solorecord) {
|
||||
await Nave.findRecByRigaColParent(idapp, riga, col, 1)];
|
||||
|
||||
let recmediatore = await Nave.findByRigaCol(idapp, riga, col, true);
|
||||
let recnavepersistente = await NavePersistente.findByRigaCol(idapp, riga, col, 0);
|
||||
|
||||
|
||||
mystr = '🌈SOGNATORE: ';
|
||||
@@ -746,15 +758,17 @@ NaveSchema.statics.getNavePos = async function (idapp, riga, col, solorecord) {
|
||||
let data = "";
|
||||
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;
|
||||
if (!!recmediatore.note)
|
||||
data += "Note: " + recmediatore.note + tools.ACAPO;
|
||||
data = '💬 Giorno di Apertura GIFT CHAT: ' + tools.getstrDateLong(recnavepersistente.date_gift_chat_open) + tools.ACAPO;
|
||||
|
||||
if (!!recnavepersistente.tutor_namesurname)
|
||||
data += 'Il Mediatore sarà contattato 1 giorno prima dal Tutor ' + recnavepersistente.tutor_namesurname + tools.ACAPO;
|
||||
|
||||
data += "🎁 Giorno in cui Inviare il DONO : " + tools.getstrDateLong(recnavepersistente.date_start) + tools.ACAPO;
|
||||
if (!!recnavepersistente.note_bot)
|
||||
data += "Note: " + recnavepersistente.note_bot + tools.ACAPO;
|
||||
data += tools.ACAPO;
|
||||
|
||||
data += 'Il Mediatore sarà contattato 1 giorno prima dal Tutor' + tools.ACAPO;
|
||||
|
||||
if (primofuoco.provvisoria)
|
||||
if (recnavepersistente.provvisoria)
|
||||
mystrtemp = 'TEMPORANEA ';
|
||||
} else
|
||||
data = "";
|
||||
@@ -803,6 +817,8 @@ async function Fuochi8Completati(idapp, params) {
|
||||
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;
|
||||
@@ -826,7 +842,9 @@ NaveSchema.statics.showListaOrd = async function (idapp) {
|
||||
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';
|
||||
let recnavepersistente = await NavePersistente.findByRigaColByDonatore(idapp, rec.riga, rec.col, 0);
|
||||
|
||||
mystr += '[' + conta + '] [' + rec.riga + '.' + rec.col + '] ' + rec.ind_order + ' ' + rec.name + ' ' + rec.surname + ' (' + tools.getstrDateShort(recnavepersistente.date_start) + ')\n';
|
||||
conta++;
|
||||
}
|
||||
|
||||
@@ -841,6 +859,19 @@ NaveSchema.statics.getLastRigaCol = async function (idapp) {
|
||||
async function addRecordNaveByParams(params, siRitesse) {
|
||||
const { ListaIngresso } = require('./listaingresso');
|
||||
|
||||
let mypos = {
|
||||
idapp: params.idapp,
|
||||
riga: params.riga,
|
||||
col: params.col,
|
||||
numup: -3
|
||||
};
|
||||
tools.getRigaColByPosUp(mypos);
|
||||
|
||||
params.riga1don = mypos.riga;
|
||||
params.col1don = mypos.col;
|
||||
|
||||
await NavePersistente.addRecordNavePersistenteByParams(params);
|
||||
|
||||
if (!siRitesse) {
|
||||
// Check if Exist:
|
||||
const giapresente = await Nave.findOne({
|
||||
@@ -863,10 +894,7 @@ async function addRecordNaveByParams(params, siRitesse) {
|
||||
ind_order: params.ind_order,
|
||||
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();
|
||||
|
||||
@@ -1040,9 +1068,10 @@ NaveSchema.statics.generaNave = async function (idapp, mydata) {
|
||||
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();
|
||||
|
||||
await NavePersistente.addRecordNavePersistenteByParams({ idapp, riga: 0, col: 0, riga1don: 0, col1don: 0 });
|
||||
|
||||
const userFondo = await User.findByIndOrder(idapp, 0);
|
||||
if (!userFondo || userFondo === undefined) {
|
||||
await telegrambot.sendMsgTelegramToTheAdmin(idapp, 'Devi creare l\'utente FONDO , con ind_order = 0 ! ');
|
||||
|
||||
178
src/server/models/navepersistente.js
Executable file
178
src/server/models/navepersistente.js
Executable file
@@ -0,0 +1,178 @@
|
||||
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 NavePersistenteSchema = new mongoose.Schema({
|
||||
idapp: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
index: {
|
||||
type: Number
|
||||
},
|
||||
riga: {
|
||||
type: Number,
|
||||
},
|
||||
col: {
|
||||
type: Number,
|
||||
},
|
||||
riga1don: {
|
||||
type: Number,
|
||||
},
|
||||
col1don: {
|
||||
type: Number,
|
||||
},
|
||||
date_start: {
|
||||
type: Date
|
||||
},
|
||||
date_gift_chat_open: {
|
||||
type: Date
|
||||
},
|
||||
link_chat: {
|
||||
type: String,
|
||||
},
|
||||
provvisoria: {
|
||||
type: Boolean,
|
||||
},
|
||||
DoniAttesaDiConferma: {
|
||||
type: Number,
|
||||
},
|
||||
DoniMancanti: {
|
||||
type: Number,
|
||||
},
|
||||
DoniConfermati: {
|
||||
type: Number,
|
||||
},
|
||||
note_bot: {
|
||||
type: String
|
||||
},
|
||||
note_interne: {
|
||||
type: String
|
||||
},
|
||||
tutor: {
|
||||
type: String
|
||||
},
|
||||
tutor_namesurname: {
|
||||
type: String
|
||||
}
|
||||
});
|
||||
|
||||
NavePersistenteSchema.statics.findById = function (idapp, id) {
|
||||
const NavePersistente = this;
|
||||
|
||||
const myquery = getQueryProj({ idapp, '_id': ObjectID(id) });
|
||||
|
||||
return NavePersistente.aggregate(myquery);
|
||||
|
||||
};
|
||||
|
||||
NavePersistenteSchema.statics.getFieldsForSearch = function () {
|
||||
return [{ field: 'ind_order', type: tools.FieldType.number },
|
||||
{ field: 'col', type: tools.FieldType.number }]
|
||||
};
|
||||
|
||||
NavePersistenteSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
NavePersistenteSchema.statics.findAllIdApp = function (idapp) {
|
||||
const NavePersistente = this;
|
||||
|
||||
const myfind = { idapp };
|
||||
|
||||
return NavePersistente.find(myfind).sort({ riga: 1, col: 1 });
|
||||
};
|
||||
|
||||
NavePersistenteSchema.statics.findByRigaColByDonatore = function (idapp, riga, col, offset) {
|
||||
const NavePersistente = this;
|
||||
|
||||
mypos = {
|
||||
riga,
|
||||
col,
|
||||
numup: 3 + offset,
|
||||
};
|
||||
tools.getRigaColByPosUp(mypos);
|
||||
|
||||
return NavePersistente.findOne({ idapp, riga: mypos.riga, col: mypos.col });
|
||||
|
||||
};
|
||||
|
||||
NavePersistenteSchema.statics.findByRigaCol = function (idapp, riga, col) {
|
||||
const NavePersistente = this;
|
||||
|
||||
return NavePersistente.findOne({ idapp, riga, col });
|
||||
|
||||
};
|
||||
|
||||
|
||||
NavePersistenteSchema.statics.getLastRigaCol = async function (idapp) {
|
||||
return NavePersistente.findOne({ idapp }).sort({ _id: -1 });
|
||||
};
|
||||
|
||||
NavePersistenteSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
const myrec = await NavePersistente.findOne().limit(1).sort({_id:-1});
|
||||
if (!!myrec) {
|
||||
this.index = myrec._doc.index + 1;
|
||||
} else {
|
||||
this.index = 1;
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
|
||||
NavePersistenteSchema.statics.addRecordNavePersistenteByParams = async function (params) {
|
||||
|
||||
// Check if Exist:
|
||||
const giapresente = await NavePersistente.findOne({
|
||||
idapp: params.idapp,
|
||||
riga: params.riga,
|
||||
col: params.col
|
||||
});
|
||||
|
||||
if (!giapresente) {
|
||||
let myNavePersistente = new NavePersistente({
|
||||
idapp: params.idapp,
|
||||
riga: params.riga,
|
||||
col: params.col,
|
||||
riga1don: params.riga1don,
|
||||
col1don: params.col1don,
|
||||
date_start: params.date_start,
|
||||
date_gift_chat_open: params.date_gift_chat_open,
|
||||
provvisoria: params.provvisoria,
|
||||
});
|
||||
return await myNavePersistente.save();
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
const NavePersistente = mongoose.model('NavePersistente', NavePersistenteSchema);
|
||||
|
||||
module.exports = { NavePersistente };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user