Add Movement !
This commit is contained in:
@@ -965,7 +965,7 @@ module.exports = {
|
||||
let typedir = shared_consts.TypeNotifs.TYPEDIR_GROUPS;
|
||||
let typeid = 0;
|
||||
let onlysave = false;
|
||||
let name = await User.countUsersInGroup(idapp, groupname);
|
||||
let numuseringroup = await User.countUsersInGroup(idapp, groupname);
|
||||
|
||||
if (cmd) {
|
||||
if (cmd === shared_consts.GROUPSCMD.SETGROUP) {
|
||||
@@ -1006,7 +1006,8 @@ module.exports = {
|
||||
},
|
||||
|
||||
sendNotifCircuitByUsername: async function(
|
||||
cmd, idapp, usernameOrig, usernameDest, username_action, circuitname, path, myreccircuit, isAdmin, username_worked) {
|
||||
cmd, idapp, usernameOrig, usernameDest, username_action,
|
||||
circuitname, path, myreccircuit, isAdmin, username_worked, extrarec) {
|
||||
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
const {User} = require('../models/user');
|
||||
@@ -1016,57 +1017,65 @@ module.exports = {
|
||||
|
||||
const user = await User.findOne({idapp, username: usernameDest},
|
||||
{_id: 1, lang: 1});
|
||||
if (user) {
|
||||
|
||||
let lang = user.lang;
|
||||
let paramsObj = {
|
||||
usernameDest,
|
||||
circuitnameDest: circuitname,
|
||||
path,
|
||||
username_action: username_action,
|
||||
singleadmin_username: usernameDest,
|
||||
options: 0,
|
||||
lang,
|
||||
isAdmin,
|
||||
username_worked,
|
||||
};
|
||||
try {
|
||||
if (user) {
|
||||
|
||||
let sendnotif = true;
|
||||
let typedir = shared_consts.TypeNotifs.TYPEDIR_CIRCUITS;
|
||||
let typeid = 0;
|
||||
let onlysave = false;
|
||||
let numuserincircuit = await User.countUsersInCircuit(idapp, circuitname);
|
||||
let lang = user.lang;
|
||||
let paramsObj = {
|
||||
usernameDest,
|
||||
circuitnameDest: circuitname,
|
||||
path,
|
||||
username_action: username_action,
|
||||
singleadmin_username: usernameDest,
|
||||
extrarec,
|
||||
options: 0,
|
||||
lang,
|
||||
isAdmin,
|
||||
username_worked,
|
||||
};
|
||||
|
||||
if (cmd) {
|
||||
if (cmd === shared_consts.CIRCUITCMD.SET) {
|
||||
if (myreccircuit && myreccircuit.createdBy === usernameDest && numuserincircuit <= 1) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_NEW_REC;
|
||||
} else {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_ACCEPTED;
|
||||
let sendnotif = true;
|
||||
let typedir = shared_consts.TypeNotifs.TYPEDIR_CIRCUITS;
|
||||
let typeid = 0;
|
||||
let onlysave = false;
|
||||
let numuserincircuit = await User.countUsersInCircuit(idapp, circuitname);
|
||||
|
||||
if (cmd) {
|
||||
if (cmd === shared_consts.CIRCUITCMD.SET) {
|
||||
if (myreccircuit && myreccircuit.createdBy === usernameDest && numuserincircuit <= 1) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_NEW_REC;
|
||||
} else {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_ACCEPTED;
|
||||
}
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REFUSE_REQ) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_REFUSED;
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REMOVE_FROM_MYLIST) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_REMOVED;
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REQ) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_REQUEST_TO_ENTER;
|
||||
// paramsObj.options = MessageOptions.Notify_OnlyToNotifinApp + MessageOptions.Notify_ByBotTelegram;
|
||||
const myuserdata = await User.getUserShortDataByUsername(idapp, username_action);
|
||||
telegrambot.askConfirmationUser(idapp, shared_consts.CallFunz.RICHIESTA_CIRCUIT, myuserdata, usernameDest, circuitname,
|
||||
myreccircuit._id);
|
||||
onlysave = false;
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.ADDADMIN) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_ADDED_ADMIN;
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REMOVEADMIN) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_REMOVED_ADMIN;
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REQ) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ;
|
||||
}
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REFUSE_REQ) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_REFUSED;
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REMOVE_FROM_MYLIST) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_REMOVED;
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REQ) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_REQUEST_TO_ENTER;
|
||||
// paramsObj.options = MessageOptions.Notify_OnlyToNotifinApp + MessageOptions.Notify_ByBotTelegram;
|
||||
const myuserdata = await User.getUserShortDataByUsername(idapp, username_action);
|
||||
telegrambot.askConfirmationUser(idapp, shared_consts.CallFunz.RICHIESTA_CIRCUIT, myuserdata, usernameDest, circuitname,
|
||||
myreccircuit._id);
|
||||
onlysave = false;
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.ADDADMIN) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_ADDED_ADMIN_OFMYGROUP;
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REMOVEADMIN) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_REMOVED_ADMIN_OFMYGROUP;
|
||||
|
||||
}
|
||||
|
||||
if (sendnotif && typeid > 0) {
|
||||
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, paramsObj, onlysave, typedir, typeid);
|
||||
}
|
||||
}
|
||||
|
||||
if (sendnotif && typeid > 0) {
|
||||
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, paramsObj, onlysave, typedir, typeid);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
|
||||
},
|
||||
@@ -1108,7 +1117,7 @@ module.exports = {
|
||||
|
||||
},
|
||||
|
||||
sendNotificationByCircuit: async function(idapp, usernameOrig, circuitname, cmd, value, telegram, username_action) {
|
||||
sendNotificationByCircuit: async function(idapp, usernameOrig, circuitname, cmd, value, telegram, username_action, extrarec) {
|
||||
|
||||
const {Circuit} = require('../models/circuit');
|
||||
const {User} = require('../models/user');
|
||||
@@ -1121,25 +1130,35 @@ module.exports = {
|
||||
|
||||
try {
|
||||
// SEND TO THE ADMINS THE NOTIFICATIONS
|
||||
for (const singleadmin of circuit.admins) {
|
||||
try {
|
||||
if (singleadmin.username) {
|
||||
if (usernameOrig === singleadmin.username)
|
||||
giainviato = true;
|
||||
|
||||
await this.sendNotifCircuitByUsername(cmd, idapp, usernameOrig, singleadmin.username, username_action, circuitname,
|
||||
circuit.path, circuit, true);
|
||||
if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REQ) {
|
||||
await this.sendNotifCircuitByUsername(cmd, idapp, usernameOrig, extrarec.dest, username_action, circuitname, circuit.path, null,
|
||||
false, '', extrarec);
|
||||
|
||||
} else {
|
||||
|
||||
for (const singleadmin of circuit.admins) {
|
||||
try {
|
||||
if (singleadmin.username) {
|
||||
if (usernameOrig === singleadmin.username)
|
||||
giainviato = true;
|
||||
|
||||
await this.sendNotifCircuitByUsername(cmd, idapp, usernameOrig, singleadmin.username, username_action, circuitname,
|
||||
circuit.path, circuit, true, '', extrarec);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('sendNotificationByCircuit', e);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('sendNotificationByCircuit', e);
|
||||
}
|
||||
|
||||
if (!giainviato && cmd !== shared_consts.CIRCUITCMD.REQ) {
|
||||
// SEND TO THE USER DEST THE NOTIFICATION
|
||||
await this.sendNotifCircuitByUsername(cmd, idapp, usernameOrig, usernameOrig, username_action, circuitname, circuit.path, null,
|
||||
false, '', extrarec);
|
||||
}
|
||||
}
|
||||
|
||||
if (!giainviato && (cmd !== shared_consts.CIRCUITCMD.REQ)) {
|
||||
// SEND TO THE USER THE NOTIFICATION
|
||||
await this.sendNotifCircuitByUsername(cmd, idapp, usernameOrig, usernameOrig, username_action, circuitname, circuit.path, null,
|
||||
false);
|
||||
}
|
||||
|
||||
|
||||
} catch (e) {
|
||||
console.error('sendNotificationByCircuit: ', e);
|
||||
@@ -1550,6 +1569,14 @@ module.exports = {
|
||||
},
|
||||
},
|
||||
};
|
||||
} else if (shared_consts.TABLES_NUM_AS_ID_NUMBER.includes(params.table)) {
|
||||
myquery = {
|
||||
$match: {
|
||||
$expr: {
|
||||
$eq: ['$Num', params.myid],
|
||||
},
|
||||
},
|
||||
};
|
||||
} else {
|
||||
myquery = {
|
||||
$match: {
|
||||
@@ -1557,7 +1584,7 @@ module.exports = {
|
||||
$eq: ['$_id', mongoose.Types.ObjectId(params.myid)],
|
||||
},
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user