Files
freeplanet_serverside/src/server/router/api/actions.js

83 lines
2.4 KiB
JavaScript
Raw Normal View History

2022-09-14 11:32:04 +02:00
const mongoose = require('mongoose').set('debug', false)
const Subscription = mongoose.model('subscribers');
2022-02-03 00:33:15 +01:00
//const { ListaIngresso } = require('../../models/listaingresso');
const { Graduatoria } = require('../../models/graduatoria');
const { User } = require('../../models/user');
const { ObjectID } = require('mongodb');
const tools = require('../../tools/general');
module.exports = {
doOtherThingsAfterDeleted: async function (tablename, rec, notifBot, req) {
try {
2020-09-04 00:06:49 +02:00
const { User } = require('../../models/user');
const telegrambot = require('../../telegram/telegrambot');
let ris = null;
2020-07-02 22:00:58 +02:00
2022-02-03 00:33:15 +01:00
// const { ListaIngresso } = require('../../models/listaingresso');
2020-07-02 22:00:58 +02:00
if (tablename === 'users') {
2022-02-03 00:33:15 +01:00
// 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 (!!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.username + ' \n';
2020-09-04 00:06:49 +02:00
await telegrambot.sendMsgTelegramToTheManagers(rec.idapp, addtext);
}
}
return ris
} catch (e) {
2020-05-04 19:34:41 +02:00
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;
}
};