Click per mandare un messaggio al Destinatario dei RIS, se non è entrato ancora in RIS ITALIA.
This commit is contained in:
@@ -640,12 +640,15 @@ AccountSchema.statics.updateQtaMax = async function (idapp, username, groupname,
|
||||
};
|
||||
|
||||
AccountSchema.statics.getAccountsCircuitiNazionali = async function (idapp) {
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
const circuit = await Circuit.find({ idapp, showAlways: true });
|
||||
|
||||
return Account.find({ idapp, circuitId: circuit.id });
|
||||
};
|
||||
|
||||
AccountSchema.statics.updateAccountCircuitoNazionaleByLimiti = async function (idapp, circuitId, fidoConcesso, qta_maxConcessa) {
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
try {
|
||||
const accounts = await this.getAccountsCircuitiNazionali(idapp);
|
||||
@@ -714,11 +717,19 @@ AccountSchema.statics.addToPeopleOfMyAccount = async function (idapp, username,
|
||||
|
||||
// Rimuovi dagli Admin del Account
|
||||
AccountSchema.statics.removeAdminOfAccount = async function (idapp, username, circuitId, person_username, perm) {
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
return await Circuit.updateOne({ idapp, username, circuitId },
|
||||
{ $pull: { people: { username: { $in: [person_username] } } } });
|
||||
};
|
||||
|
||||
// Rimuovi l'account
|
||||
AccountSchema.statics.removeAccount = async function (accountId) {
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
return await Circuit.deleteOne({ _id: accountId});
|
||||
};
|
||||
|
||||
AccountSchema.statics.updateSaldoAndTransato_AllAccounts = async function (idapp) {
|
||||
|
||||
const recaccounts = await Account.find({ idapp });
|
||||
|
||||
@@ -478,6 +478,23 @@ CircuitSchema.statics.getCircuitByName = async function (idapp, name) {
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getCircuitIdByName = async function (idapp, name) {
|
||||
|
||||
const myfind = {
|
||||
idapp,
|
||||
name,
|
||||
};
|
||||
|
||||
try {
|
||||
const circuit = await Circuit.findOne(myfind);
|
||||
return (!!circuit ? circuit._id : 0);
|
||||
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getCircuitByProvince = async function (idapp, strProv) {
|
||||
|
||||
const myfind = {
|
||||
@@ -924,6 +941,28 @@ CircuitSchema.statics.SetDefMinMaxPersonali = async function (idapp, valmin, val
|
||||
|
||||
};
|
||||
|
||||
// Imposta a tutti i Conti Collettivi, i seguenti minimi e massimi
|
||||
CircuitSchema.statics.getCircuitMyProvince = async function (idapp, username) {
|
||||
const { User } = require('../models/user');
|
||||
|
||||
const myuser = await User.getUserByUsername(idapp, username);
|
||||
|
||||
try {
|
||||
const circuit = await this.getCircuitByProvince(idapp, myuser.profile.resid_province);
|
||||
|
||||
if (circuit) {
|
||||
if (await User.ifAlreadyInCircuit(idapp, username, circuit.name)) {
|
||||
return circuit.name;
|
||||
}
|
||||
}
|
||||
|
||||
return '[nessun Circuito]';
|
||||
|
||||
} catch (e) {
|
||||
console.error('Error', e);
|
||||
}
|
||||
};
|
||||
|
||||
// Imposta a tutti i Conti Collettivi, i seguenti minimi e massimi
|
||||
CircuitSchema.statics.createCircuitIfNotExist = async function (req, idapp, province) {
|
||||
const { User } = require('../models/user');
|
||||
|
||||
@@ -450,6 +450,9 @@ const UserSchema = new mongoose.Schema({
|
||||
noCircuit: {
|
||||
type: Boolean,
|
||||
},
|
||||
noCircIta: {
|
||||
type: Boolean,
|
||||
},
|
||||
noFoto: {
|
||||
type: Boolean,
|
||||
},
|
||||
@@ -1899,9 +1902,26 @@ UserSchema.statics.removeFromCircuits = async function (idapp, username, circuit
|
||||
update = { $pull: { req_users: { username: { $in: [username] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
|
||||
return await User.updateOne({ idapp, username },
|
||||
const ris = await User.updateOne({ idapp, username },
|
||||
{ $pull: { 'profile.mycircuits': { circuitname: { $in: [circuitname] } } } });
|
||||
|
||||
|
||||
const circuitId = await Circuit.getCircuitIdByName(idapp, circuitname);
|
||||
let remove = false;
|
||||
|
||||
// Se il mio account non è stato utilizzato, allora lo cancello anche questo
|
||||
const myaccount = await Account.getAccountByUsernameAndCircuitId(idapp, username, circuitId, false, false, '', '');
|
||||
if (myaccount && myaccount.totTransato === 0) {
|
||||
remove = true;
|
||||
} else {
|
||||
remove = true;
|
||||
}
|
||||
|
||||
if (remove) {
|
||||
await Account.removeAccount(myaccount._id);
|
||||
}
|
||||
|
||||
return ris;
|
||||
};
|
||||
|
||||
// Aggiungo il Circuito
|
||||
@@ -2329,6 +2349,86 @@ UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, use
|
||||
return ris;
|
||||
};
|
||||
|
||||
UserSchema.statics.sendCmd = async function (req, idapp, usernameOrig, usernameDest, cmd, value, disablenotif) {
|
||||
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
|
||||
const telegrambot = require('../telegram/telegrambot');
|
||||
|
||||
const cl = telegrambot.getclTelegByidapp(idapp);
|
||||
|
||||
if (!req) {
|
||||
req = tools.getReqByPar(idapp, usernameOrig);
|
||||
}
|
||||
|
||||
const myuser = await User.getUserByUsername(idapp, usernameOrig);
|
||||
const recuserDest = await User.getUserByUsername(idapp, usernameDest);
|
||||
|
||||
const langdest = recuserDest.lang;
|
||||
const telegid = recuserDest.profile.teleg_id;
|
||||
|
||||
let userId = recuserDest._id;
|
||||
let title = tools.getNomeAppByIdApp(idapp);
|
||||
let keyb = null;
|
||||
let descr = '';
|
||||
|
||||
let send_notif = false;
|
||||
let send_msgTelegramBot = false;
|
||||
let actions = [];
|
||||
let popupOnApp = '';
|
||||
|
||||
let ris = null;
|
||||
|
||||
try {
|
||||
if (cmd === shared_consts.CallFunz.ENTRA_RIS_ITALIA) {
|
||||
mycircuitOrig = await Circuit.getCircuitMyProvince(idapp, usernameOrig);
|
||||
descr = i18n.__({ phrase: 'SENDMSG_ENTRA_IN_RISO_ITALIA', locale: langdest }, usernameDest, usernameOrig, mycircuitOrig);
|
||||
msgtelegram = descr;
|
||||
|
||||
openUrl = '/circuit/ris_italia';
|
||||
bottone = i18n.__({ phrase: 'CIRCUIT_OPEN_RISITALIA', locale: langdest });
|
||||
tag = 'risitalia';
|
||||
|
||||
send_notif = true;
|
||||
send_msgTelegramBot = true;
|
||||
|
||||
keyb = cl.getInlineKeyboard(langdest, [
|
||||
{
|
||||
text: bottone,
|
||||
url: tools.getHostByIdApp(idapp) + openUrl,
|
||||
// callback_data: InlineConferma.RISPOSTA_SI + myfunc + tools.SEP + myuser.username + tools.SEP + '' + tools.SEP + '' + tools.SEP +
|
||||
// groupid,
|
||||
},
|
||||
]);
|
||||
|
||||
popupOnApp = 'Messaggio inviato al destinatario';
|
||||
|
||||
}
|
||||
|
||||
if (send_notif) {
|
||||
// SEND PUSH NOTIFICATION
|
||||
await tools.sendNotificationToUser(userId, title, descr, openUrl, '', tag, actions);
|
||||
}
|
||||
|
||||
// Invia Msg
|
||||
if (send_msgTelegramBot && msgtelegram) {
|
||||
await telegrambot.local_sendMsgTelegramByIdTelegram(idapp, telegid, msgtelegram, undefined, undefined, true, keyb);
|
||||
}
|
||||
|
||||
const userprofile = await User.getInfoFriendByUsername(idapp, usernameDest);
|
||||
const myuser = await User.getInfoFriendByUsername(idapp, usernameOrig);
|
||||
|
||||
ris = { userprofile, myuser, popupOnApp, result: true };
|
||||
|
||||
} catch (e) {
|
||||
popupOnApp = e;
|
||||
ris = { popupOnApp };
|
||||
console.error('Error sendCmd: ', e);
|
||||
}
|
||||
|
||||
return ris;
|
||||
};
|
||||
|
||||
UserSchema.statics.ifAlreadyInGroup = async function (idapp, usernameOrig, groupnameDest) {
|
||||
|
||||
// Controllo se è stato già inserito
|
||||
@@ -4839,7 +4939,7 @@ UserSchema.statics.getExtraInfoByUsername = async function (idapp, username) {
|
||||
UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, version) {
|
||||
|
||||
try {
|
||||
tools.startTimeLog('addExtraInfo')
|
||||
// tools.startTimeLog('addExtraInfo')
|
||||
|
||||
if (version) {
|
||||
let versattualeuser = 0;
|
||||
@@ -4938,7 +5038,7 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, v
|
||||
|
||||
recUser.profile.calc = await User.calcOtherByUser(idapp, recUser._id);
|
||||
|
||||
tools.endTimeLog('addExtraInfo')
|
||||
// tools.endTimeLog('addExtraInfo')
|
||||
|
||||
return recUser;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user