2019-10-20 01:21:54 +02:00
|
|
|
var mongoose = require('mongoose');
|
|
|
|
|
const Subscription = mongoose.model('subscribers');
|
|
|
|
|
|
2020-03-10 21:44:14 +01:00
|
|
|
const { ListaIngresso } = require('../../models/listaingresso');
|
|
|
|
|
const { User } = require('../../models/user');
|
|
|
|
|
|
|
|
|
|
const telegrambot = require('../../telegram/telegrambot');
|
|
|
|
|
|
2019-10-20 01:21:54 +02:00
|
|
|
module.exports = {
|
2019-10-21 20:38:10 +02:00
|
|
|
doOtherThingsAfterDeleted: async function (tablename, rec) {
|
2019-10-20 01:21:54 +02:00
|
|
|
try {
|
|
|
|
|
if (tablename === 'users') {
|
2020-03-10 21:44:14 +01:00
|
|
|
|
2020-05-10 21:07:51 +02:00
|
|
|
await ListaIngresso.deleteUserInListaIngresso(rec.idapp, rec.username);
|
2020-03-10 21:44:14 +01:00
|
|
|
|
|
|
|
|
// 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(idapp, msg);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-20 01:21:54 +02:00
|
|
|
// Delete also all the subscribers record of this User
|
2020-01-13 23:52:51 +01:00
|
|
|
return Subscription.deleteOne({ userId: rec._id })
|
2019-10-20 01:21:54 +02:00
|
|
|
}
|
|
|
|
|
} catch (e) {
|
2020-05-04 19:34:41 +02:00
|
|
|
console.error(e.message);
|
2019-10-20 01:21:54 +02:00
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2019-10-20 22:45:09 +02:00
|
|
|
},
|
2019-10-21 20:38:10 +02:00
|
|
|
doOtherThingsAfterDuplicated: async function (tablename, myrec, mynewrec) {
|
2019-10-20 22:45:09 +02:00
|
|
|
try {
|
|
|
|
|
if (tablename === 'users') {
|
|
|
|
|
// Delete also all the subscribers record of this User
|
|
|
|
|
|
|
|
|
|
}
|
2019-10-21 20:38:10 +02:00
|
|
|
return { myrec }
|
|
|
|
|
|
2019-10-20 22:45:09 +02:00
|
|
|
} catch (e) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2019-10-20 01:21:54 +02:00
|
|
|
}
|
|
|
|
|
};
|