106 lines
3.4 KiB
JavaScript
Executable File
106 lines
3.4 KiB
JavaScript
Executable File
const mongoose = require('mongoose').set('debug', false)
|
|
const Subscription = mongoose.model('subscribers');
|
|
|
|
const { ListaIngresso } = require('../../models/listaingresso');
|
|
const { Graduatoria } = require('../../models/graduatoria');
|
|
const { User } = require('../../models/user');
|
|
const { Nave } = require('../../models/nave');
|
|
|
|
const { ObjectID } = require('mongodb');
|
|
|
|
const tools = require('../../tools/general');
|
|
|
|
|
|
module.exports = {
|
|
doOtherThingsAfterDeleted: async function (tablename, rec, notifBot, req) {
|
|
try {
|
|
|
|
const { User } = require('../../models/user');
|
|
const telegrambot = require('../../telegram/telegrambot');
|
|
|
|
let ris = null;
|
|
|
|
const { ListaIngresso } = require('../../models/listaingresso');
|
|
|
|
if (tablename === 'users') {
|
|
|
|
await ListaIngresso.deleteUserInListaIngresso(rec.idapp, rec.username);
|
|
|
|
// Controlla se aveva invitati, li regala a quello sopra
|
|
const arrap = await User.getDownlineByUsername(rec.idapp, rec.username);
|
|
for (let user of arrap) {
|
|
|
|
await User.findOneAndUpdate({
|
|
idapp: rec.idapp,
|
|
username: user.username
|
|
}, { $set: { aportador_solidario: rec.aportador_solidario } }, { new: false });
|
|
|
|
let msg = 'Spostato ' + user.name + ' ' + user.surname + ' sotto di ' + rec.aportador_solidario;
|
|
telegrambot.sendMsgTelegramToTheManagers(rec.idapp, msg);
|
|
}
|
|
|
|
// Delete also all the subscribers record of this User
|
|
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 (notifBot) {
|
|
// Send Notification to the BOT
|
|
let nomerecord = '';
|
|
if ((tablename === 'users') || (tablename === 'extralist')) {
|
|
nomerecord = rec.name + ' ' + rec.surname + ' (' + rec.username + ')';
|
|
}
|
|
|
|
addtext = 'Eliminato il Record "' + nomerecord + '" dalla tabella ' + tablename + '\n' +
|
|
'Eseguito da ' + req.user.name + ' ' + req.user.surname + ' \n';
|
|
await telegrambot.sendMsgTelegramToTheManagers(rec.idapp, addtext);
|
|
}
|
|
|
|
}
|
|
|
|
return ris
|
|
|
|
} catch (e) {
|
|
console.error(e.message);
|
|
return false
|
|
}
|
|
|
|
},
|
|
doOtherThingsAfterDuplicated: async function (tablename, myrec, mynewrec) {
|
|
try {
|
|
if (tablename === 'users') {
|
|
// Delete also all the subscribers record of this User
|
|
|
|
}
|
|
return { myrec }
|
|
|
|
} catch (e) {
|
|
return false
|
|
}
|
|
return true;
|
|
}
|
|
};
|