- Gruppi
This commit is contained in:
@@ -1,362 +0,0 @@
|
|||||||
const mongoose = require('mongoose').set('debug', false)
|
|
||||||
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 FlottaSchema = new mongoose.Schema({
|
|
||||||
idapp: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
index: {
|
|
||||||
type: Number
|
|
||||||
},
|
|
||||||
riga: {
|
|
||||||
type: Number,
|
|
||||||
},
|
|
||||||
col_prima: {
|
|
||||||
type: Number,
|
|
||||||
},
|
|
||||||
col_ultima: {
|
|
||||||
type: Number,
|
|
||||||
},
|
|
||||||
date_start: {
|
|
||||||
type: Date
|
|
||||||
},
|
|
||||||
date_close: {
|
|
||||||
type: Date
|
|
||||||
},
|
|
||||||
provvisoria: {
|
|
||||||
type: Boolean,
|
|
||||||
},
|
|
||||||
DoniAttesaDiConferma: {
|
|
||||||
type: Number,
|
|
||||||
},
|
|
||||||
DoniMancanti: {
|
|
||||||
type: Number,
|
|
||||||
},
|
|
||||||
DoniConfermati: {
|
|
||||||
type: Number,
|
|
||||||
},
|
|
||||||
DoniTotali: {
|
|
||||||
type: Number,
|
|
||||||
},
|
|
||||||
note_interne: {
|
|
||||||
type: String
|
|
||||||
},
|
|
||||||
sognatore: {
|
|
||||||
type: String
|
|
||||||
},
|
|
||||||
sognatore_nomecognome: {
|
|
||||||
type: String
|
|
||||||
},
|
|
||||||
link_superchat: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
link_payment: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
email_paypal: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
revolut: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
payeer_id: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
advcash_id: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
note_payment: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
tutor1: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
tutor2: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
tutor3: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
tutorslo: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
msg_inviato: {
|
|
||||||
type: Boolean,
|
|
||||||
},
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
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,
|
|
||||||
'profile.payeer_id': 1,
|
|
||||||
'profile.advcash_id': 1,
|
|
||||||
'profile.revolut': 1,
|
|
||||||
'profile.cell': 1,
|
|
||||||
made_gift: 1,
|
|
||||||
commento_al_sognatore: 1,
|
|
||||||
sent_msg_howto_make_gift: 1,
|
|
||||||
date_made_gift: 1,
|
|
||||||
note: 1,
|
|
||||||
received_gift: 1,
|
|
||||||
date_received_gift: 1,
|
|
||||||
num_tess: 1,
|
|
||||||
parent_id: 1,
|
|
||||||
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 = [
|
|
||||||
{ $match: myfilter },
|
|
||||||
{
|
|
||||||
$lookup: {
|
|
||||||
from: "listaingressos",
|
|
||||||
localField: "ind_order",
|
|
||||||
foreignField: "ind_order", // field in the user collection
|
|
||||||
as: "mylista"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$replaceRoot: { newRoot: { $mergeObjects: [ { $arrayElemAt: [ "$mylista", 0 ] }, "$$ROOT" ] } }
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$lookup: {
|
|
||||||
from: "users",
|
|
||||||
as: "user",
|
|
||||||
let: {username: '$username' },
|
|
||||||
pipeline: [
|
|
||||||
{
|
|
||||||
$match: {
|
|
||||||
$expr: {
|
|
||||||
$and: [
|
|
||||||
{ $eq: ['$username', '$$username'] },
|
|
||||||
{ $eq: ['$idapp', myfilter.idapp] },
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$user", 0] }, "$$ROOT"] } }
|
|
||||||
// $replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$user", 0] },] } }
|
|
||||||
},
|
|
||||||
{ $project: myobjField }
|
|
||||||
];
|
|
||||||
|
|
||||||
return query;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
FlottaSchema.statics.findById = function (idapp, id) {
|
|
||||||
const Flotta = this;
|
|
||||||
|
|
||||||
const myquery = getQueryProj({ idapp, '_id': ObjectID(id) });
|
|
||||||
|
|
||||||
return Flotta.aggregate(myquery);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
FlottaSchema.statics.getFieldsForSearch = function () {
|
|
||||||
return [{ field: 'ind_order', type: tools.FieldType.number },
|
|
||||||
{ field: 'col', type: tools.FieldType.number }]
|
|
||||||
};
|
|
||||||
|
|
||||||
FlottaSchema.statics.executeQueryTable = function (idapp, params) {
|
|
||||||
params.fieldsearch = this.getFieldsForSearch();
|
|
||||||
return tools.executeQueryTable(this, idapp, params);
|
|
||||||
};
|
|
||||||
|
|
||||||
FlottaSchema.statics.findAllIdApp = async function (idapp) {
|
|
||||||
const Flotta = this;
|
|
||||||
|
|
||||||
const myfind = { idapp };
|
|
||||||
|
|
||||||
return Flotta.find(myfind).sort({ riga: 1, col: 1 });
|
|
||||||
};
|
|
||||||
|
|
||||||
FlottaSchema.statics.getListaFlotta = function (idapp) {
|
|
||||||
const Flotta = this;
|
|
||||||
|
|
||||||
const myfind = { idapp };
|
|
||||||
|
|
||||||
return Flotta.find(myfind).sort({ riga: 1, col_prima: 1 });
|
|
||||||
};
|
|
||||||
|
|
||||||
FlottaSchema.statics.getLastFlotta = function (idapp) {
|
|
||||||
const Flotta = this;
|
|
||||||
|
|
||||||
const myfind = { idapp, date_start: { $lte: tools.IncDateNow(0) }, provvisoria: false };
|
|
||||||
|
|
||||||
return Flotta.findOne(myfind).sort({ riga: -1, col_prima: -1 }).limit(1);
|
|
||||||
};
|
|
||||||
|
|
||||||
FlottaSchema.statics.findByRigaColByDonatore = function (idapp, riga, col, offset) {
|
|
||||||
const Flotta = this;
|
|
||||||
|
|
||||||
mypos = {
|
|
||||||
riga,
|
|
||||||
col,
|
|
||||||
numup: 3 + offset,
|
|
||||||
};
|
|
||||||
tools.getRigaColByPosUp(mypos);
|
|
||||||
|
|
||||||
return Flotta.findOne({ idapp, riga: mypos.riga, col_prima: mypos.col });
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
FlottaSchema.statics.findByRigaCol = function (idapp, riga, col) {
|
|
||||||
const Flotta = this;
|
|
||||||
|
|
||||||
return Flotta.findOne({ idapp, riga, col });
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
FlottaSchema.statics.getLastRigaCol = async function (idapp) {
|
|
||||||
return Flotta.findOne({ idapp }).sort({ riga: -1, col_prima: -1 });
|
|
||||||
};
|
|
||||||
|
|
||||||
FlottaSchema.statics.getLastRigaColDefinitiva = async function (idapp) {
|
|
||||||
return Flotta.findOne({ idapp, provvisoria: false }).sort({ riga: -1, col_prima: -1 });
|
|
||||||
};
|
|
||||||
|
|
||||||
FlottaSchema.pre('save', async function (next) {
|
|
||||||
if (this.isNew) {
|
|
||||||
const myrec = await Flotta.findOne().limit(1).sort({ _id: -1 });
|
|
||||||
if (!!myrec) {
|
|
||||||
this.index = myrec._doc.index + 1;
|
|
||||||
} else {
|
|
||||||
this.index = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
FlottaSchema.statics.addRecordFlottaByParams = async function (params) {
|
|
||||||
|
|
||||||
// Check if Exist:
|
|
||||||
const giapresente = await Flotta.findOne({
|
|
||||||
idapp: params.idapp,
|
|
||||||
riga: params.riga,
|
|
||||||
col: params.col
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!giapresente) {
|
|
||||||
// Prende la nave prima:
|
|
||||||
const lastnave = await Flotta.findOne({idapp}).sort({riga: -1, col: -1});
|
|
||||||
|
|
||||||
let nextgiftchat = null;
|
|
||||||
|
|
||||||
if (((params.col - 1) % 8 === 0)) {
|
|
||||||
nextgiftchat = getNextDayNave(lastnave.date_gift_chat_open);
|
|
||||||
} else {
|
|
||||||
nextgiftchat = lastnave.date_gift_chat_open;
|
|
||||||
}
|
|
||||||
|
|
||||||
const next_date_start = tools.AddDate(nextgiftchat, 7);
|
|
||||||
|
|
||||||
let myFlotta = new Flotta({
|
|
||||||
idapp: params.idapp,
|
|
||||||
riga: params.riga,
|
|
||||||
col: params.col,
|
|
||||||
riga1don: params.riga1don,
|
|
||||||
col1don: params.col1don,
|
|
||||||
date_gift_chat_open: nextgiftchat,
|
|
||||||
date_start: next_date_start,
|
|
||||||
provvisoria: true,
|
|
||||||
});
|
|
||||||
return await myFlotta.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
FlottaSchema.statics.getFlottaByNavePersistente = async function (idapp, navepers) {
|
|
||||||
const Flotta = this;
|
|
||||||
|
|
||||||
// const indcolflottaprima = tools.getPrimaColFlotta(navepers.col1don + 7);
|
|
||||||
|
|
||||||
const myflotta = await Flotta.findOne({ idapp, riga: navepers.riga,
|
|
||||||
$and: [
|
|
||||||
{ col_prima: { $lte: navepers.col1don } },
|
|
||||||
{ col_ultima: { $gte: navepers.col1don } } ]
|
|
||||||
});
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
module.exports = { Flotta };
|
|
||||||
|
|
||||||
|
|
||||||
@@ -8,7 +8,6 @@ const tools = require('../tools/general');
|
|||||||
|
|
||||||
const { ObjectID } = require('mongodb');
|
const { ObjectID } = require('mongodb');
|
||||||
|
|
||||||
const { Nave } = require('./nave');
|
|
||||||
const { Settings } = require('./settings');
|
const { Settings } = require('./settings');
|
||||||
|
|
||||||
const shared_consts = require('../tools/shared_nodejs');
|
const shared_consts = require('../tools/shared_nodejs');
|
||||||
@@ -192,7 +191,7 @@ GraduatoriaSchema.statics.getFirstUserGradFree = async function (idapp) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
GraduatoriaSchema.statics.addSingoloInGraduatoria_InFondo = async function (idapp, recingr) {
|
GraduatoriaSchema.statics.addSingoloInGraduatoria_InFondo = async function (idapp, recingr) {
|
||||||
const Graduatoria = this;
|
const Graduatoria = this;
|
||||||
|
|
||||||
@@ -200,8 +199,6 @@ GraduatoriaSchema.statics.addSingoloInGraduatoria_InFondo = async function (idap
|
|||||||
|
|
||||||
const arrindex = [];
|
const arrindex = [];
|
||||||
|
|
||||||
const { ListaIngresso } = require('../models/listaingresso');
|
|
||||||
|
|
||||||
if (!!lastimbarco) {
|
if (!!lastimbarco) {
|
||||||
arrindex[recingr.username] = lastimbarco.indimbarco;
|
arrindex[recingr.username] = lastimbarco.indimbarco;
|
||||||
} else {
|
} else {
|
||||||
@@ -223,6 +220,8 @@ GraduatoriaSchema.statics.addSingoloInGraduatoria_InFondo = async function (idap
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
function addRecGraduatoria(idapp, ingr, index) {
|
function addRecGraduatoria(idapp, ingr, index) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
253
src/server/models/mygroup.js
Executable file
253
src/server/models/mygroup.js
Executable file
@@ -0,0 +1,253 @@
|
|||||||
|
const mongoose = require('mongoose').set('debug', false);
|
||||||
|
const Schema = mongoose.Schema;
|
||||||
|
|
||||||
|
const tools = require('../tools/general');
|
||||||
|
|
||||||
|
mongoose.Promise = global.Promise;
|
||||||
|
mongoose.level = 'F';
|
||||||
|
|
||||||
|
// Resolving error Unknown modifier: $pushAll
|
||||||
|
mongoose.plugin(schema => {
|
||||||
|
schema.options.usePushEach = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
const MyGroupSchema = new Schema({
|
||||||
|
idapp: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
groupname: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
descr: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
idSector: {
|
||||||
|
type: Number,
|
||||||
|
},
|
||||||
|
userId: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
photos: [
|
||||||
|
{
|
||||||
|
imagefile: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
alt: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
description: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
idCity: [
|
||||||
|
{
|
||||||
|
type: Number,
|
||||||
|
}],
|
||||||
|
website: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
link_telegram: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
visibility: {
|
||||||
|
type: Number,
|
||||||
|
},
|
||||||
|
admins: [
|
||||||
|
{
|
||||||
|
_id: false,
|
||||||
|
username: {type: String},
|
||||||
|
date: {type: Date},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
blocked: {
|
||||||
|
type: Boolean,
|
||||||
|
},
|
||||||
|
username_who_block: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
date_created: {
|
||||||
|
type: Date,
|
||||||
|
default: Date.now,
|
||||||
|
},
|
||||||
|
date_blocked: {
|
||||||
|
type: Date,
|
||||||
|
},
|
||||||
|
req_users: [
|
||||||
|
{
|
||||||
|
_id: false,
|
||||||
|
username: {type: String},
|
||||||
|
date: {type: Date},
|
||||||
|
}], // username
|
||||||
|
deleted: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
MyGroupSchema.statics.getFieldsForSearch = function() {
|
||||||
|
return [{field: 'descr', type: tools.FieldType.string}];
|
||||||
|
};
|
||||||
|
|
||||||
|
MyGroupSchema.statics.executeQueryTable = function(idapp, params) {
|
||||||
|
params.fieldsearch = this.getFieldsForSearch();
|
||||||
|
return tools.executeQueryTable(this, idapp, params);
|
||||||
|
};
|
||||||
|
|
||||||
|
MyGroupSchema.statics.findAllIdApp = async function(idapp) {
|
||||||
|
const myfind = {idapp};
|
||||||
|
|
||||||
|
return await MyGroup.find(myfind);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Rimuovo la Richiesta del Gruppo
|
||||||
|
MyGroupSchema.statics.removeReqGroup = async function(
|
||||||
|
idapp, username, groupnameDest) {
|
||||||
|
const {User} = require('../models/user');
|
||||||
|
|
||||||
|
return User.updateOne({idapp, username: username},
|
||||||
|
{$pull: {'profile.req_groups': {groupname: {$in: [groupnameDest]}}}});
|
||||||
|
};
|
||||||
|
|
||||||
|
function getWhatToShow(idapp, username) {
|
||||||
|
// ++Todo: MyGroup what to show
|
||||||
|
return {
|
||||||
|
groupname: 1,
|
||||||
|
title: 1,
|
||||||
|
descr: 1,
|
||||||
|
visibility: 1,
|
||||||
|
idSector: 1,
|
||||||
|
userId: 1,
|
||||||
|
photos: 1,
|
||||||
|
idCity: 1,
|
||||||
|
website: 1,
|
||||||
|
link_telegram: 1,
|
||||||
|
admins: 1,
|
||||||
|
blocked: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function getWhatToShow_Unknown(idapp, username) {
|
||||||
|
return {
|
||||||
|
groupname: 1,
|
||||||
|
title: 1,
|
||||||
|
descr: 1,
|
||||||
|
photos: 1,
|
||||||
|
visibility: 1,
|
||||||
|
idSector: 1,
|
||||||
|
idCity: 1,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
MyGroupSchema.statics.getArrUsernameFromFieldByGroupname = async function(
|
||||||
|
idapp, groupname, field) {
|
||||||
|
|
||||||
|
const {User} = require('../models/user');
|
||||||
|
|
||||||
|
const myobj = {};
|
||||||
|
myobj[field + '.' + subfield] = 1;
|
||||||
|
|
||||||
|
let arrrec = await User.findOne({
|
||||||
|
idapp,
|
||||||
|
groupname,
|
||||||
|
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
|
||||||
|
}, myobj).then((ris) => ris ? ris._doc[field] : []);
|
||||||
|
|
||||||
|
if (arrrec.length > 0) {
|
||||||
|
return arrrec.map(m => m.username);
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
MyGroupSchema.statics.getUsernameReqGroupsByGroupname = async function(
|
||||||
|
idapp, groupname) {
|
||||||
|
|
||||||
|
return this.getArrUsernameFromFieldByGroupname(idapp, groupname, 'req_users');
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
MyGroupSchema.statics.getInfoGroupByGroupname = async function(
|
||||||
|
idapp, groupname) {
|
||||||
|
|
||||||
|
const whatToShow = getWhatToShow(idapp, groupname);
|
||||||
|
|
||||||
|
return MyGroup.findOne({
|
||||||
|
idapp,
|
||||||
|
groupname,
|
||||||
|
}, whatToShow).then((rec) => !!rec ? rec._doc : null);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
MyGroupSchema.statics.getGroupsByUsername = async function(idapp, username) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
const {User} = require('../models/user');
|
||||||
|
|
||||||
|
const whatToShow = getWhatToShow(idapp, username);
|
||||||
|
const whatToShow_Unknown = getWhatToShow_Unknown(idapp, username);
|
||||||
|
const arrUsernameGroups = await User.getUsernameGroupsByUsername(idapp,
|
||||||
|
username);
|
||||||
|
// const arrUsernameReqGroups = await MyGroup.getUsernameReqGroupsByGroupname(idapp, username);
|
||||||
|
|
||||||
|
let listUsersGroup = await User.find({
|
||||||
|
idapp,
|
||||||
|
username: {$in: arrUsernameGroups},
|
||||||
|
$or: [
|
||||||
|
{deleted: {$exists: false}},
|
||||||
|
{deleted: {$exists: true, $eq: false}}],
|
||||||
|
}, whatToShow);
|
||||||
|
|
||||||
|
let listgroups = await MyGroup.find({
|
||||||
|
idapp,
|
||||||
|
$or: [
|
||||||
|
{deleted: {$exists: false}},
|
||||||
|
{deleted: {$exists: true, $eq: false}}],
|
||||||
|
}, whatToShow_Unknown);
|
||||||
|
|
||||||
|
/*let listRequestUsersGroup = await User.find({
|
||||||
|
idapp,
|
||||||
|
username: {$in: arrUsernameReqGroups},
|
||||||
|
$or: [
|
||||||
|
{deleted: {$exists: false}},
|
||||||
|
{deleted: {$exists: true, $eq: false}}],
|
||||||
|
}, whatToShow_Unknown);
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
let listSentRequestGroups = await MyGroup.find({
|
||||||
|
idapp,
|
||||||
|
'req_users': {
|
||||||
|
$elemMatch: {username: {$eq: username}},
|
||||||
|
},
|
||||||
|
$or: [
|
||||||
|
{deleted: {$exists: false}},
|
||||||
|
{deleted: {$exists: true, $eq: false}}],
|
||||||
|
}, whatToShow_Unknown);
|
||||||
|
|
||||||
|
return {
|
||||||
|
listUsersGroup,
|
||||||
|
listgroups,
|
||||||
|
//listRequestUsersGroup,
|
||||||
|
listSentRequestGroups,
|
||||||
|
};
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Error', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
listUsersGroup: [],
|
||||||
|
listRequestUsersGroup: [],
|
||||||
|
listTrusted: [],
|
||||||
|
listSentRequestGroups: [],
|
||||||
|
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const MyGroup = mongoose.model('MyGroup', MyGroupSchema);
|
||||||
|
|
||||||
|
module.exports = {MyGroup};
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,511 +0,0 @@
|
|||||||
const mongoose = require('mongoose').set('debug', false)
|
|
||||||
const _ = require('lodash');
|
|
||||||
|
|
||||||
const tools = require('../tools/general');
|
|
||||||
|
|
||||||
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');
|
|
||||||
|
|
||||||
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,
|
|
||||||
},
|
|
||||||
DoniTotali: {
|
|
||||||
type: Number,
|
|
||||||
},
|
|
||||||
note_bot: {
|
|
||||||
type: String
|
|
||||||
},
|
|
||||||
note_interne: {
|
|
||||||
type: String
|
|
||||||
},
|
|
||||||
tutor: {
|
|
||||||
type: String
|
|
||||||
},
|
|
||||||
tutor_namesurname: {
|
|
||||||
type: String
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
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,
|
|
||||||
'profile.revolut': 1,
|
|
||||||
'profile.link_payment': 1,
|
|
||||||
'profile.note_payment': 1,
|
|
||||||
'profile.cell': 1,
|
|
||||||
made_gift: 1,
|
|
||||||
sent_msg_howto_make_gift: 1,
|
|
||||||
date_made_gift: 1,
|
|
||||||
note: 1,
|
|
||||||
received_gift: 1,
|
|
||||||
date_received_gift: 1,
|
|
||||||
num_tess: 1,
|
|
||||||
parent_id: 1,
|
|
||||||
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 = [
|
|
||||||
{ $match: myfilter },
|
|
||||||
{
|
|
||||||
$lookup: {
|
|
||||||
from: "listaingressos",
|
|
||||||
localField: "ind_order",
|
|
||||||
foreignField: "ind_order", // field in the user collection
|
|
||||||
as: "mylista"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$mylista", 0] }, "$$ROOT"] } }
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$lookup: {
|
|
||||||
from: "users",
|
|
||||||
as: "user",
|
|
||||||
let: { username: '$username' },
|
|
||||||
pipeline: [
|
|
||||||
{
|
|
||||||
$match: {
|
|
||||||
$expr: {
|
|
||||||
$and: [
|
|
||||||
{ $eq: ['$username', '$$username'] },
|
|
||||||
{ $eq: ['$idapp', myfilter.idapp] },
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$user", 0] }, "$$ROOT"] } }
|
|
||||||
// $replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$user", 0] },] } }
|
|
||||||
},
|
|
||||||
{ $project: myobjField }
|
|
||||||
];
|
|
||||||
|
|
||||||
return query;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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 = async function (idapp) {
|
|
||||||
const NavePersistente = this;
|
|
||||||
|
|
||||||
const myfind = { idapp };
|
|
||||||
|
|
||||||
return NavePersistente.find(myfind).sort({ riga: 1, col: 1 });
|
|
||||||
};
|
|
||||||
|
|
||||||
NavePersistenteSchema.statics.getListaNavi = function (idapp) {
|
|
||||||
const NavePersistente = this;
|
|
||||||
|
|
||||||
const myfind = { idapp };
|
|
||||||
|
|
||||||
return NavePersistente.find(myfind,
|
|
||||||
{
|
|
||||||
index: 1,
|
|
||||||
riga: 1,
|
|
||||||
col: 1,
|
|
||||||
riga1don: 1,
|
|
||||||
col1don: 1,
|
|
||||||
date_gift_chat_open: 1,
|
|
||||||
date_start: 1,
|
|
||||||
provvisoria: 1,
|
|
||||||
DoniConfermati: 1,
|
|
||||||
DoniTotali: 1,
|
|
||||||
DoniMancanti: 1,
|
|
||||||
}
|
|
||||||
).sort({ riga: 1, col: 1 });
|
|
||||||
};
|
|
||||||
|
|
||||||
NavePersistenteSchema.statics.getLastNave = function (idapp) {
|
|
||||||
const NavePersistente = this;
|
|
||||||
|
|
||||||
const myfind = { idapp, date_start: { $lte: tools.IncDateNow(0) }, provvisoria: false };
|
|
||||||
|
|
||||||
return NavePersistente.findOne(myfind,
|
|
||||||
{
|
|
||||||
index: 1,
|
|
||||||
riga: 1,
|
|
||||||
col: 1,
|
|
||||||
riga1don: 1,
|
|
||||||
col1don: 1,
|
|
||||||
date_start: 1,
|
|
||||||
provvisoria: 1,
|
|
||||||
DoniConfermati: 1,
|
|
||||||
DoniTotali: 1,
|
|
||||||
DoniMancanti: 1,
|
|
||||||
}
|
|
||||||
).sort({ riga: -1, col: -1 }).limit(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) {
|
|
||||||
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 });
|
|
||||||
};
|
|
||||||
|
|
||||||
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();
|
|
||||||
});
|
|
||||||
|
|
||||||
function getNextDayNave(miadata) {
|
|
||||||
|
|
||||||
// const dayofweek = [1, 2, 4, 5]; // LUNEDI, MARTEDI', GIOVEDI, VENERDI
|
|
||||||
const dayofweek = [1, 4]; // LUNEDI, GIOVEDI
|
|
||||||
|
|
||||||
let mydate = tools.AddDate(miadata, 1);
|
|
||||||
|
|
||||||
while (!dayofweek.includes(mydate.getDay())) {
|
|
||||||
mydate = tools.AddDate(mydate, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return mydate
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
NavePersistenteSchema.statics.addRecordNavePersistenteByParams = async function (params) {
|
|
||||||
const NavePersistente = this;
|
|
||||||
|
|
||||||
// Check if Exist:
|
|
||||||
const giapresente = await NavePersistente.findOne({
|
|
||||||
idapp: params.idapp,
|
|
||||||
riga: params.riga,
|
|
||||||
col: params.col
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!giapresente) {
|
|
||||||
// Prende la nave prima:
|
|
||||||
const lastnave = await NavePersistente.findOne({ idapp: params.idapp }).sort({ riga: -1, col: -1 });
|
|
||||||
|
|
||||||
let nextgiftchat = null;
|
|
||||||
|
|
||||||
if (((params.col - 1) % 8 === 0)) {
|
|
||||||
nextgiftchat = getNextDayNave(lastnave.date_gift_chat_open);
|
|
||||||
} else {
|
|
||||||
nextgiftchat = lastnave.date_gift_chat_open;
|
|
||||||
}
|
|
||||||
|
|
||||||
const next_date_start = tools.AddDate(nextgiftchat, 7);
|
|
||||||
|
|
||||||
let myNavePersistente = new NavePersistente({
|
|
||||||
idapp: params.idapp,
|
|
||||||
riga: params.riga,
|
|
||||||
col: params.col,
|
|
||||||
riga1don: params.riga1don,
|
|
||||||
col1don: params.col1don,
|
|
||||||
date_gift_chat_open: nextgiftchat,
|
|
||||||
date_start: next_date_start,
|
|
||||||
provvisoria: true,
|
|
||||||
});
|
|
||||||
return await myNavePersistente.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
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_start'] = fieldvalue['date_close'];
|
|
||||||
} else if ('date_start' in fieldvalue) {
|
|
||||||
myval['date_gift_chat_open'] = fieldvalue['date_start'];
|
|
||||||
} 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');
|
|
||||||
const { Flotta } = require('./flotta');
|
|
||||||
|
|
||||||
|
|
||||||
let num = 0;
|
|
||||||
|
|
||||||
try {
|
|
||||||
let nuovo = false;
|
|
||||||
// let primacol = false;
|
|
||||||
|
|
||||||
indcolflottaprima = tools.getPrimaColFlotta(naveinput.col1don + 7);
|
|
||||||
|
|
||||||
console.log(num, ' -> [', naveinput.riga, '.', naveinput.col1don, '] 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_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 === '') {
|
|
||||||
myflotta.sognatore = sognatore.username;
|
|
||||||
if (!!sognatore.username)
|
|
||||||
myflotta.sognatore_nomecognome = await User.getNameSurnameByUsername(idapp, sognatore.username);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nuovo) {
|
|
||||||
myflotta.email_paypal = '';
|
|
||||||
myflotta.payeer_id = '';
|
|
||||||
myflotta.advcash_id = '';
|
|
||||||
myflotta.revolut = '';
|
|
||||||
myflotta.link_payment = '';
|
|
||||||
myflotta.note_payment = '';
|
|
||||||
if (!!sognatore) {
|
|
||||||
myflotta.email_paypal = sognatore.profile.email_paypal;
|
|
||||||
myflotta.payeer_id = sognatore.profile.payeer_id;
|
|
||||||
myflotta.advcash_id = sognatore.profile.advcash_id;
|
|
||||||
myflotta.revolut = sognatore.profile.revolut;
|
|
||||||
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.payeer_id)
|
|
||||||
myflotta.payeer_id = sognatore.profile.payeer_id;
|
|
||||||
if (!myflotta.advcash_id)
|
|
||||||
myflotta.advcash_id = sognatore.profile.advcash_id;
|
|
||||||
if (!myflotta.revolut)
|
|
||||||
myflotta.revolut = sognatore.profile.revolut;
|
|
||||||
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);
|
|
||||||
|
|
||||||
module.exports = { NavePersistente };
|
|
||||||
|
|
||||||
|
|
||||||
@@ -6,14 +6,15 @@ const _ = require('lodash');
|
|||||||
|
|
||||||
const tools = require('../tools/general');
|
const tools = require('../tools/general');
|
||||||
|
|
||||||
const {Flotta} = require('../models/flotta');
|
|
||||||
const {Settings} = require('../models/settings');
|
const {Settings} = require('../models/settings');
|
||||||
const {ListaIngresso} = require('../models/listaingresso');
|
// const {ListaIngresso} = require('../models/listaingresso');
|
||||||
const {Graduatoria} = require('../models/graduatoria');
|
const {Graduatoria} = require('../models/graduatoria');
|
||||||
const {Nave} = require('../models/nave');
|
// const {Nave} = require('../models/nave');
|
||||||
const {NavePersistente} = require('../models/navepersistente');
|
// const {NavePersistente} = require('../models/navepersistente');
|
||||||
// const { ExtraList } = require('../models/extralist');
|
// const { ExtraList } = require('../models/extralist');
|
||||||
|
|
||||||
|
const {MyGroup} = require('../models/mygroup');
|
||||||
|
|
||||||
const {ObjectID} = require('mongodb');
|
const {ObjectID} = require('mongodb');
|
||||||
|
|
||||||
const shared_consts = require('../tools/shared_nodejs');
|
const shared_consts = require('../tools/shared_nodejs');
|
||||||
@@ -341,6 +342,12 @@ const UserSchema = new mongoose.Schema({
|
|||||||
username: {type: String},
|
username: {type: String},
|
||||||
date: {type: Date},
|
date: {type: Date},
|
||||||
}], // username
|
}], // username
|
||||||
|
groups: [
|
||||||
|
{
|
||||||
|
_id: false,
|
||||||
|
groupname: {type: String},
|
||||||
|
date: {type: Date},
|
||||||
|
}], // username
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
;
|
;
|
||||||
@@ -657,12 +664,9 @@ UserSchema.statics.getUserShortDataByUsername = async function(
|
|||||||
|
|
||||||
if (myrec) {
|
if (myrec) {
|
||||||
myrec.qualified = await User.isUserQualified7(idapp, myrec.username);
|
myrec.qualified = await User.isUserQualified7(idapp, myrec.username);
|
||||||
myrec.numNaviEntrato = await Nave.getnumNaviByUsername(idapp,
|
myrec.numNaviEntrato = 0;
|
||||||
myrec.username);
|
// myrec.numinvitati = await ListaIngresso.getnumInvitati(idapp, myrec.username);
|
||||||
myrec.numinvitati = await ListaIngresso.getnumInvitati(idapp,
|
// myrec.numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(idapp, myrec.username);
|
||||||
myrec.username);
|
|
||||||
myrec.numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(idapp,
|
|
||||||
myrec.username);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return myrec;
|
return myrec;
|
||||||
@@ -674,37 +678,7 @@ UserSchema.statics.getDownlineByUsername = async function(
|
|||||||
if (username === undefined)
|
if (username === undefined)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
let arrrec = await ListaIngresso.getInvitati(idapp, username, includemyself,
|
let arrrec = [];
|
||||||
{
|
|
||||||
index: 1,
|
|
||||||
lang: 1,
|
|
||||||
invitante_username: 1,
|
|
||||||
ind_order: 1,
|
|
||||||
username: 1,
|
|
||||||
name: 1,
|
|
||||||
surname: 1,
|
|
||||||
verified_email: 1,
|
|
||||||
'profile.teleg_id': 1,
|
|
||||||
// 'profile.saw_zoom_presentation': 1,
|
|
||||||
'profile.ask_zoom_partecipato': 1,
|
|
||||||
'profile.qualified': 1,
|
|
||||||
'profile.qualified_2invitati': 1,
|
|
||||||
'profile.saw_and_accepted': 1,
|
|
||||||
'profile.email_paypal': 1,
|
|
||||||
'profile.payeer_id': 1,
|
|
||||||
'profile.advcash_id': 1,
|
|
||||||
'profile.revolut': 1,
|
|
||||||
'profile.link_payment': 1,
|
|
||||||
'profile.note_payment': 1,
|
|
||||||
// 'profile.my_dream': 1,
|
|
||||||
'profile.paymenttypes': 1,
|
|
||||||
'profile.cell': 1,
|
|
||||||
made_gift: 1,
|
|
||||||
email: 1,
|
|
||||||
date_reg: 1,
|
|
||||||
img: 1,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
let myq = {
|
let myq = {
|
||||||
idapp,
|
idapp,
|
||||||
@@ -716,44 +690,6 @@ UserSchema.statics.getDownlineByUsername = async function(
|
|||||||
myq = {...myq, username: {$ne: username}};
|
myq = {...myq, username: {$ne: username}};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ottieni gli invitati che ancora non hanno un'imbarco
|
|
||||||
const arrinv = await User.find(myq);
|
|
||||||
|
|
||||||
for (const inv of arrinv) {
|
|
||||||
if (!arrrec.find((rec) => rec.username === inv.username))
|
|
||||||
arrrec.push(inv._doc);
|
|
||||||
}
|
|
||||||
|
|
||||||
const arrusername = [];
|
|
||||||
|
|
||||||
for (const inv of arrrec) {
|
|
||||||
|
|
||||||
const rectrovato = arrusername.find((rec) => inv.username === rec.username);
|
|
||||||
if (!!rectrovato) {
|
|
||||||
rectrovato.quanti++;
|
|
||||||
} else {
|
|
||||||
const myrec = {...inv};
|
|
||||||
myrec.quanti = 1;
|
|
||||||
arrusername.push(myrec);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
arrrec = arrusername;
|
|
||||||
|
|
||||||
if (!onlynumber) {
|
|
||||||
if (!!arrrec) {
|
|
||||||
for (const rec of arrrec) {
|
|
||||||
rec.qualified = await User.isUserQualified7(idapp, rec.username);
|
|
||||||
rec.numNaviEntrato = await Nave.getnumNaviByUsername(idapp,
|
|
||||||
rec.username);
|
|
||||||
rec.numinvitati = await ListaIngresso.getnumInvitati(idapp,
|
|
||||||
rec.username);
|
|
||||||
rec.numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(idapp,
|
|
||||||
rec.username);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return arrrec;
|
return arrrec;
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -961,6 +897,7 @@ UserSchema.statics.setUserQualified_2Invitati = async function(
|
|||||||
return !!myrec;
|
return !!myrec;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
UserSchema.statics.isUserQualified9 = async function(idapp, username) {
|
UserSchema.statics.isUserQualified9 = async function(idapp, username) {
|
||||||
const User = this;
|
const User = this;
|
||||||
|
|
||||||
@@ -968,11 +905,12 @@ UserSchema.statics.isUserQualified9 = async function(idapp, username) {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
qualified = await User.isUserQualified7(idapp, username);
|
qualified = await User.isUserQualified7(idapp, username);
|
||||||
numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(idapp, username);
|
// numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(idapp, username);
|
||||||
|
|
||||||
return qualified && (numinvitatiattivi >= 2);
|
return qualified && (numinvitatiattivi >= 2);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
UserSchema.statics.getnumPaymentOk = function (idapp) {
|
UserSchema.statics.getnumPaymentOk = function (idapp) {
|
||||||
@@ -1201,6 +1139,16 @@ UserSchema.statics.getUserById = function(idapp, id) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
UserSchema.statics.getUserByUsername = function(idapp, username) {
|
||||||
|
const User = this;
|
||||||
|
|
||||||
|
return User.findOne({
|
||||||
|
idapp,
|
||||||
|
username,
|
||||||
|
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
UserSchema.statics.isMyFriend = async function(idapp, username, myusername) {
|
UserSchema.statics.isMyFriend = async function(idapp, username, myusername) {
|
||||||
|
|
||||||
const myfriends = await User.getUsernameFriendsByUsername(idapp, myusername);
|
const myfriends = await User.getUsernameFriendsByUsername(idapp, myusername);
|
||||||
@@ -1337,11 +1285,11 @@ UserSchema.statics.getArrUsernameFromFieldByUsername = async function(
|
|||||||
UserSchema.statics.getUsernameReqFriendsByUsername = async function(
|
UserSchema.statics.getUsernameReqFriendsByUsername = async function(
|
||||||
idapp, username) {
|
idapp, username) {
|
||||||
|
|
||||||
return this.getArrUsernameFromFieldByUsername(idapp, username, 'profile',
|
return this.getArrUsernameFromFieldByUsername(idapp, username, 'profile', 'req_friends');
|
||||||
'req_friends');
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
UserSchema.statics.getUsernameFriendsByUsername = async function(
|
UserSchema.statics.getUsernameFriendsByUsername = async function(
|
||||||
idapp, username) {
|
idapp, username) {
|
||||||
|
|
||||||
@@ -1350,12 +1298,25 @@ UserSchema.statics.getUsernameFriendsByUsername = async function(
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
UserSchema.statics.getUsernameGroupsByUsername = async function(
|
||||||
|
idapp, username) {
|
||||||
|
|
||||||
|
return this.getArrUsernameFromFieldByUsername(idapp, username, 'profile', 'groups');
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
// Rimuovo l'Amicizia
|
// Rimuovo l'Amicizia
|
||||||
UserSchema.statics.removeFriend = async function(idapp, username, usernameDest) {
|
UserSchema.statics.removeFriend = async function(idapp, username, usernameDest) {
|
||||||
return User.updateOne({idapp, username},
|
return User.updateOne({idapp, username},
|
||||||
{$pull: {'profile.friends': {username: {$in: [usernameDest]}}}});
|
{$pull: {'profile.friends': {username: {$in: [usernameDest]}}}});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Rimuovo il Gruppo
|
||||||
|
UserSchema.statics.removeFromMyGroups = async function(idapp, username, groupnameDest) {
|
||||||
|
return User.updateOne({idapp, username},
|
||||||
|
{$pull: {'profile.groups': {groupname: {$in: [groupnameDest]}}}});
|
||||||
|
};
|
||||||
|
|
||||||
// Rimuovo la Richiesta di Amicizia
|
// Rimuovo la Richiesta di Amicizia
|
||||||
UserSchema.statics.removeReqFriend = async function(idapp, username, usernameDest) {
|
UserSchema.statics.removeReqFriend = async function(idapp, username, usernameDest) {
|
||||||
return User.updateOne({idapp, username: username},
|
return User.updateOne({idapp, username: username},
|
||||||
@@ -1496,8 +1457,106 @@ UserSchema.statics.setFriendsCmd = async function(
|
|||||||
return ris;
|
return ris;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameDest, cmd, value) {
|
||||||
|
|
||||||
|
let ris = null;
|
||||||
|
let update = {};
|
||||||
|
try {
|
||||||
|
if (cmd === shared_consts.GROUPSCMD.SETGROUP) {
|
||||||
|
// Aggiungo l'Amicizia a me
|
||||||
|
const foundIfAlreadyGroup = await User.findOne({
|
||||||
|
idapp,
|
||||||
|
username: usernameOrig,
|
||||||
|
'profile.groups': {
|
||||||
|
$elemMatch: {groupname: {$eq: groupnameDest}},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!foundIfAlreadyGroup) {
|
||||||
|
update = {
|
||||||
|
$push: {
|
||||||
|
'profile.groups': {
|
||||||
|
groupname: groupnameDest,
|
||||||
|
date: new Date(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
ris = await User.updateOne({idapp, username: usernameOrig}, update);
|
||||||
|
|
||||||
|
update = {$pull: {'profile.req_groups': {groupname: {$in: [groupnameDest]}}}};
|
||||||
|
ris = await User.updateOne({idapp, username: usernameOrig}, update);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ris) {
|
||||||
|
ris = await MyGroup.getInfoGroupByGroupname(idapp, groupnameDest);
|
||||||
|
}
|
||||||
|
} else if (cmd === shared_consts.GROUPSCMD.REQGROUP) {
|
||||||
|
// Aggiungo la richiesta di Amicizia a me
|
||||||
|
const foundIfAlreadyAskGroup = await MyGroup.findOne({
|
||||||
|
idapp,
|
||||||
|
groupname: groupnameDest,
|
||||||
|
'req_groups': {
|
||||||
|
$elemMatch: { username: {$eq: usernameOrig}},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (value) {
|
||||||
|
if (!foundIfAlreadyAskGroup) {
|
||||||
|
update = {
|
||||||
|
$push: {
|
||||||
|
'profile.req_groups': {
|
||||||
|
username: usernameOrig,
|
||||||
|
date: new Date(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
ris = await User.updateOne({idapp, username: groupnameDest}, update);
|
||||||
|
}
|
||||||
|
if (ris) {
|
||||||
|
// Invia una notifica alla persona
|
||||||
|
tools.sendNotificationByGroupName(idapp, groupnameDest, cmd, true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (foundIfAlreadyAskGroup) {
|
||||||
|
ris = await this.removeFromMyGroups(idapp, groupnameDest, usernameOrig); // Rimuovo l'Amicizia da me
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ris) {
|
||||||
|
ris = await User.getInfoAskGroupByUsername(idapp, groupnameDest);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (cmd === shared_consts.GROUPSCMD.REMOVE_FROM_MYGROUPS) {
|
||||||
|
|
||||||
|
ris = await this.removeFromMyGroups(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me
|
||||||
|
|
||||||
|
} else if (cmd === shared_consts.GROUPSCMD.CANCEL_REQ_GROUP) {
|
||||||
|
|
||||||
|
ris = await MyGroup.removeReqGroup(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me
|
||||||
|
|
||||||
|
} else if (cmd === shared_consts.GROUPSCMD.BLOCK_GROUP) {
|
||||||
|
|
||||||
|
await this.removeFromMyGroups(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me
|
||||||
|
|
||||||
|
// Blocco il Gruppo
|
||||||
|
ris = await MyGroup.updateOne({idapp, username: groupnameDest}, {
|
||||||
|
$set: {
|
||||||
|
blocked: true,
|
||||||
|
username_who_block: usernameOrig,
|
||||||
|
date_blocked: new Date(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
//++Todo: Send Notification to Admin and Group's manager
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error: ', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ris;
|
||||||
|
};
|
||||||
|
|
||||||
function getWhatToShow(idapp, username) {
|
function getWhatToShow(idapp, username) {
|
||||||
//++Todo: check which data to show
|
|
||||||
return {
|
return {
|
||||||
username: 1,
|
username: 1,
|
||||||
aportador_solidario: 1,
|
aportador_solidario: 1,
|
||||||
@@ -1841,6 +1900,8 @@ UserSchema.statics.getNameSurnameById = async function(idapp, userId) {
|
|||||||
UserSchema.statics.getSmallRecByIndOrder = async function(idapp, ind_order) {
|
UserSchema.statics.getSmallRecByIndOrder = async function(idapp, ind_order) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const rec = {};
|
||||||
|
/*
|
||||||
const rec = await ListaIngresso.getarray(idapp,
|
const rec = await ListaIngresso.getarray(idapp,
|
||||||
{
|
{
|
||||||
idapp,
|
idapp,
|
||||||
@@ -1864,6 +1925,8 @@ UserSchema.statics.getSmallRecByIndOrder = async function(idapp, ind_order) {
|
|||||||
if (!!rec)
|
if (!!rec)
|
||||||
return rec[0];
|
return rec[0];
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -1889,7 +1952,7 @@ UserSchema.statics.getRecByIndOrder = async function(idapp, ind_order) {
|
|||||||
const User = this;
|
const User = this;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
/*
|
||||||
let filters = {
|
let filters = {
|
||||||
idapp: 1,
|
idapp: 1,
|
||||||
index: 1,
|
index: 1,
|
||||||
@@ -1920,6 +1983,8 @@ UserSchema.statics.getRecByIndOrder = async function(idapp, ind_order) {
|
|||||||
if (!!rec)
|
if (!!rec)
|
||||||
return rec[0];
|
return rec[0];
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -2147,99 +2212,6 @@ UserSchema.statics.getDashboard = async function(
|
|||||||
if (!!arrap)
|
if (!!arrap)
|
||||||
dashboard.numpeople_aportador = arrap.length;
|
dashboard.numpeople_aportador = arrap.length;
|
||||||
|
|
||||||
dashboard.arrimbarchi = await ListaIngresso.findAllByUsername(idapp,
|
|
||||||
username);
|
|
||||||
|
|
||||||
// dashboard.arrprofili = await Nave.getArrProfiliByIndOrder(idapp, dashboard.myself.ind_order);
|
|
||||||
|
|
||||||
dashboard.arrposizioni = await Nave.getArrPosizioniByUsername(idapp,
|
|
||||||
username);
|
|
||||||
|
|
||||||
/* let arrrec = [];
|
|
||||||
if (dashboard.arrimbarchi.length > 0) {
|
|
||||||
arrrec = await ListaIngresso.getProssimiInLista(idapp, true);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
for (let myimbarco of dashboard.arrimbarchi) {
|
|
||||||
if (!!myimbarco.invitante_username)
|
|
||||||
dashboard.arrusers[myimbarco.invitante_username] = await User.getUserShortDataByUsername(
|
|
||||||
idapp, myimbarco.invitante_username);
|
|
||||||
myimbarco._doc.posiz = await Graduatoria.getPosizioneInGraduatoria(idapp,
|
|
||||||
myimbarco.ind_order, myimbarco.username, myimbarco.num_tess);
|
|
||||||
}
|
|
||||||
dashboard.navi_partenza = await NavePersistente.getListaNavi(idapp);
|
|
||||||
|
|
||||||
dashboard.lastnave = await NavePersistente.getLastNave(idapp);
|
|
||||||
|
|
||||||
for (let mypos of dashboard.arrposizioni) {
|
|
||||||
mypos.rec = await Nave.getNaveByRigaCol(idapp, mypos.riga, mypos.col);
|
|
||||||
mypos.nave_partenza = await NavePersistente.findByRigaColByDonatore(idapp,
|
|
||||||
mypos.riga, mypos.col, 0);
|
|
||||||
if (!!mypos.nave_partenza)
|
|
||||||
mypos.flotta = await Flotta.getFlottaByNavePersistente(idapp,
|
|
||||||
mypos.nave_partenza);
|
|
||||||
}
|
|
||||||
|
|
||||||
//for (let indriga = 0; indriga < 10; indriga++) {
|
|
||||||
// dashboard.navi_partenza.push(await Nave.getPrimaNaveByRiga(idapp, indriga));
|
|
||||||
//}
|
|
||||||
|
|
||||||
const arrnew = [];
|
|
||||||
|
|
||||||
try {
|
|
||||||
for (let mypos of dashboard.arrposizioni) {
|
|
||||||
// Controlla se è presente la Nave con il num_tess pari
|
|
||||||
|
|
||||||
let trovato = false;
|
|
||||||
|
|
||||||
if (mypos.num_tess % 2 !== 0) {
|
|
||||||
for (let myrec of dashboard.arrposizioni) {
|
|
||||||
if (myrec.num_tess === mypos.num_tess + 1 &&
|
|
||||||
(myrec.ind_order === mypos.ind_order)) {
|
|
||||||
// La Nave di Ritorno (numtess = 2) esiste nella lista !
|
|
||||||
trovato = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
trovato = true;
|
|
||||||
}
|
|
||||||
if (!trovato) {
|
|
||||||
let myr = null;
|
|
||||||
if (!!mypos._doc)
|
|
||||||
myr = mypos._doc;
|
|
||||||
else
|
|
||||||
myr = mypos;
|
|
||||||
|
|
||||||
if (!!myr && !!myr.rec.mediatore) {
|
|
||||||
const mymediatore = myr.rec.mediatore.arrdonatori[7];
|
|
||||||
if (!!mymediatore) {
|
|
||||||
const myrec = {
|
|
||||||
riga: mymediatore.riga,
|
|
||||||
col: mymediatore.col,
|
|
||||||
name: myr.rec.mediatore.recmediatore.name,
|
|
||||||
surname: myr.rec.mediatore.recmediatore.surname,
|
|
||||||
username: myr.rec.mediatore.recmediatore.username,
|
|
||||||
num_tess: myr.rec.mediatore.recmediatore.num_tess + 1,
|
|
||||||
rec: await Nave.getNaveByRigaCol(idapp, mymediatore.riga,
|
|
||||||
mymediatore.col),
|
|
||||||
nave_partenza: {},
|
|
||||||
};
|
|
||||||
|
|
||||||
myrec.nave_partenza = await NavePersistente.findByRigaColByDonatore(
|
|
||||||
idapp, myrec.riga, myrec.col, 0);
|
|
||||||
|
|
||||||
arrnew.push(myrec);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
dashboard.arrposizioni = [...dashboard.arrposizioni, ...arrnew];
|
|
||||||
|
|
||||||
// console.table(dashboard.arrnavi);
|
// console.table(dashboard.arrnavi);
|
||||||
|
|
||||||
return dashboard;
|
return dashboard;
|
||||||
@@ -2377,131 +2349,6 @@ UserSchema.statics.getUsersQualified = async function (idapp, numinvitati) {
|
|||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
UserSchema.statics.visuUtentiNonInNavi = async function(idapp) {
|
|
||||||
const User = this;
|
|
||||||
|
|
||||||
const arrusers = await User.find({
|
|
||||||
idapp,
|
|
||||||
$and: User.getQueryQualified(),
|
|
||||||
}, {
|
|
||||||
name: 1,
|
|
||||||
surname: 1,
|
|
||||||
username: 1,
|
|
||||||
ind_order: 1,
|
|
||||||
deleted: 1,
|
|
||||||
sospeso: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
let num = 0;
|
|
||||||
let innave = 0;
|
|
||||||
let noninnave = 0;
|
|
||||||
let mystr = 'visuUtentiNonInNavi: ' + tools.ACAPO;
|
|
||||||
let reg = 0;
|
|
||||||
let num0inv = 0;
|
|
||||||
let num1inv = 0;
|
|
||||||
let num2inv = 0;
|
|
||||||
let numnoinlista = 0;
|
|
||||||
let numeliminati = 0;
|
|
||||||
let numsospesi = 0;
|
|
||||||
let strnavidoppie = '';
|
|
||||||
let esiste = false;
|
|
||||||
|
|
||||||
for (const user of arrusers) {
|
|
||||||
esiste = true;
|
|
||||||
if (!!user.deleted) {
|
|
||||||
if (user.deleted) {
|
|
||||||
numeliminati++;
|
|
||||||
esiste = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (esiste) {
|
|
||||||
|
|
||||||
let visualizza = false;
|
|
||||||
|
|
||||||
// Controlla se ho un doppione nelle Navi !
|
|
||||||
let mienavi = await Nave.find({idapp, ind_order: user.ind_order},
|
|
||||||
{num_tess: 1});
|
|
||||||
|
|
||||||
let strnavidoppie = [];
|
|
||||||
if (!!mienavi) {
|
|
||||||
strnavidoppie = mienavi.reduce((acc, currentValue, index, array) => {
|
|
||||||
if (array.indexOf(currentValue.num_tess) > -1 &&
|
|
||||||
!acc.includes(currentValue.num_tess))
|
|
||||||
acc.push(currentValue.num_tess);
|
|
||||||
return acc;
|
|
||||||
}, []);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strnavidoppie.length > 1) {
|
|
||||||
visualizza = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
user.numinvitati = await ListaIngresso.getnumInvitati(idapp,
|
|
||||||
user.username);
|
|
||||||
reg++;
|
|
||||||
let mianave = await Nave.findOne({idapp, ind_order: user.ind_order});
|
|
||||||
let mialistaingresso = await ListaIngresso.findOne(
|
|
||||||
{idapp, ind_order: user.ind_order});
|
|
||||||
let trovato = false;
|
|
||||||
|
|
||||||
if (!mianave)
|
|
||||||
visualizza = true;
|
|
||||||
|
|
||||||
if (visualizza) {
|
|
||||||
mystr += user.username + ' ' + user.name + ' ' + user.surname + ' [' +
|
|
||||||
user.index + '] [inv=' + user.numinvitati + ']';
|
|
||||||
trovato = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strnavidoppie.length > 1) {
|
|
||||||
mystr += ' NAVI DUPLICATE! ' + strnavidoppie.join(',');
|
|
||||||
}
|
|
||||||
if (!mianave)
|
|
||||||
noninnave++;
|
|
||||||
else
|
|
||||||
innave++;
|
|
||||||
|
|
||||||
if (user.sospeso) {
|
|
||||||
numsospesi++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mialistaingresso) {
|
|
||||||
mystr += ' NO IN LISTA INGRESSO!';
|
|
||||||
trovato = true;
|
|
||||||
numnoinlista++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (trovato)
|
|
||||||
mystr += tools.ACAPO;
|
|
||||||
|
|
||||||
if (user.numinvitati === 0) {
|
|
||||||
num0inv++;
|
|
||||||
}
|
|
||||||
if (user.numinvitati === 1) {
|
|
||||||
num1inv++;
|
|
||||||
}
|
|
||||||
if (user.numinvitati >= 2) {
|
|
||||||
num2inv++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mystrstart = 'Registrati: ' + reg + tools.ACAPO;
|
|
||||||
mystrstart += '0 Invitati: ' + num0inv + tools.ACAPO;
|
|
||||||
mystrstart += '1 Invitato: ' + num1inv + tools.ACAPO;
|
|
||||||
mystrstart += '2 o più Invitati: ' + num2inv + tools.ACAPO;
|
|
||||||
mystrstart += 'Presente in Nave: ' + innave + tools.ACAPO;
|
|
||||||
mystrstart += 'Non in Nave: ' + noninnave + tools.ACAPO;
|
|
||||||
mystrstart += 'Non in Lista Imbarco: ' + numnoinlista + tools.ACAPO;
|
|
||||||
mystrstart += 'Usciti (Nascosti): ' + numeliminati + tools.ACAPO;
|
|
||||||
mystrstart += 'Sospesi: ' + numsospesi + tools.ACAPO;
|
|
||||||
|
|
||||||
mystrstart += tools.ACAPO;
|
|
||||||
|
|
||||||
mystr = mystrstart + mystr;
|
|
||||||
|
|
||||||
return {num, mystr};
|
|
||||||
};
|
|
||||||
|
|
||||||
// UserSchema.statics.getNumUsersQualified = async function (idapp, numinvitati) {
|
// UserSchema.statics.getNumUsersQualified = async function (idapp, numinvitati) {
|
||||||
//
|
//
|
||||||
@@ -2639,12 +2486,15 @@ UserSchema.statics.checkUser = async function(idapp, username) {
|
|||||||
UserSchema.statics.calculateStat = async function(idapp, username) {
|
UserSchema.statics.calculateStat = async function(idapp, username) {
|
||||||
const User = this;
|
const User = this;
|
||||||
|
|
||||||
|
/*
|
||||||
return calcstat = {
|
return calcstat = {
|
||||||
numinvitati: await ListaIngresso.getnumInvitati(idapp, username),
|
numinvitati: await ListaIngresso.getnumInvitati(idapp, username),
|
||||||
numinvitati_attivi: await ListaIngresso.getnumInvitatiAttivi(idapp,
|
numinvitati_attivi: await ListaIngresso.getnumInvitatiAttivi(idapp,
|
||||||
username),
|
username),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
UserSchema.statics.getDistinctNationalityQuery = function(idapp) {
|
UserSchema.statics.getDistinctNationalityQuery = function(idapp) {
|
||||||
@@ -2804,44 +2654,6 @@ if (tools.INITDB_FIRSTIME) {
|
|||||||
// UserSchema.index({ surname: 1 });
|
// UserSchema.index({ surname: 1 });
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addUtentiInLista(idapp, mode, arrusers) {
|
|
||||||
|
|
||||||
let num = 0;
|
|
||||||
for (const rec of arrusers) {
|
|
||||||
let ok = false;
|
|
||||||
let qualified = await User.isUserQualified7(idapp, rec.username);
|
|
||||||
let numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(idapp,
|
|
||||||
rec.username);
|
|
||||||
let numinvitati = await ListaIngresso.getnumInvitati(idapp, rec.username);
|
|
||||||
|
|
||||||
if (rec.profile.special_req) {
|
|
||||||
numinvitatiattivi = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode === 1) {
|
|
||||||
// 9 punti qualificati
|
|
||||||
ok = qualified && (numinvitatiattivi >= 2);
|
|
||||||
} else if (mode === 2) {
|
|
||||||
// 8 punti qualificati ( 1 Invitato)
|
|
||||||
ok = qualified && (numinvitati === 2);
|
|
||||||
} else if (mode === 3) {
|
|
||||||
ok = qualified && (numinvitatiattivi === 1);
|
|
||||||
} else if (mode === 4) {
|
|
||||||
ok = qualified && (numinvitati === 1);
|
|
||||||
} else if (mode === 5) {
|
|
||||||
ok = qualified;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ok) {
|
|
||||||
ris = await ListaIngresso.addUserInListaIngresso(idapp, rec.username,
|
|
||||||
rec.aportador_solidario, rec.lang, false, true);
|
|
||||||
if (!!ris)
|
|
||||||
num++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return num;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
UserSchema.statics.getUsernameByIndOrder = async function(idapp, ind_order) {
|
UserSchema.statics.getUsernameByIndOrder = async function(idapp, ind_order) {
|
||||||
|
|
||||||
@@ -2886,85 +2698,11 @@ UserSchema.statics.ricalcolaIndex = async function(idapp) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
UserSchema.statics.changeInvitante = async function(
|
|
||||||
idapp, username, invitante_username, ind_order_ingr) {
|
|
||||||
const User = this;
|
|
||||||
|
|
||||||
const rec_ind_order_prima = await ListaIngresso.findOne({idapp, username});
|
|
||||||
|
|
||||||
let modif_aportador = false;
|
|
||||||
// cambia aportador_solidario solo se è la prima nave!
|
|
||||||
|
|
||||||
// Oppure se ancora non sono in Lista!
|
|
||||||
if (!rec_ind_order_prima) {
|
|
||||||
modif_aportador = true;
|
|
||||||
} else {
|
|
||||||
if (rec_ind_order_prima.ind_order === ind_order_ingr) {
|
|
||||||
modif_aportador = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (modif_aportador) {
|
|
||||||
await User.findOneAndUpdate({idapp, username},
|
|
||||||
{$set: {aportador_solidario: invitante_username}});
|
|
||||||
}
|
|
||||||
|
|
||||||
// **
|
|
||||||
// ** Cambia invitante_username e ind_order di LISTAINGRESSO
|
|
||||||
// **
|
|
||||||
const rec_ingr = await ListaIngresso.findOne({idapp, username: username});
|
|
||||||
if (!!rec_ingr) {
|
|
||||||
// await ListaIngresso.findByIdAndUpdate(rec_ingr._id, { $set: { invitante_username, ind_order: ind_order_ingr } });
|
|
||||||
await ListaIngresso.findByIdAndUpdate(rec_ingr._id,
|
|
||||||
{$set: {invitante_username}});
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
UserSchema.statics.NessunaNavePresenteByUsername = async function(
|
|
||||||
idapp, username) {
|
|
||||||
const User = this;
|
|
||||||
|
|
||||||
const rec = await User.findOne({idapp, username},
|
|
||||||
{username: 1, ind_order: 1});
|
|
||||||
if (!!rec) {
|
|
||||||
// Controlla se è qualificato!
|
|
||||||
const qualified = await User.isUserQualified7(idapp, rec.username);
|
|
||||||
if (qualified) {
|
|
||||||
|
|
||||||
// Ha un'imbarco almeno?
|
|
||||||
const arrimbarchi = await ListaIngresso.findOne({
|
|
||||||
idapp, username: rec.username,
|
|
||||||
$or: [
|
|
||||||
{deleted: {$exists: false}},
|
|
||||||
{deleted: {$exists: true, $eq: false}}],
|
|
||||||
});
|
|
||||||
|
|
||||||
const arrnavi = await Nave.findOne({
|
|
||||||
idapp, ind_order: rec.old_order,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!arrimbarchi && !arrnavi) {
|
|
||||||
// NEANCHE 1 !
|
|
||||||
const recout = await User.findOneAndUpdate({
|
|
||||||
idapp,
|
|
||||||
username,
|
|
||||||
}, {$set: {navinonpresenti: true}}, {new: false});
|
|
||||||
|
|
||||||
return (!!recout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
UserSchema.statics.getInfoUser = async function(idapp, username) {
|
UserSchema.statics.getInfoUser = async function(idapp, username) {
|
||||||
return {
|
return {
|
||||||
username,
|
username,
|
||||||
is7req: await User.isUserQualified7(idapp, username),
|
is7req: await User.isUserQualified7(idapp, username),
|
||||||
is9req: await User.isUserQualified9(idapp, username),
|
// is9req: await User.isUserQualified9(idapp, username),
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -2978,37 +2716,15 @@ UserSchema.statics.checkIfSbloccatiRequisiti = async function(
|
|||||||
if (!allData.myuser)
|
if (!allData.myuser)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (await Nave.checkIfNaveExist(idapp, allData.myuser.username)) {
|
//if (await Nave.checkIfNaveExist(idapp, allData.myuser.username)) {
|
||||||
// Se già sei dentro la Nave, allora sei OK
|
// // Se già sei dentro la Nave, allora sei OK
|
||||||
return true; //TOGLEREE
|
// return true; //TOGLEREE
|
||||||
}
|
//}
|
||||||
|
|
||||||
// Controlla se Sblocca i 7 requisiti
|
// Controlla se Sblocca i 7 requisiti
|
||||||
const is7req = await User.isUserQualified7(idapp, allData.myuser.username);
|
const is7req = await User.isUserQualified7(idapp, allData.myuser.username);
|
||||||
const is9req = await User.isUserQualified9(idapp, allData.myuser.username);
|
const is9req = false;
|
||||||
|
// const is9req = await User.isUserQualified9(idapp, allData.myuser.username);
|
||||||
const userlista = await ListaIngresso.getListaTessByUsername(idapp,
|
|
||||||
allData.myuser.username);
|
|
||||||
//if (userlista.length > 0) { //TOGLIERE
|
|
||||||
if (userlista.length === 0) {
|
|
||||||
// Se non sono ancora dentro alla lista, allora controllo
|
|
||||||
|
|
||||||
if (!!allData.precDataUser) {
|
|
||||||
if ((!allData.precDataUser.is7req && is7req) &&
|
|
||||||
!await User.isUserAlreadyQualified(idapp, allData.myuser.username)) {
|
|
||||||
|
|
||||||
await User.setUserQualified(idapp, allData.myuser.username);
|
|
||||||
// ORA HAI I 7 REQUISITI !
|
|
||||||
// const msgtext = telegrambot.getCiao(idapp, allData.myuser.username, allData.myuser.lang) + tools.gettranslate('HAI_I_7_REQUISITI', allData.myuser.lang);
|
|
||||||
// telegrambot.sendMsgTelegram(idapp, allData.myuser.username, msgtext, true); // Anche a STAFF
|
|
||||||
|
|
||||||
// Aggiungilo alla ListaIngresso
|
|
||||||
risingr = await ListaIngresso.addUserInListaIngresso(idapp,
|
|
||||||
allData.myuser.username, allData.myuser.aportador_iniziale,
|
|
||||||
allData.myuser.lang, true, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!!allData.precDataUser) {
|
if (!!allData.precDataUser) {
|
||||||
if ((!allData.precDataUser.is9req && is9req) &&
|
if ((!allData.precDataUser.is9req && is9req) &&
|
||||||
@@ -3107,57 +2823,6 @@ UserSchema.statics.mettiSognoePaypal = async function(idapp, modifica) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
UserSchema.statics.flagUtentiNaviNonPresenti = async function(idapp) {
|
|
||||||
const User = this;
|
|
||||||
|
|
||||||
let num = 0;
|
|
||||||
|
|
||||||
await User.updateMany({idapp}, {$set: {navinonpresenti: false}});
|
|
||||||
|
|
||||||
arrusers = await User.find({
|
|
||||||
'idapp': idapp,
|
|
||||||
$or: [
|
|
||||||
{deleted: {$exists: false}},
|
|
||||||
{deleted: {$exists: true, $eq: false}},
|
|
||||||
{subaccount: {$exists: false}},
|
|
||||||
{subaccount: {$exists: true, $eq: false}}],
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const rec of arrusers) {
|
|
||||||
|
|
||||||
const nessunanave = await User.NessunaNavePresenteByUsername(idapp,
|
|
||||||
rec.username);
|
|
||||||
if (nessunanave)
|
|
||||||
num++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {num};
|
|
||||||
};
|
|
||||||
|
|
||||||
UserSchema.statics.addNavePerUtentiNaviNonPresenti = async function(idapp) {
|
|
||||||
const User = this;
|
|
||||||
|
|
||||||
let num = 0;
|
|
||||||
|
|
||||||
arrusers = await User.find({
|
|
||||||
'idapp': idapp,
|
|
||||||
navinonpresenti: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const user of arrusers) {
|
|
||||||
// Controlla se è qualificato!
|
|
||||||
mydata = tools.AddDate(user.date_reg, 7);
|
|
||||||
|
|
||||||
const newrecingr = await ListaIngresso.addUserInListaIngresso(idapp,
|
|
||||||
user.username, user.aportador_solidario, user.lang, true, true, mydata);
|
|
||||||
await tools.snooze(1000);
|
|
||||||
|
|
||||||
num++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {num};
|
|
||||||
};
|
|
||||||
|
|
||||||
UserSchema.statics.convSubAccount = async function(idapp) {
|
UserSchema.statics.convSubAccount = async function(idapp) {
|
||||||
const User = this;
|
const User = this;
|
||||||
|
|
||||||
@@ -3269,6 +2934,18 @@ UserSchema.statics.addExtraInfo = async function(idapp, recUser) {
|
|||||||
}, {username: 1});
|
}, {username: 1});
|
||||||
|
|
||||||
recUser._doc.profile.asked_friends = listSentMyRequestFriends ? listSentMyRequestFriends : [];
|
recUser._doc.profile.asked_friends = listSentMyRequestFriends ? listSentMyRequestFriends : [];
|
||||||
|
|
||||||
|
const listSentMyRequestGroups = await User.find({
|
||||||
|
idapp,
|
||||||
|
'profile.req_groups': {
|
||||||
|
$elemMatch: {username: {$eq: recUser.username}},
|
||||||
|
},
|
||||||
|
$or: [
|
||||||
|
{deleted: {$exists: false}},
|
||||||
|
{deleted: {$exists: true, $eq: false}}],
|
||||||
|
}, {username: 1});
|
||||||
|
|
||||||
|
recUser._doc.profile.asked_groups = listSentMyRequestGroups ? listSentMyRequestGroups : [];
|
||||||
}catch (e){
|
}catch (e){
|
||||||
console.error('Err', e);
|
console.error('Err', e);
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/server/populate/levels.js
Normal file
10
src/server/populate/levels.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
module.exports = {
|
||||||
|
list: [
|
||||||
|
{_id: 0, descr: '[Nessuno]', years_of_exp: 0},
|
||||||
|
{_id: 1, descr: 'Principiante', years_of_exp: 1},
|
||||||
|
{_id: 2, descr: 'Intermedio', years_of_exp: 3},
|
||||||
|
{_id: 3, descr: 'Avanzato', years_of_exp: 5},
|
||||||
|
{_id: 4, descr: 'Esperto', years_of_exp: 10},
|
||||||
|
{_id: 5, descr: 'Veterano', years_of_exp: 20},
|
||||||
|
],
|
||||||
|
};
|
||||||
@@ -25,7 +25,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
popolaTabelleNuove() {
|
popolaTabelleNuove() {
|
||||||
const abilita = true;
|
const abilita = false;
|
||||||
const scrivi_citta = false;
|
const scrivi_citta = false;
|
||||||
|
|
||||||
let ris = null;
|
let ris = null;
|
||||||
@@ -42,6 +42,14 @@ module.exports = {
|
|||||||
const { SubSkill } = require('../models/subskill');
|
const { SubSkill } = require('../models/subskill');
|
||||||
this.insertIntoDb('subskills', SubSkill)
|
this.insertIntoDb('subskills', SubSkill)
|
||||||
|
|
||||||
|
// Levels
|
||||||
|
const { Level } = require('../models/level');
|
||||||
|
this.insertIntoDb('levels', Level)
|
||||||
|
|
||||||
|
// Status
|
||||||
|
const { StatusSkill } = require('../models/statusSkill');
|
||||||
|
this.insertIntoDb('statusskills', StatusSkill)
|
||||||
|
|
||||||
if (scrivi_citta) {
|
if (scrivi_citta) {
|
||||||
// Cities
|
// Cities
|
||||||
const {City} = require('../models/city');
|
const {City} = require('../models/city');
|
||||||
|
|||||||
6
src/server/populate/statusskills.js
Normal file
6
src/server/populate/statusskills.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
module.exports = {
|
||||||
|
list: [
|
||||||
|
{_id: 1, descr: 'Di Persona'},
|
||||||
|
{_id: 2, descr: 'On Line'},
|
||||||
|
],
|
||||||
|
};
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
const mongoose = require('mongoose').set('debug', false)
|
const mongoose = require('mongoose').set('debug', false)
|
||||||
const Subscription = mongoose.model('subscribers');
|
const Subscription = mongoose.model('subscribers');
|
||||||
|
|
||||||
const { ListaIngresso } = require('../../models/listaingresso');
|
//const { ListaIngresso } = require('../../models/listaingresso');
|
||||||
const { Graduatoria } = require('../../models/graduatoria');
|
const { Graduatoria } = require('../../models/graduatoria');
|
||||||
const { User } = require('../../models/user');
|
const { User } = require('../../models/user');
|
||||||
const { Nave } = require('../../models/nave');
|
|
||||||
|
|
||||||
const { ObjectID } = require('mongodb');
|
const { ObjectID } = require('mongodb');
|
||||||
|
|
||||||
@@ -20,11 +19,11 @@ module.exports = {
|
|||||||
|
|
||||||
let ris = null;
|
let ris = null;
|
||||||
|
|
||||||
const { ListaIngresso } = require('../../models/listaingresso');
|
// const { ListaIngresso } = require('../../models/listaingresso');
|
||||||
|
|
||||||
if (tablename === 'users') {
|
if (tablename === 'users') {
|
||||||
|
|
||||||
await ListaIngresso.deleteUserInListaIngresso(rec.idapp, rec.username);
|
// await ListaIngresso.deleteUserInListaIngresso(rec.idapp, rec.username);
|
||||||
|
|
||||||
// Controlla se aveva invitati, li regala a quello sopra
|
// Controlla se aveva invitati, li regala a quello sopra
|
||||||
const arrap = await User.getDownlineByUsername(rec.idapp, rec.username);
|
const arrap = await User.getDownlineByUsername(rec.idapp, rec.username);
|
||||||
@@ -43,28 +42,6 @@ module.exports = {
|
|||||||
ris = Subscription.deleteOne({ userId: rec._id })
|
ris = Subscription.deleteOne({ userId: rec._id })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tablename === 'listaingressos') {
|
|
||||||
// Rimuovi anche nella Tabella Graduatoria
|
|
||||||
ris = await Graduatoria.deleteOne({ idListaIngresso: ObjectID(rec._id) });
|
|
||||||
if (!!ris) {
|
|
||||||
|
|
||||||
let msg = 'Eliminato dalla Graduatoria di ' + rec.name + ' ' + rec.surname + ' (ind_order=' + rec.ind_order + ', num_tess=' + rec.num_tess + ') [Num = ' + rec.index + `] (da ${req.user.name} ${req.user.surname} )` ;
|
|
||||||
await telegrambot.sendMsgTelegramToTheManagers(rec.idapp, msg);
|
|
||||||
tools.writeSostituzioniLog(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Elimina anche la Nave se è temporanea!
|
|
||||||
const arrnave = await Nave.find({ idapp: rec.idapp, ind_order: rec.ind_order, num_tess: rec.num_tess });
|
|
||||||
for (const mynave of arrnave) {
|
|
||||||
if (!!mynave) {
|
|
||||||
if (!await Nave.isDefinitiva(rec.idapp, mynave)) {
|
|
||||||
await Nave.findByIdAndUpdate(mynave.id, { $set: { ind_order: -1 } });
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!!ris) {
|
if (!!ris) {
|
||||||
|
|
||||||
if (notifBot) {
|
if (notifBot) {
|
||||||
|
|||||||
@@ -9,9 +9,6 @@ const { authenticate } = require('../middleware/authenticate');
|
|||||||
|
|
||||||
const { User } = require('../models/user');
|
const { User } = require('../models/user');
|
||||||
|
|
||||||
const { Nave } = require('../models/nave');
|
|
||||||
const { Flotta } = require('../models/flotta');
|
|
||||||
const { NavePersistente } = require('../models/navepersistente');
|
|
||||||
const { MsgTemplate } = require('../models/msg_template');
|
const { MsgTemplate } = require('../models/msg_template');
|
||||||
|
|
||||||
const mongoose = require('mongoose').set('debug', false)
|
const mongoose = require('mongoose').set('debug', false)
|
||||||
@@ -137,76 +134,6 @@ router.post('/msgflotta', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('/getnave', authenticate, async (req, res) => {
|
|
||||||
const idapp = req.body.idapp;
|
|
||||||
const riga = req.body.riga;
|
|
||||||
const col = req.body.col;
|
|
||||||
const riga1don = req.body.riga1don;
|
|
||||||
const col1don = req.body.col1don;
|
|
||||||
const ind_order = req.body.ind_order;
|
|
||||||
|
|
||||||
const nave = await NavePersistente.findByRigaCol(idapp, riga, col);
|
|
||||||
if (!!nave) {
|
|
||||||
nave._doc.rec = await Nave.getNaveByRigaCol(idapp, riga1don, col1don);
|
|
||||||
if (ind_order >= 0)
|
|
||||||
nave._doc.ind_order = ind_order;
|
|
||||||
|
|
||||||
nave._doc.listadonatoridelsognatore = await Nave.getDonatoridelSognatore(idapp, riga1don, col1don);
|
|
||||||
}
|
|
||||||
|
|
||||||
const navi_partenza = await NavePersistente.findAllIdApp(idapp);
|
|
||||||
|
|
||||||
ris = { nave, navi_partenza };
|
|
||||||
|
|
||||||
if (ris)
|
|
||||||
res.send({ code: server_constants.RIS_CODE_OK, ris });
|
|
||||||
else
|
|
||||||
res.status(400).send(e);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
router.post('/getnavi', authenticate, async (req, res) => {
|
|
||||||
const idapp = req.body.idapp;
|
|
||||||
|
|
||||||
const { Flotta } = require('../models/flotta');
|
|
||||||
|
|
||||||
|
|
||||||
let arrnavi = await NavePersistente.findAllIdApp(idapp);
|
|
||||||
|
|
||||||
// let arrnavi = await NavePersistente.find({idapp, date_gift_chat_open: { $gte: tools.IncDateNow(-1000 * 3600 * 24 * 7 ) } }).sort({ riga: 1, col: 1 });
|
|
||||||
|
|
||||||
for (nave of arrnavi) {
|
|
||||||
//nave.rec = await Nave.getNaveByRigaCol(idapp, nave.riga, nave.col);
|
|
||||||
nave._doc.rec = {
|
|
||||||
donatore: {},
|
|
||||||
mediatore: null
|
|
||||||
};
|
|
||||||
|
|
||||||
let riganave = nave.riga;
|
|
||||||
let colnave = nave.col;
|
|
||||||
// if (riganave < 4) {
|
|
||||||
// riganave = 4;
|
|
||||||
// colnave = 1;
|
|
||||||
// }
|
|
||||||
// nave._doc.rec.donatore.navepersistente = await NavePersistente.findByRigaColByDonatore(idapp, riganave, colnave, 0);
|
|
||||||
nave._doc.rec.donatore.navepersistente = await NavePersistente.findOne({ idapp, riga: riganave, col: colnave });
|
|
||||||
if (!!nave._doc.rec) {
|
|
||||||
if (!!nave._doc.rec.donatore.navepersistente)
|
|
||||||
nave._doc.rec.donatore.flotta = await Flotta.getFlottaByNavePersistente(idapp, nave._doc.rec.donatore.navepersistente);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const navi_partenza = await NavePersistente.findAllIdApp(idapp);
|
|
||||||
|
|
||||||
ris = { arrnavi, navi_partenza };
|
|
||||||
|
|
||||||
if (ris)
|
|
||||||
res.send({ code: server_constants.RIS_CODE_OK, ris });
|
|
||||||
else
|
|
||||||
res.status(400).send(e);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
router.post('/getmsg_templates', authenticate, async (req, res) => {
|
router.post('/getmsg_templates', authenticate, async (req, res) => {
|
||||||
const idapp = req.body.idapp;
|
const idapp = req.body.idapp;
|
||||||
|
|
||||||
@@ -232,84 +159,6 @@ router.post('/getflotte', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('/getflotta', authenticate, async (req, res) => {
|
|
||||||
const idapp = req.body.idapp;
|
|
||||||
const riga = req.body.riga;
|
|
||||||
const col_prima = req.body.col_prima;
|
|
||||||
const col_ultima = req.body.col_ultima;
|
|
||||||
|
|
||||||
// const ris2 = await NavePersistente.aggiornaFlottaByNavePersistente(idapp, {riga, col1don: col_prima });
|
|
||||||
|
|
||||||
let ris = await Nave.getFlotta(idapp, riga, col_prima, col_ultima);
|
|
||||||
|
|
||||||
ris.flotta._doc.log_attivita = tools.readFlottaLog(idapp, ris.flotta.riga, ris.flotta.col_prima);
|
|
||||||
|
|
||||||
if (!!ris)
|
|
||||||
res.send({ code: server_constants.RIS_CODE_OK, flotta: ris.flotta, arrdonatori: ris.arrdonatori, arrmediatori: ris.arrmediatori });
|
|
||||||
else
|
|
||||||
res.status(400).send(e);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
router.post('/getdoninavi', authenticate, async (req, res) => {
|
|
||||||
const idapp = req.body.idapp;
|
|
||||||
const ricalcola = req.body.ricalcola;
|
|
||||||
const showall = req.body.showall;
|
|
||||||
|
|
||||||
let arrnavi = null;
|
|
||||||
if (showall)
|
|
||||||
arrnavi = await NavePersistente.findAllIdApp(idapp);
|
|
||||||
else
|
|
||||||
arrnavi = await NavePersistente.find({idapp, date_gift_chat_open: { $gte: tools.IncDateNow(-1000 * 3600 * 24 * 10 ) } }).sort({ riga: 1, col: 1 });
|
|
||||||
|
|
||||||
let test = false;
|
|
||||||
|
|
||||||
//arrnavi.push({ riga: indriga, col: indcol, rigadon: indriga + 3, coldon: (indcol * 8) - 7 });
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (ricalcola) {
|
|
||||||
let index = 1;
|
|
||||||
|
|
||||||
for (nave of arrnavi) {
|
|
||||||
nave = await Nave.ricalcolaNave(idapp, nave, 0, 0, ricalcola, index);
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// arrnavi = await NavePersistente.findAllIdApp(idapp);
|
|
||||||
let index = 1;
|
|
||||||
for (nave of arrnavi) {
|
|
||||||
if (nave.provvisoria || nave.DoniTotali !== nave.DoniConfermati) {
|
|
||||||
nave._doc.rec = await Nave.getNaveByRigaCol(idapp, nave.riga1don, nave.col1don);
|
|
||||||
} else {
|
|
||||||
let rigapos = nave.riga1don;
|
|
||||||
let colpos = nave.col1don;
|
|
||||||
if (rigapos < 4) {
|
|
||||||
rigapos = 4;
|
|
||||||
colpos = 1;
|
|
||||||
}
|
|
||||||
nave._doc.rec = {};
|
|
||||||
nave._doc.rec.donatore = {};
|
|
||||||
nave._doc.rec.donatore.navepersistente = await NavePersistente.findByRigaColByDonatore(idapp, rigapos, colpos, tools.Placca.SONOFUOCO);
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
if (index > 8 * 6 ) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ris = { arrnavi };
|
|
||||||
|
|
||||||
if (ris)
|
|
||||||
res.send({ code: server_constants.RIS_CODE_OK, ris });
|
|
||||||
else
|
|
||||||
res.status(400).send(e);
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
router.post('/getdata', authenticate, async (req, res) => {
|
router.post('/getdata', authenticate, async (req, res) => {
|
||||||
const idapp = req.body.idapp;
|
const idapp = req.body.idapp;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const {authenticate, authenticate_noerror} = require(
|
|||||||
'../middleware/authenticate');
|
'../middleware/authenticate');
|
||||||
|
|
||||||
const {ObjectID} = require('mongodb');
|
const {ObjectID} = require('mongodb');
|
||||||
const {ListaIngresso} = require('../models/listaingresso');
|
// const {ListaIngresso} = require('../models/listaingresso');
|
||||||
const {Graduatoria} = require('../models/graduatoria');
|
const {Graduatoria} = require('../models/graduatoria');
|
||||||
|
|
||||||
const mongoose = require('mongoose').set('debug', false);
|
const mongoose = require('mongoose').set('debug', false);
|
||||||
@@ -34,9 +34,7 @@ if (!fs.existsSync(folder)) {
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
const {User} = require('../models/user');
|
const {User} = require('../models/user');
|
||||||
const {Nave} = require('../models/nave');
|
const {MyGroup} = require('../models/mygroup');
|
||||||
const {Flotta} = require('../models/flotta');
|
|
||||||
const {NavePersistente} = require('../models/navepersistente');
|
|
||||||
// const { ExtraList } = require('../models/extralist');
|
// const { ExtraList } = require('../models/extralist');
|
||||||
const {Booking} = require('../models/booking');
|
const {Booking} = require('../models/booking');
|
||||||
const {Operator} = require('../models/operator');
|
const {Operator} = require('../models/operator');
|
||||||
@@ -103,7 +101,6 @@ const UserCost = {
|
|||||||
'profile.paymenttypes'],
|
'profile.paymenttypes'],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
router.post(process.env.LINKVERIF_REG, (req, res) => {
|
router.post(process.env.LINKVERIF_REG, (req, res) => {
|
||||||
const body = _.pick(req.body, ['idapp', 'idlink']);
|
const body = _.pick(req.body, ['idapp', 'idlink']);
|
||||||
const idapp = body.idapp;
|
const idapp = body.idapp;
|
||||||
@@ -222,6 +219,8 @@ function getTableByTableName(tablename) {
|
|||||||
let mytable = '';
|
let mytable = '';
|
||||||
if (tablename === 'users')
|
if (tablename === 'users')
|
||||||
mytable = User;
|
mytable = User;
|
||||||
|
else if (tablename === 'mygroups')
|
||||||
|
mytable = MyGroup;
|
||||||
else if (tablename === 'tessitura')
|
else if (tablename === 'tessitura')
|
||||||
mytable = Tessitura;
|
mytable = Tessitura;
|
||||||
// else if (tablename === 'extralist')
|
// else if (tablename === 'extralist')
|
||||||
@@ -294,16 +293,12 @@ function getTableByTableName(tablename) {
|
|||||||
mytable = Permission;
|
mytable = Permission;
|
||||||
else if (tablename === 'mailinglist')
|
else if (tablename === 'mailinglist')
|
||||||
mytable = MailingList;
|
mytable = MailingList;
|
||||||
else if (tablename === 'navi')
|
|
||||||
mytable = Nave;
|
|
||||||
else if (tablename === 'flotte')
|
|
||||||
mytable = Flotta;
|
|
||||||
else if (tablename === 'msg_templates')
|
else if (tablename === 'msg_templates')
|
||||||
mytable = MsgTemplate;
|
mytable = MsgTemplate;
|
||||||
else if (tablename === 'navepersistente')
|
else if (tablename === 'navepersistente')
|
||||||
mytable = NavePersistente;
|
mytable = NavePersistente;
|
||||||
else if (tablename === 'listaingressos')
|
// else if (tablename === 'listaingressos')
|
||||||
mytable = ListaIngresso;
|
// mytable = ListaIngresso;
|
||||||
else if (tablename === 'graduatorias')
|
else if (tablename === 'graduatorias')
|
||||||
mytable = Graduatoria;
|
mytable = Graduatoria;
|
||||||
else if (tablename === 'skills')
|
else if (tablename === 'skills')
|
||||||
@@ -365,6 +360,23 @@ router.post('/settable', authenticate, (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shared_consts.TABLES_USER_INCLUDE_MY.includes(params.table)) {
|
||||||
|
if (!mydata.admins) {
|
||||||
|
mydata.admins = [];
|
||||||
|
} else {
|
||||||
|
const arrnew = [];
|
||||||
|
for (const username of mydata.admins) {
|
||||||
|
arrnew.push({username});
|
||||||
|
}
|
||||||
|
mydata.admins = arrnew;
|
||||||
|
}
|
||||||
|
const indfind = mydata.admins.findIndex((rec) => (rec.username === req.user.username));
|
||||||
|
|
||||||
|
if (indfind < 0) {
|
||||||
|
mydata.admins.push({_id: new ObjectID(), username: req.user.username});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
delete mydata['__v'];
|
delete mydata['__v'];
|
||||||
delete mydata['__proto__'];
|
delete mydata['__proto__'];
|
||||||
|
|
||||||
@@ -411,7 +423,7 @@ router.post('/settable', authenticate, (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}catch (e) {
|
} catch (e) {
|
||||||
return res.status(400).send(e);
|
return res.status(400).send(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -627,7 +639,8 @@ router.patch('/chval', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
if (mydata.table === shared_consts.TAB_SITES) {
|
if (mydata.table === shared_consts.TAB_SITES) {
|
||||||
if (shared_consts.SITES_KEY_TO_CRYPTED in fieldsvalue) {
|
if (shared_consts.SITES_KEY_TO_CRYPTED in fieldsvalue) {
|
||||||
fieldsvalue[shared_consts.SITES_KEY_TO_CRYPTED] = tools.cryptdata(fieldsvalue[shared_consts.SITES_KEY_TO_CRYPTED]);
|
fieldsvalue[shared_consts.SITES_KEY_TO_CRYPTED] = tools.cryptdata(
|
||||||
|
fieldsvalue[shared_consts.SITES_KEY_TO_CRYPTED]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -810,272 +823,7 @@ router.patch('/callfunz', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
let fieldsvalue = {};
|
let fieldsvalue = {};
|
||||||
|
|
||||||
if (mydata.myfunc === shared_consts.CallFunz.SOSTITUISCI) { // SOSTITUISCI
|
if (mydata.myfunc === shared_consts.CallFunz.ZOOM_GIA_PARTECIPATO) {
|
||||||
|
|
||||||
let username_da_sostituire = mydata.data.username_da_sostituire;
|
|
||||||
|
|
||||||
let myuservecchio = await User.findOne(
|
|
||||||
{idapp, username: username_da_sostituire});
|
|
||||||
|
|
||||||
let mianavedasost = await Nave.findOne(
|
|
||||||
{idapp, riga: mydata.data.riga, col: mydata.data.col});
|
|
||||||
if (!!mianavedasost) {
|
|
||||||
|
|
||||||
// Sostituisci l'Utente
|
|
||||||
let myusernuovo = await User.getUserShortDataByUsername(idapp,
|
|
||||||
mydata.data.username);
|
|
||||||
let navepersistente = await NavePersistente.findByRigaColByDonatore(
|
|
||||||
idapp, mydata.data.riga, mydata.data.col, 0);
|
|
||||||
|
|
||||||
if (myusernuovo) {
|
|
||||||
|
|
||||||
if (!mydata.data.AddImbarco && mianavedasost.ind_order > 0) {
|
|
||||||
|
|
||||||
// Controlla prima se è in una Nave Temporanea, allora lo elimina dall'ultima Nave Temporanea
|
|
||||||
|
|
||||||
let miaarrnavi = await Nave.getArrPosizioniByUsername(idapp,
|
|
||||||
username);
|
|
||||||
if (miaarrnavi) {
|
|
||||||
miaarrnavi = miaarrnavi.reverse(); // parto dall'ultima
|
|
||||||
for (const mianave of miaarrnavi) {
|
|
||||||
let persistente = await NavePersistente.findByRigaColByDonatore(
|
|
||||||
idapp, mianave.riga, mianave.col, 0);
|
|
||||||
if (persistente.provvisoria) {
|
|
||||||
fieldsvalue = {
|
|
||||||
ind_order: -1,
|
|
||||||
};
|
|
||||||
|
|
||||||
let ris = await Nave.findByIdAndUpdate(mianave._id,
|
|
||||||
{$set: fieldsvalue});
|
|
||||||
if (!!ris) {
|
|
||||||
// rimosso++;
|
|
||||||
break; // Rimuovilo solo 1 !
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mianavedasost.ind_order >= 0) {
|
|
||||||
|
|
||||||
// ELIMINO LA LISTAINGRESSO CHE STO SOSTITUENDO (SOLO SE NON VIENE USATA DA ALTRA NAVE!)
|
|
||||||
let eliminatoingr = await ListaIngresso.eliminaListaIngresso(idapp,
|
|
||||||
mianavedasost.ind_order, req, mianavedasost.num_tess);
|
|
||||||
|
|
||||||
if (!eliminatoingr) {
|
|
||||||
return res.send({
|
|
||||||
code: server_constants.RIS_CODE_ERR,
|
|
||||||
msg: 'La Sostituzione non può avvenire ! Contattare Paolo. (ind_order=' +
|
|
||||||
mianavedasost.ind_order + ')',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!!myuservecchio) {
|
|
||||||
if (mydata.data.notifBot) {
|
|
||||||
|
|
||||||
const mydatamsg = {
|
|
||||||
tipomsg: tools.TipoMsg.SEND_MSG_A_UTENTE_SOSTITUITO,
|
|
||||||
navemediatore: {
|
|
||||||
riga: navepersistente.riga,
|
|
||||||
col: navepersistente.col,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
mydatamsg.flotta = await Flotta.getFlottaByNavePersistente(idapp,
|
|
||||||
navepersistente);
|
|
||||||
|
|
||||||
const rismsg = await telegrambot.getMsgByTipoMsg(mydatamsg,
|
|
||||||
myuservecchio.lang, myuservecchio, false);
|
|
||||||
|
|
||||||
if (!!rismsg) {
|
|
||||||
let messaggio = rismsg.body;
|
|
||||||
// let mytitle = rismsg.title;
|
|
||||||
if (!!messaggio) {
|
|
||||||
await telegrambot.sendMsgTelegram(idapp, myusernuovo.username,
|
|
||||||
messaggio);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Se ha gia delle altre navi, non cancellarlo!
|
|
||||||
if (!await Nave.checkIfMadeGift(idapp, myuservecchio.username)) {
|
|
||||||
|
|
||||||
if (mydata.data.deleteUser && mianavedasost.ind_order > 0) {
|
|
||||||
// Metti Deleted allo User
|
|
||||||
fieldsvalue = {
|
|
||||||
deleted: true,
|
|
||||||
date_deleted: new Date(),
|
|
||||||
};
|
|
||||||
|
|
||||||
await User.findByIdAndUpdate(myuservecchio.id,
|
|
||||||
{$set: fieldsvalue});
|
|
||||||
await telegrambot.sendMsgTelegramToTheManagers(idapp,
|
|
||||||
`L\'utente ${myuservecchio.name} ${myuservecchio.surname} (${myuservecchio.username}) è stato cancellato (nascosto) perchè sostituito (da ${req.user.name} ${req.user.surname} )`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
let ind_order = -1;
|
|
||||||
let myingr = null;
|
|
||||||
// Estrai un ind_order dalla Lista, se era ancora in attesa
|
|
||||||
if (!mydata.data.AddImbarco)
|
|
||||||
myingr = await ListaIngresso.findOne(
|
|
||||||
{idapp, added: false, username: myusernuovo.username});
|
|
||||||
|
|
||||||
if (!!myingr) {
|
|
||||||
ind_order = myingr.ind_order;
|
|
||||||
|
|
||||||
myingr.added = true;
|
|
||||||
await myingr.save();
|
|
||||||
} else {
|
|
||||||
// Crea un nuovo Ingresso
|
|
||||||
myingr = await ListaIngresso.addUserInListaIngresso(idapp,
|
|
||||||
myuser.username, myuser.username, myuser.lang, false, true,
|
|
||||||
null, null, true);
|
|
||||||
ind_order = myingr.ind_order;
|
|
||||||
|
|
||||||
await myingr.save();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Togliolo dalla Graduatoria!
|
|
||||||
await Graduatoria.findOneAndUpdate({
|
|
||||||
idapp,
|
|
||||||
idListaIngresso: myingr._id,
|
|
||||||
}, {$set: {ind_order: -1}}, {new: false});
|
|
||||||
|
|
||||||
// Aggiorna la Nave con il Nuovo
|
|
||||||
fieldsvalue = {
|
|
||||||
ind_order,
|
|
||||||
};
|
|
||||||
|
|
||||||
const dachi = req.user.name + ' ' + req.user.surname;
|
|
||||||
|
|
||||||
return await Nave.findByIdAndUpdate(mianavedasost.id,
|
|
||||||
{$set: fieldsvalue}).then(async (nave) => {
|
|
||||||
// tools.mylogshow(' REC TO MODIFY: ', rec);
|
|
||||||
if (!nave) {
|
|
||||||
return res.status(404).send();
|
|
||||||
} else {
|
|
||||||
|
|
||||||
const mydatamsg = {
|
|
||||||
tipomsg: tools.TipoMsg.SEND_MSG_EFFETTUA_IL_DONO,
|
|
||||||
navemediatore: {
|
|
||||||
riga: navepersistente.riga,
|
|
||||||
col: navepersistente.col,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
mydatamsg.flotta = await Flotta.getFlottaByNavePersistente(idapp,
|
|
||||||
navepersistente);
|
|
||||||
|
|
||||||
const rismsg = await telegrambot.getMsgByTipoMsg(mydatamsg,
|
|
||||||
myusernuovo.lang, myusernuovo, false);
|
|
||||||
|
|
||||||
let messaggio = rismsg.body;
|
|
||||||
let mytitle = rismsg.title;
|
|
||||||
|
|
||||||
// const myplacca = await Nave.getNavePos(idapp, navepersistente.riga, navepersistente.col);
|
|
||||||
// messaggio += tools.ACAPO + myplacca;
|
|
||||||
|
|
||||||
let testostaff = '';
|
|
||||||
if (mydata.notifBot)
|
|
||||||
testostaff = mydata.notifBot.txt;
|
|
||||||
|
|
||||||
const mymsg = testostaff + ' ' + myusernuovo.name + ' ' +
|
|
||||||
myusernuovo.surname + ' [da ' + dachi + ']' + tools.ACAPO +
|
|
||||||
'Inviato messaggio: ' + messaggio;
|
|
||||||
|
|
||||||
if (mydata.data.notifBot) {
|
|
||||||
|
|
||||||
await telegrambot.sendMsgTelegram(idapp, myusernuovo.username,
|
|
||||||
messaggio);
|
|
||||||
|
|
||||||
if (mydata.data.inviaemail) {
|
|
||||||
await sendemail.sendEmail_ByText(myusernuovo.lang,
|
|
||||||
myusernuovo.email, myusernuovo, idapp, {
|
|
||||||
emailbody: messaggio,
|
|
||||||
emailtitle: mytitle,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
await telegrambot.sendMsgTelegramToTheManagers(idapp,
|
|
||||||
testostaff);
|
|
||||||
await telegrambot.sendMsgTelegram(idapp, req.user.username,
|
|
||||||
testostaff);
|
|
||||||
// await telegrambot.sendMsgTelegram(idapp, req.user.username, myplacca);
|
|
||||||
} else {
|
|
||||||
tools.writeManagersLog(mymsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
const msgsost = '[NAVE ' + navepersistente.riga + '.' +
|
|
||||||
navepersistente.col + '] Sostituito ' +
|
|
||||||
myuservecchio.username + ' (' + myuservecchio.name + ' ' +
|
|
||||||
myuservecchio.surname + ') ' + ' con -> ' +
|
|
||||||
myusernuovo.username + ' (' + myusernuovo.name + ' ' +
|
|
||||||
myusernuovo.surname + '' +
|
|
||||||
') [Posiz. ' + nave.riga + '.' + nave.col + ' ind_order=' +
|
|
||||||
nave.ind_order + '] ' + ' [da ' + dachi + ']';
|
|
||||||
tools.writeSostituzioniLog(msgsost);
|
|
||||||
tools.writeFlottaLog(idapp, msgsost, mydatamsg.flotta.riga,
|
|
||||||
mydatamsg.flotta.col_prima);
|
|
||||||
await telegrambot.sendMsgTelegramToTheManagers(idapp, msgsost,
|
|
||||||
false);
|
|
||||||
|
|
||||||
// const nomecognomeprima = myuser.name + ' ' + myuser.surname + '(' + myuser.username + ')';
|
|
||||||
// const nomecognomenuovo = await User.getNameSurnameByUsername(idapp,);
|
|
||||||
|
|
||||||
res.send({code: server_constants.RIS_CODE_OK, msg: ''});
|
|
||||||
}
|
|
||||||
|
|
||||||
}).catch((e) => {
|
|
||||||
tools.mylogserr('Error patch USER: ', e.message);
|
|
||||||
res.status(400).send();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (mydata.myfunc ===
|
|
||||||
shared_consts.CallFunz.AGGIUNGI_NUOVO_IMBARCO) {
|
|
||||||
// Ottieni il prossimo Numero di Tessitura
|
|
||||||
//let num_tess = await Nave.getNextNumTess(idapp, ind_order);
|
|
||||||
// const num_tess = 1;
|
|
||||||
|
|
||||||
/*
|
|
||||||
let listaingr = await ListaIngresso.find({ idapp, ind_order }).sort({ num_tess: 1 });
|
|
||||||
const trovato = listaingr.find((rec) => rec.num_tess === num_tess);
|
|
||||||
if (trovato) {
|
|
||||||
num_tess = listaingr.slice(-1)[0].num_tess + 2;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// metti l'invitante inizialmente a Te stesso !
|
|
||||||
const invitante_username = req.body.data.invitante_username;
|
|
||||||
|
|
||||||
await ListaIngresso.addUserInListaIngresso(idapp, username,
|
|
||||||
invitante_username, myuser.lang, true, true);
|
|
||||||
|
|
||||||
let arrimbarchi = await ListaIngresso.findAllByUsername(idapp, username);
|
|
||||||
return res.send({code: server_constants.RIS_CODE_OK, arrimbarchi});
|
|
||||||
|
|
||||||
} else if (mydata.myfunc === shared_consts.CallFunz.CANCELLA_IMBARCO) {
|
|
||||||
|
|
||||||
const myrec = await ListaIngresso.getIngrEUserByFilter(idapp,
|
|
||||||
{idapp, _id: ObjectID(mydata.data.id)});
|
|
||||||
|
|
||||||
if (!!myrec) {
|
|
||||||
await ListaIngresso.find({_id: mydata.data.id});
|
|
||||||
|
|
||||||
const risdel = await ListaIngresso.eliminaListaIngresso(idapp,
|
|
||||||
mydata.ind_order, req, mydata.data.num_tess);
|
|
||||||
|
|
||||||
if (risdel) {
|
|
||||||
return res.send({code: server_constants.RIS_CODE_OK, msg: ''});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (mydata.myfunc === shared_consts.CallFunz.ZOOM_GIA_PARTECIPATO) {
|
|
||||||
|
|
||||||
if (!!myuser.username) {
|
if (!!myuser.username) {
|
||||||
let FormDaMostrare = telegrambot.getFormDaMostrare(idapp, mydata.myfunc,
|
let FormDaMostrare = telegrambot.getFormDaMostrare(idapp, mydata.myfunc,
|
||||||
@@ -1152,7 +900,8 @@ router.delete('/delrec/:table/:id', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
let cancellato = false;
|
let cancellato = false;
|
||||||
|
|
||||||
// tools.NotifyIfDelRecord(tablename);
|
//++Tools: Notify...
|
||||||
|
tools.NotifyIfDelRecord(tablename);
|
||||||
|
|
||||||
if (!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm)) {
|
if (!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm)) {
|
||||||
if (tablename === 'users') {
|
if (tablename === 'users') {
|
||||||
@@ -1276,7 +1025,8 @@ function load(req, res, version) {
|
|||||||
|
|
||||||
let gestoredelSito = '0';
|
let gestoredelSito = '0';
|
||||||
if (!!req.user) {
|
if (!!req.user) {
|
||||||
gestoredelSito = (User.isAdmin(req.user.perm) || User.isManager(req.user.perm) ||
|
gestoredelSito = (User.isAdmin(req.user.perm) ||
|
||||||
|
User.isManager(req.user.perm) ||
|
||||||
User.isEditor(req.user.perm)) ? '1' : '0';
|
User.isEditor(req.user.perm)) ? '1' : '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1284,7 +1034,6 @@ function load(req, res, version) {
|
|||||||
|
|
||||||
// tools.mylog('loadsite : ', req.params);
|
// tools.mylog('loadsite : ', req.params);
|
||||||
|
|
||||||
|
|
||||||
let bookedevent = [];
|
let bookedevent = [];
|
||||||
// let msgs = [];
|
// let msgs = [];
|
||||||
|
|
||||||
@@ -1295,7 +1044,8 @@ function load(req, res, version) {
|
|||||||
|
|
||||||
if (userId !== '0') {
|
if (userId !== '0') {
|
||||||
// LOGGED WITH USERID
|
// LOGGED WITH USERID
|
||||||
bookedevent = Booking.findAllByUserIdAndIdApp(userId, idapp, gestoredelSito);
|
bookedevent = Booking.findAllByUserIdAndIdApp(userId, idapp,
|
||||||
|
gestoredelSito);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract all the todos of the userId only
|
// Extract all the todos of the userId only
|
||||||
@@ -1357,7 +1107,7 @@ function load(req, res, version) {
|
|||||||
orderscart = OrdersCart.getOrdersCartByUserId(req.user.id, idapp, 0);
|
orderscart = OrdersCart.getOrdersCartByUserId(req.user.id, idapp, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let askedfriends = []
|
let askedfriends = [];
|
||||||
let myuserextra = null;
|
let myuserextra = null;
|
||||||
if (req.user) {
|
if (req.user) {
|
||||||
// askedfriends = User.getAskedFriendsByUsername(idapp, req.user.username);
|
// askedfriends = User.getAskedFriendsByUsername(idapp, req.user.username);
|
||||||
@@ -1506,7 +1256,6 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate, async (req, res) => {
|
|||||||
if (User.isAdmin(req.user.perm) || User.isEditor(req.user.perm) ||
|
if (User.isAdmin(req.user.perm) || User.isEditor(req.user.perm) ||
|
||||||
User.isManager(req.user.perm)) {
|
User.isManager(req.user.perm)) {
|
||||||
|
|
||||||
|
|
||||||
// Send UsersList
|
// Send UsersList
|
||||||
usersList = User.getUsersList(req.user.idapp);
|
usersList = User.getUsersList(req.user.idapp);
|
||||||
// usersList = null;
|
// usersList = null;
|
||||||
@@ -1621,7 +1370,8 @@ function uploadFile(req, res, version) {
|
|||||||
form.on('file', async function(name, file) {
|
form.on('file', async function(name, file) {
|
||||||
try {
|
try {
|
||||||
console.log('Uploaded ' + file.name);
|
console.log('Uploaded ' + file.name);
|
||||||
const mydir = tools.getdirByIdApp(idapp) + dirmain + server_constants.DIR_UPLOAD + '/' + dir;
|
const mydir = tools.getdirByIdApp(idapp) + dirmain +
|
||||||
|
server_constants.DIR_UPLOAD + '/' + dir;
|
||||||
|
|
||||||
// Create Dir if doesn't exist:
|
// Create Dir if doesn't exist:
|
||||||
tools.mkdirpath(mydir);
|
tools.mkdirpath(mydir);
|
||||||
@@ -1634,7 +1384,7 @@ function uploadFile(req, res, version) {
|
|||||||
// filename = uuidv4() + ext;
|
// filename = uuidv4() + ext;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
file.name = filename
|
file.name = filename;
|
||||||
let newname = mydir + '/' + file.name;
|
let newname = mydir + '/' + file.name;
|
||||||
let resized_img = mydir + '/' + server_constants.PREFIX_IMG + filename;
|
let resized_img = mydir + '/' + server_constants.PREFIX_IMG + filename;
|
||||||
|
|
||||||
@@ -1643,7 +1393,7 @@ function uploadFile(req, res, version) {
|
|||||||
// For local: ... resolve this... sending through the static folder...
|
// For local: ... resolve this... sending through the static folder...
|
||||||
// res.sendFile(path.resolve(filename));
|
// res.sendFile(path.resolve(filename));
|
||||||
|
|
||||||
oldpath = file.path
|
oldpath = file.path;
|
||||||
file.path = newname;
|
file.path = newname;
|
||||||
|
|
||||||
// Move in the folder application !
|
// Move in the folder application !
|
||||||
@@ -1675,13 +1425,13 @@ function uploadFile(req, res, version) {
|
|||||||
const ris = await resizer(newname, setup_image_compress);
|
const ris = await resizer(newname, setup_image_compress);
|
||||||
|
|
||||||
if (ris) {
|
if (ris) {
|
||||||
tools.delete(newname, false, () => {})
|
tools.delete(newname, false, () => {});
|
||||||
|
|
||||||
tools.move(resized_img, newname, (err) => {
|
tools.move(resized_img, newname, (err) => {
|
||||||
|
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}catch (e) {
|
} catch (e) {
|
||||||
console.error('newname', e);
|
console.error('newname', e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
39
src/server/router/mygroups_router.js
Executable file
39
src/server/router/mygroups_router.js
Executable file
@@ -0,0 +1,39 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
const tools = require('../tools/general');
|
||||||
|
|
||||||
|
const server_constants = require('../tools/server_constants');
|
||||||
|
|
||||||
|
const { authenticate } = require('../middleware/authenticate');
|
||||||
|
|
||||||
|
const mongoose = require('mongoose').set('debug', false)
|
||||||
|
|
||||||
|
const { User } = require('../models/user');
|
||||||
|
const { MyGroup } = require('../models/mygroup');
|
||||||
|
|
||||||
|
const _ = require('lodash');
|
||||||
|
|
||||||
|
const { ObjectID } = require('mongodb');
|
||||||
|
|
||||||
|
|
||||||
|
router.post('/load', authenticate, async (req, res) => {
|
||||||
|
const idapp = req.body.idapp;
|
||||||
|
const groupname = req.body.groupname;
|
||||||
|
|
||||||
|
try{
|
||||||
|
data = await MyGroup.findOne({idapp, groupname}).lean();
|
||||||
|
|
||||||
|
res.send(data);
|
||||||
|
|
||||||
|
}catch (e) {
|
||||||
|
console.error('Error in MyGroups');
|
||||||
|
return res.status(400).send(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
const ris = null
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
@@ -10,8 +10,8 @@ const { authenticate } = require('../middleware/authenticate');
|
|||||||
const mongoose = require('mongoose').set('debug', false)
|
const mongoose = require('mongoose').set('debug', false)
|
||||||
|
|
||||||
const { User } = require('../models/user');
|
const { User } = require('../models/user');
|
||||||
const { Nave } = require('../models/nave');
|
// const { Nave } = require('../models/nave');
|
||||||
const { ListaIngresso } = require('../models/listaingresso');
|
// const { ListaIngresso } = require('../models/listaingresso');
|
||||||
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
@@ -26,8 +26,8 @@ router.post('/load', async (req, res) => {
|
|||||||
|
|
||||||
let datastat = {
|
let datastat = {
|
||||||
num_reg: await User.getUsersRegistered(idapp),
|
num_reg: await User.getUsersRegistered(idapp),
|
||||||
num_passeggeri: await Nave.getTotInLista(idapp),
|
num_passeggeri: await 0,
|
||||||
num_imbarcati: await ListaIngresso.getTotInLista(idapp),
|
num_imbarcati: 0,
|
||||||
email_non_verif: await User.getEmailNotVerified(idapp),
|
email_non_verif: await User.getEmailNotVerified(idapp),
|
||||||
num_teleg_attivo: await User.getUsersTelegramAttivo(idapp),
|
num_teleg_attivo: await User.getUsersTelegramAttivo(idapp),
|
||||||
num_teleg_pending: await User.getUsersTelegramPending(idapp),
|
num_teleg_pending: await User.getUsersTelegramPending(idapp),
|
||||||
@@ -39,8 +39,8 @@ router.post('/load', async (req, res) => {
|
|||||||
arr_nations: await User.findAllDistinctNationality(idapp),
|
arr_nations: await User.findAllDistinctNationality(idapp),
|
||||||
numreg_untilday: await User.calcnumRegUntilDay(idapp),
|
numreg_untilday: await User.calcnumRegUntilDay(idapp),
|
||||||
reg_daily: await User.calcRegDaily(idapp),
|
reg_daily: await User.calcRegDaily(idapp),
|
||||||
imbarcati_daily: await ListaIngresso.ImbarcatiDaily(idapp),
|
imbarcati_daily: 0,
|
||||||
imbarcati_weekly: await ListaIngresso.ImbarcatiWeekly(idapp),
|
imbarcati_weekly: 0,
|
||||||
reg_weekly: await User.calcRegWeekly(idapp),
|
reg_weekly: await User.calcRegWeekly(idapp),
|
||||||
lastsreg: await User.getLastUsers(idapp),
|
lastsreg: await User.getLastUsers(idapp),
|
||||||
checkuser: await User.checkUser(idapp, username),
|
checkuser: await User.checkUser(idapp, username),
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ const Product = require('../models/product');
|
|||||||
const Variant = require('../models/variant');
|
const Variant = require('../models/variant');
|
||||||
const TypedError = require('../modules/ErrorHandler');
|
const TypedError = require('../modules/ErrorHandler');
|
||||||
|
|
||||||
|
const { MyGroup } = require('../models/mygroup');
|
||||||
|
|
||||||
const mongoose = require('mongoose').set('debug', false);
|
const mongoose = require('mongoose').set('debug', false);
|
||||||
const Subscription = mongoose.model('subscribers');
|
const Subscription = mongoose.model('subscribers');
|
||||||
|
|
||||||
@@ -491,6 +493,21 @@ router.post('/friends', authenticate, (req, res) => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.post('/groups', authenticate, (req, res) => {
|
||||||
|
const username = req.user.username;
|
||||||
|
idapp = req.body.idapp;
|
||||||
|
locale = req.body.locale;
|
||||||
|
|
||||||
|
|
||||||
|
return MyGroup.getGroupsByUsername(idapp, username).then((ris) => {
|
||||||
|
res.send(ris);
|
||||||
|
}).catch((e) => {
|
||||||
|
tools.mylog('ERRORE IN groups: ' + e.message);
|
||||||
|
res.status(400).send();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
router.post('/friends/cmd', authenticate, (req, res) => {
|
router.post('/friends/cmd', authenticate, (req, res) => {
|
||||||
const usernameLogged = req.user.username;
|
const usernameLogged = req.user.username;
|
||||||
const idapp = req.body.idapp;
|
const idapp = req.body.idapp;
|
||||||
@@ -516,6 +533,31 @@ router.post('/friends/cmd', authenticate, (req, res) => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.post('/groups/cmd', authenticate, (req, res) => {
|
||||||
|
const usernameLogged = req.user.username;
|
||||||
|
const idapp = req.body.idapp;
|
||||||
|
const locale = req.body.locale;
|
||||||
|
const usernameOrig = req.body.usernameOrig;
|
||||||
|
const groupnameDest = req.body.groupnameDest;
|
||||||
|
const cmd = req.body.cmd;
|
||||||
|
const value = req.body.value;
|
||||||
|
|
||||||
|
if (!User.isAdmin(req.user.perm) || !User.isManager(req.user.perm)) {
|
||||||
|
// If without permissions, exit
|
||||||
|
if (usernameOrig !== usernameLogged) {
|
||||||
|
return res.status(404).send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return MyGroup.setGroupsCmd(idapp, usernameOrig, groupnameDest, cmd, value).then((ris) => {
|
||||||
|
res.send(ris);
|
||||||
|
}).catch((e) => {
|
||||||
|
tools.mylog('ERRORE IN groups/cmd: ' + e.message);
|
||||||
|
res.status(400).send();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
async function eseguiDbOp(idapp, mydata, locale) {
|
async function eseguiDbOp(idapp, mydata, locale) {
|
||||||
|
|
||||||
let ris = await User.DbOp(idapp, mydata);
|
let ris = await User.DbOp(idapp, mydata);
|
||||||
@@ -529,7 +571,7 @@ async function eseguiDbOp(idapp, mydata, locale) {
|
|||||||
// } else if (mydata.dbop === 'rigeneraTutto') {
|
// } else if (mydata.dbop === 'rigeneraTutto') {
|
||||||
// await ListaIngresso.Esegui_CronTab(idapp, mydata);
|
// await ListaIngresso.Esegui_CronTab(idapp, mydata);
|
||||||
} else if (mydata.dbop === 'visuStat') {
|
} else if (mydata.dbop === 'visuStat') {
|
||||||
ris = await User.visuUtentiNonInNavi(idapp);
|
// ris = await User.visuUtentiNonInNavi(idapp);
|
||||||
//} else if (mydata.dbop === 'creaNavi') {
|
//} else if (mydata.dbop === 'creaNavi') {
|
||||||
// const num = await Nave.generaNave(idapp, mydata, false);
|
// const num = await Nave.generaNave(idapp, mydata, false);
|
||||||
// ris = { num };
|
// ris = { num };
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ myLoad().then(ris => {
|
|||||||
const projects_router = require('./router/projects_router');
|
const projects_router = require('./router/projects_router');
|
||||||
const report_router = require('./router/report_router');
|
const report_router = require('./router/report_router');
|
||||||
const users_router = require('./router/users_router');
|
const users_router = require('./router/users_router');
|
||||||
|
const mygroups_router = require('./router/mygroups_router');
|
||||||
const iscrittiConacreis_router = require('./router/iscrittiConacreis_router');
|
const iscrittiConacreis_router = require('./router/iscrittiConacreis_router');
|
||||||
const site_router = require('./router/site_router');
|
const site_router = require('./router/site_router');
|
||||||
const admin_router = require('./router/admin_router');
|
const admin_router = require('./router/admin_router');
|
||||||
@@ -148,6 +149,7 @@ myLoad().then(ris => {
|
|||||||
app.use('/test', test_router);
|
app.use('/test', test_router);
|
||||||
app.use('/projects', projects_router);
|
app.use('/projects', projects_router);
|
||||||
app.use('/users', users_router);
|
app.use('/users', users_router);
|
||||||
|
app.use('/mygroup', mygroups_router);
|
||||||
app.use('/iscritti_conacreis', iscrittiConacreis_router);
|
app.use('/iscritti_conacreis', iscrittiConacreis_router);
|
||||||
app.use('/report', report_router);
|
app.use('/report', report_router);
|
||||||
app.use('/site', site_router);
|
app.use('/site', site_router);
|
||||||
|
|||||||
@@ -12,17 +12,14 @@ const printf = require('util').format;
|
|||||||
|
|
||||||
const {User} = require('../models/user');
|
const {User} = require('../models/user');
|
||||||
const {CalZoom} = require('../models/calzoom');
|
const {CalZoom} = require('../models/calzoom');
|
||||||
const {Nave} = require('../models/nave');
|
|
||||||
const {MyBot} = require('../models/bot');
|
const {MyBot} = require('../models/bot');
|
||||||
const shared_consts = require('../tools/shared_nodejs');
|
const shared_consts = require('../tools/shared_nodejs');
|
||||||
|
|
||||||
const {ListaIngresso} = require('../models/listaingresso');
|
// const {ListaIngresso} = require('../models/listaingresso');
|
||||||
const {MsgTemplate} = require('../models/msg_template');
|
const {MsgTemplate} = require('../models/msg_template');
|
||||||
|
|
||||||
const emoji = require('node-emoji');
|
const emoji = require('node-emoji');
|
||||||
|
|
||||||
const {Flotta} = require('../models/flotta');
|
|
||||||
|
|
||||||
const i18n = require('i18n');
|
const i18n = require('i18n');
|
||||||
|
|
||||||
let url = process.env.URL || 'https://<PUBLIC-URL>';
|
let url = process.env.URL || 'https://<PUBLIC-URL>';
|
||||||
@@ -2498,21 +2495,8 @@ class Telegram {
|
|||||||
} else if (destin === Destin.NO_7_REQ) {
|
} else if (destin === Destin.NO_7_REQ) {
|
||||||
invia = !await User.isUserQualified7(this.idapp,
|
invia = !await User.isUserQualified7(this.idapp,
|
||||||
utente.username);
|
utente.username);
|
||||||
} else if (destin === Destin.NO_9_REQ) {
|
|
||||||
invia = !await User.isUserQualified9(this.idapp,
|
|
||||||
utente.username);
|
|
||||||
} else if (destin === Destin.NESSUN_IMBARCO_7REQ) {
|
|
||||||
invia = await User.NessunaNavePresenteByUsername(this.idapp,
|
|
||||||
utente.username);
|
|
||||||
} else if (destin === Destin.MSG_TO_NAVE) {
|
} else if (destin === Destin.MSG_TO_NAVE) {
|
||||||
invia = !await Nave.findDonatoreByNave(this.idapp,
|
// invia = !await Nave.findDonatoreByNave(this.idapp, rec.extraparam);
|
||||||
rec.extraparam);
|
|
||||||
} else if (destin === Destin.SI_INVITATI_NO_7REQ_INVITATI) {
|
|
||||||
const numinvitati = await ListaIngresso.getnumInvitati(
|
|
||||||
this.idapp, utente.username);
|
|
||||||
const numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(
|
|
||||||
this.idapp, utente.username);
|
|
||||||
invia = (numinvitati >= 2) && (numinvitatiattivi < 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TEST invia = true;
|
// TEST invia = true;
|
||||||
@@ -3371,13 +3355,7 @@ if (true) {
|
|||||||
// Controlla se è qualificato!
|
// Controlla se è qualificato!
|
||||||
const mydata = tools.AddDate(user.date_reg, 7);
|
const mydata = tools.AddDate(user.date_reg, 7);
|
||||||
|
|
||||||
const newrecingr = await ListaIngresso.addUserInListaIngresso(
|
// bot.editMessageText(tools.gettranslate('ADDED_TOLISTAINGRESSO', user.lang), opts);
|
||||||
user.idapp, user.username, user.aportador_solidario,
|
|
||||||
user.lang, true, true, mydata);
|
|
||||||
|
|
||||||
bot.editMessageText(
|
|
||||||
tools.gettranslate('ADDED_TOLISTAINGRESSO', user.lang),
|
|
||||||
opts);
|
|
||||||
|
|
||||||
} else if (data.action === InlineCmd.NON_VOGLIO_IMBARCARMI) {
|
} else if (data.action === InlineCmd.NON_VOGLIO_IMBARCARMI) {
|
||||||
await User.NonVoglioImbarcarmi(user.idapp, user.username);
|
await User.NonVoglioImbarcarmi(user.idapp, user.username);
|
||||||
|
|||||||
@@ -838,6 +838,53 @@ module.exports = {
|
|||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
sendNotificationByGroupname: async function(idapp, groupname, cmd, telegram) {
|
||||||
|
|
||||||
|
var {User} = require('../models/user');
|
||||||
|
var {MyGroup} = require('../models/mygroup');
|
||||||
|
|
||||||
|
const group = await MyGroup.findOne({idapp, groupname}, {_id: 1, admins: 1});
|
||||||
|
if (!group)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Send msg to Admins
|
||||||
|
|
||||||
|
const arrusernameAdmins = group.admins;
|
||||||
|
|
||||||
|
for (const username of arrusernameAdmins) {
|
||||||
|
const user = await User.get
|
||||||
|
let userId = user._id;
|
||||||
|
let lang = user.lang;
|
||||||
|
|
||||||
|
let title = this.getNomeAppByIdApp(idapp);
|
||||||
|
let descr = '';
|
||||||
|
let openUrl = '/';
|
||||||
|
let tag = '';
|
||||||
|
let actions = [];
|
||||||
|
if (cmd) {
|
||||||
|
if (cmd === shared_consts.FRIENDSCMD.REQFRIEND) {
|
||||||
|
descr = printf(this.get__('RICHIESTA_AMICIZIA', lang), username);
|
||||||
|
openUrl = '/my/' + username;
|
||||||
|
tag = 'reqfriends';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userId) {
|
||||||
|
this.sendNotificationToUser(userId, title, descr, openUrl, '', tag,
|
||||||
|
actions);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (telegram) {
|
||||||
|
const telegrambot = require('../telegram/telegrambot');
|
||||||
|
|
||||||
|
const idtelegram = await User.TelegIdByUsername(idapp, username);
|
||||||
|
|
||||||
|
await telegrambot.sendMsgTelegramByIdTelegram(idapp, idtelegram, descr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
// **********************
|
// **********************
|
||||||
// SORT WITH PREV_ID
|
// SORT WITH PREV_ID
|
||||||
// **********************
|
// **********************
|
||||||
@@ -2099,7 +2146,7 @@ module.exports = {
|
|||||||
|
|
||||||
NotifyIfDelRecord(table) {
|
NotifyIfDelRecord(table) {
|
||||||
if ((table === 'users') || (table === 'extralist') ||
|
if ((table === 'users') || (table === 'extralist') ||
|
||||||
(table === 'listaingressos') || (table === 'graduatorias')) {
|
(table === 'groups') || (table === 'graduatorias')) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,17 @@ module.exports = {
|
|||||||
FIND_PEOPLE: 166,
|
FIND_PEOPLE: 166,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
GROUPSCMD: {
|
||||||
|
SETTRUST: 1121,
|
||||||
|
REQGROUP: 1125,
|
||||||
|
SETGROUP: 1132,
|
||||||
|
REMOVE_FROM_MYGROUP: 1144,
|
||||||
|
REFUSE_REQ_GROUP: 1145,
|
||||||
|
CANCEL_REQ_GROUP: 1146,
|
||||||
|
BLOCK_GROUP: 1155,
|
||||||
|
FIND_GROUP: 1166,
|
||||||
|
},
|
||||||
|
|
||||||
REPORT_FILT_RESP: 1,
|
REPORT_FILT_RESP: 1,
|
||||||
REPORT_FILT_ATTIVITA: 2,
|
REPORT_FILT_ATTIVITA: 2,
|
||||||
|
|
||||||
@@ -69,8 +80,9 @@ module.exports = {
|
|||||||
PARAM_SHOW_PROVINCE: 1,
|
PARAM_SHOW_PROVINCE: 1,
|
||||||
|
|
||||||
TABLES_ID_NUMBER: ['permissions', 'levels', 'statusSkills', 'sectors', 'skills', 'subskills', 'cities', 'myskills'],
|
TABLES_ID_NUMBER: ['permissions', 'levels', 'statusSkills', 'sectors', 'skills', 'subskills', 'cities', 'myskills'],
|
||||||
TABLES_USER_ID: ['myskills'],
|
TABLES_USER_ID: ['myskills', 'mygroups'],
|
||||||
TABLES_UPDATE_LASTMODIFIED: ['myskills', 'mybots'],
|
TABLES_USER_INCLUDE_MY: ['mygroups'],
|
||||||
|
TABLES_UPDATE_LASTMODIFIED: ['myskills', 'mybots', 'mygroups'],
|
||||||
|
|
||||||
TABLES_PERM_CHANGE_FOR_USERS: ['myskills'],
|
TABLES_PERM_CHANGE_FOR_USERS: ['myskills'],
|
||||||
TABLES_PERM_NEWREC: ['skills', 'subskills'],
|
TABLES_PERM_NEWREC: ['skills', 'subskills'],
|
||||||
|
|||||||
Reference in New Issue
Block a user