set notif if service your province
This commit is contained in:
@@ -3,8 +3,9 @@
|
|||||||
"Hello %s": "Ciao %s",
|
"Hello %s": "Ciao %s",
|
||||||
"Good: %s": "Bene: %s",
|
"Good: %s": "Bene: %s",
|
||||||
"Service: %s": "Servizio: %s",
|
"Service: %s": "Servizio: %s",
|
||||||
"<strong>%s</strong> new Good: %s": "<strong>%s</strong> nuovo Bene: %s",
|
"NEW_GOOD": "<strong>%s</strong> ha aggiunto un nuovo Bene: %s",
|
||||||
"<strong>%s</strong> new Service: %s": "<strong>%s</strong> nuovo Servizio: %s",
|
"NEW_SERVICE": "<strong>%s</strong> ha aggiunto un nuovo Servizio: %s",
|
||||||
|
"NEW_HOSP": "<strong>%s</strong> ha aggiunto una nuova Ospitalità: %s",
|
||||||
"OPEN PAGE": "<em>APRI la APP RISO oppure visita riso.app</em>",
|
"OPEN PAGE": "<em>APRI la APP RISO oppure visita riso.app</em>",
|
||||||
"<strong>%s</strong> asked you for Friendship": "<strong>%s</strong> ti ha chiesto l'Amicizia",
|
"<strong>%s</strong> asked you for Friendship": "<strong>%s</strong> ti ha chiesto l'Amicizia",
|
||||||
"<strong>%s</strong> accepted your Friendship": "<strong>%s</strong> ha accettato l'Amicizia",
|
"<strong>%s</strong> accepted your Friendship": "<strong>%s</strong> ha accettato l'Amicizia",
|
||||||
|
|||||||
45
src/server/models/search.js
Executable file
45
src/server/models/search.js
Executable file
@@ -0,0 +1,45 @@
|
|||||||
|
const mongoose = require('mongoose').set('debug', false)
|
||||||
|
const Schema = mongoose.Schema;
|
||||||
|
|
||||||
|
mongoose.Promise = global.Promise;
|
||||||
|
mongoose.level = "F";
|
||||||
|
|
||||||
|
const tools = require('../tools/general');
|
||||||
|
|
||||||
|
const { ObjectID } = require('mongodb');
|
||||||
|
|
||||||
|
// Resolving error Unknown modifier: $pushAll
|
||||||
|
mongoose.plugin(schema => {
|
||||||
|
schema.options.usePushEach = true
|
||||||
|
});
|
||||||
|
|
||||||
|
const searchSchema = new Schema({
|
||||||
|
idapp: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
userId: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
text: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
searchSchema.statics.findAllByUserIdAndIdApp = function (userId, idapp, sall) {
|
||||||
|
const Search = this;
|
||||||
|
|
||||||
|
let myfind = {};
|
||||||
|
if (sall === '1')
|
||||||
|
myfind = { idapp };
|
||||||
|
else
|
||||||
|
myfind = { userId, idapp };
|
||||||
|
|
||||||
|
return Search.find(myfind, (err, arrsearch) => {
|
||||||
|
return arrsearch
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const Search = mongoose.model('Search', searchSchema);
|
||||||
|
|
||||||
|
module.exports = { Search };
|
||||||
@@ -182,14 +182,19 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
|||||||
|
|
||||||
if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_BACHECA) {
|
if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_BACHECA) {
|
||||||
if (recnotif.typeid === shared_consts.TypeNotifs.ID_BACHECA_NEW_GOOD) {
|
if (recnotif.typeid === shared_consts.TypeNotifs.ID_BACHECA_NEW_GOOD) {
|
||||||
newdescr = i18n.__('<strong>%s</strong> new Good: %s', userorig, mydescr);
|
newdescr = i18n.__('NEW_GOOD', userorig, mydescr);
|
||||||
recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYGOODS, true) + myidrec;
|
recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYGOODS, true) + myidrec;
|
||||||
tag = 'newgood';
|
tag = 'newgood';
|
||||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_BACHECA_NEW_SERVICE) {
|
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_BACHECA_NEW_SERVICE) {
|
||||||
newdescr = i18n.__('<strong>%s</strong> new Service: %s', userorig, mydescr);
|
newdescr = i18n.__('NEW_SERVICE', userorig, mydescr);
|
||||||
recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYSKILLS, true) + myidrec;
|
recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYSKILLS, true) + myidrec;
|
||||||
tag = 'newservice';
|
tag = 'newservice';
|
||||||
|
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_BACHECA_NEW_HOSP) {
|
||||||
|
newdescr = i18n.__('NEW_HOSP', userorig, mydescr);
|
||||||
|
recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYHOSPS, true) + myidrec;
|
||||||
|
tag = 'newhosp';
|
||||||
}
|
}
|
||||||
|
recnotif.textaddTelegram = 'Vedi post';
|
||||||
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_FRIENDS) {
|
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_FRIENDS) {
|
||||||
recnotif.openUrl = '/my/' + sender;
|
recnotif.openUrl = '/my/' + sender;
|
||||||
if (recnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_NEW_REC) {
|
if (recnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_NEW_REC) {
|
||||||
@@ -882,6 +887,7 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass,
|
|||||||
lang: 1,
|
lang: 1,
|
||||||
username: 1,
|
username: 1,
|
||||||
'profile.notifs': 1,
|
'profile.notifs': 1,
|
||||||
|
'profile.resid_province': 1,
|
||||||
'profile.notif_idCities': 1,
|
'profile.notif_idCities': 1,
|
||||||
'profile.notif_provinces': 1,
|
'profile.notif_provinces': 1,
|
||||||
'profile.notif_regions': 1,
|
'profile.notif_regions': 1,
|
||||||
@@ -939,6 +945,10 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass,
|
|||||||
shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
|
shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
|
||||||
// Estrai la Città, la Provincia e la regione.
|
// Estrai la Città, la Provincia e la regione.
|
||||||
|
|
||||||
|
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_YOUR_PROVINCE) &&
|
||||||
|
user.profile.resid_province && arrprovinces.indexOf(user.profile.resid_province) >= 0) {
|
||||||
|
send = true;
|
||||||
|
}
|
||||||
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_PROVINCE) &&
|
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_PROVINCE) &&
|
||||||
user.profile.notif_provinces && user.profile.notif_provinces.some(r => arrprovinces.indexOf(r) >= 0)) {
|
user.profile.notif_provinces && user.profile.notif_provinces.some(r => arrprovinces.indexOf(r) >= 0)) {
|
||||||
send = true;
|
send = true;
|
||||||
|
|||||||
@@ -4696,13 +4696,21 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, v
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
try {
|
if (version) {
|
||||||
if (recUserSave && recUser.profile && recUser.profile.notifs && recUser.profile.notifs.length <= 0) {
|
let versattualeuser = 0;
|
||||||
recUser.profile.notifs = shared_consts.DEFAULT_NOTIFS_USER;
|
if (!recUser.profile.version) {
|
||||||
await recUserSave.save();
|
recUser.version = 0;
|
||||||
|
versattualeuser = 0;
|
||||||
|
} else {
|
||||||
|
versattualeuser = recUser.profile.version;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (versattualeuser < version) {
|
||||||
|
// Aggiornamento versione
|
||||||
|
recUser = await User.updateVersion(versattualeuser, recUser);
|
||||||
|
|
||||||
|
await User.findOneAndUpdate({_id: recUser._id}, {$set: { 'profile.version' : version }});
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
console.error('Err addExtraInfo notifs ', e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const listSentMyRequestFriends = await User.find({
|
const listSentMyRequestFriends = await User.find({
|
||||||
@@ -4781,23 +4789,6 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, v
|
|||||||
|
|
||||||
recUser.profile.calc = await User.calcOtherByUser(idapp, recUser._id);
|
recUser.profile.calc = await User.calcOtherByUser(idapp, recUser._id);
|
||||||
|
|
||||||
if (version) {
|
|
||||||
let versattualeuser = 0;
|
|
||||||
if (!recUser.profile.version) {
|
|
||||||
recUser.version = 0;
|
|
||||||
versattualeuser = 0;
|
|
||||||
} else {
|
|
||||||
versattualeuser = recUser.profile.version;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (versattualeuser < version) {
|
|
||||||
// Aggiornamento versione
|
|
||||||
recUser = await User.updateVersion(versattualeuser, recUser);
|
|
||||||
|
|
||||||
await User.findOneAndUpdate({_id: recUser._id}, {$set: { 'profile.version' : version }});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return recUser;
|
return recUser;
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -4809,8 +4800,47 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, v
|
|||||||
|
|
||||||
UserSchema.statics.updateVersion = async function (userversion, recUser) {
|
UserSchema.statics.updateVersion = async function (userversion, recUser) {
|
||||||
|
|
||||||
if (userversion < 603) {
|
const { MySkill } = require('../models/myskill');
|
||||||
|
const { MyGood } = require('../models/mygood');
|
||||||
|
const { City } = require('../models/city');
|
||||||
|
|
||||||
|
if (userversion < 604) {
|
||||||
|
if (!recUser.profile.notifs || recUser.profile.notifs.length === 0) {
|
||||||
|
recUser.profile.notifs = shared_consts.DEFAULT_NOTIFS_USER;
|
||||||
|
}
|
||||||
|
|
||||||
|
const recfavoriteNotif = recUser.profile.notifs.find((rec) => rec.dir === 11);
|
||||||
|
if (!recfavoriteNotif){
|
||||||
recUser.profile.notifs.push( { dir: 11, value: 1 })
|
recUser.profile.notifs.push( { dir: 11, value: 1 })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Imposta la provincia, se non l'ho messa, in base al bene o servizio che hai messo.
|
||||||
|
if (!recUser.profile.resid_province) {
|
||||||
|
let resid_province = '';
|
||||||
|
const firstrec = await MySkill.findOne({userId: recUser._id}).lean();
|
||||||
|
if (firstrec && firstrec.idCity && firstrec.idCity.length > 0) {
|
||||||
|
resid_province = await City.getProvinceByIdCity(firstrec.idCity[0]);
|
||||||
|
} else {
|
||||||
|
const firstrec = await MyGood.findOne({userId: recUser._id}).lean();
|
||||||
|
if (firstrec && firstrec.idCity && firstrec.idCity.length === 1) {
|
||||||
|
resid_province = await City.getProvinceByIdCity(firstrec.idCity[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (resid_province) {
|
||||||
|
await User.findOneAndUpdate({_id: recUser._id}, {$set: {'profile.resid_province': resid_province}});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let recmybach = recUser.profile.notifs.find((rec) => rec.dir === shared_consts.TypeNotifs.TYPEDIR_BACHECA);
|
||||||
|
if (!tools.isBitActive(recmybach.value, shared_consts.UsersNotif.NEW_ADV_YOUR_PROVINCE)) {
|
||||||
|
recmybach.value = tools.SetBit(recmybach.value, shared_consts.UsersNotif.NEW_ADV_YOUR_PROVINCE);
|
||||||
|
for (let i = 0; i < recUser.profile.notifs.length; i++) {
|
||||||
|
if (recUser.profile.notifs[i].dir === shared_consts.TypeNotifs.TYPEDIR_BACHECA)
|
||||||
|
recUser.profile.notifs[i].value = recmybach.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await User.findOneAndUpdate({_id: recUser._id}, {$set: { 'profile.notifs': recUser.profile.notifs }});
|
await User.findOneAndUpdate({_id: recUser._id}, {$set: { 'profile.notifs': recUser.profile.notifs }});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -448,9 +448,12 @@ router.post('/settable', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(params.table)) {
|
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(params.table)) {
|
||||||
typedir = shared_consts.TypeNotifs.TYPEDIR_BACHECA;
|
typedir = shared_consts.TypeNotifs.TYPEDIR_BACHECA;
|
||||||
typeid = (params.table === shared_consts.TABLES_MYGOODS)
|
if (params.table === shared_consts.TABLES_MYGOODS)
|
||||||
? shared_consts.TypeNotifs.ID_BACHECA_NEW_GOOD
|
typeid = shared_consts.TypeNotifs.ID_BACHECA_NEW_GOOD
|
||||||
: shared_consts.TypeNotifs.ID_BACHECA_NEW_SERVICE;
|
else if (params.table === shared_consts.TABLES_MYSKILLS)
|
||||||
|
typeid = shared_consts.TypeNotifs.ID_BACHECA_NEW_SERVICE
|
||||||
|
else if (params.table === shared_consts.TABLES_MYHOSPS)
|
||||||
|
typeid = shared_consts.TypeNotifs.ID_BACHECA_NEW_HOSP
|
||||||
setnotif = true;
|
setnotif = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1992,6 +1992,9 @@ module.exports = {
|
|||||||
|
|
||||||
getQueryTable: async function (idapp, params, user) {
|
getQueryTable: async function (idapp, params, user) {
|
||||||
|
|
||||||
|
|
||||||
|
const { Search }= require('../models/search');
|
||||||
|
|
||||||
if (typeof params.startRow !== 'number') {
|
if (typeof params.startRow !== 'number') {
|
||||||
throw new Error('startRow must be number');
|
throw new Error('startRow must be number');
|
||||||
} else if (typeof params.endRow !== 'number') {
|
} else if (typeof params.endRow !== 'number') {
|
||||||
@@ -2571,6 +2574,12 @@ module.exports = {
|
|||||||
if (querytemp) {
|
if (querytemp) {
|
||||||
query = [...query, ...querytemp];
|
query = [...query, ...querytemp];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save the search:
|
||||||
|
if (user._id) {
|
||||||
|
const mysearch = new Search({idapp, userId: user._id, text: params.filter});
|
||||||
|
await mysearch.save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params.table === 'mygroups' || params.table === 'circuits') {
|
if (params.table === 'mygroups' || params.table === 'circuits') {
|
||||||
@@ -2718,8 +2727,9 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
SetBit(myval, bit) {
|
SetBit(myval, bit) {
|
||||||
myval = myval & bit;
|
let myvalout = myval
|
||||||
return myval;
|
myvalout |= bit
|
||||||
|
return myvalout
|
||||||
},
|
},
|
||||||
|
|
||||||
async snooze(ms) {
|
async snooze(ms) {
|
||||||
|
|||||||
@@ -362,6 +362,7 @@ module.exports = {
|
|||||||
NEW_ADV_MY_GROUPS: 8,
|
NEW_ADV_MY_GROUPS: 8,
|
||||||
NEW_ADV_MY_RIS_CIRCUIT: 16,
|
NEW_ADV_MY_RIS_CIRCUIT: 16,
|
||||||
NEW_ADV_SECTOR: 32,
|
NEW_ADV_SECTOR: 32,
|
||||||
|
NEW_ADV_YOUR_PROVINCE: 64,
|
||||||
},
|
},
|
||||||
|
|
||||||
StatusNotifs: {
|
StatusNotifs: {
|
||||||
@@ -404,6 +405,7 @@ module.exports = {
|
|||||||
TYPEDIR_BACHECA: 1,
|
TYPEDIR_BACHECA: 1,
|
||||||
ID_BACHECA_NEW_GOOD: 1,
|
ID_BACHECA_NEW_GOOD: 1,
|
||||||
ID_BACHECA_NEW_SERVICE: 2,
|
ID_BACHECA_NEW_SERVICE: 2,
|
||||||
|
ID_BACHECA_NEW_HOSP: 4,
|
||||||
|
|
||||||
TYPEDIR_EVENTS: 2,
|
TYPEDIR_EVENTS: 2,
|
||||||
ID_EVENTS_NEW_REC: 1,
|
ID_EVENTS_NEW_REC: 1,
|
||||||
@@ -513,7 +515,7 @@ module.exports = {
|
|||||||
DEFAULT_NOTIFS_USER: [
|
DEFAULT_NOTIFS_USER: [
|
||||||
{
|
{
|
||||||
'dir': 1,
|
'dir': 1,
|
||||||
'value': 24
|
'value': 88
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'dir': 2,
|
'dir': 2,
|
||||||
|
|||||||
Reference in New Issue
Block a user