set notif if service your province

This commit is contained in:
Surya Paolo
2023-04-13 13:46:48 +02:00
parent cada7aa0b6
commit cda0bff21f
7 changed files with 136 additions and 35 deletions

45
src/server/models/search.js Executable file
View 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 };

View File

@@ -182,14 +182,19 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_BACHECA) {
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;
tag = 'newgood';
} 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;
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) {
recnotif.openUrl = '/my/' + sender;
if (recnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_NEW_REC) {
@@ -882,6 +887,7 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass,
lang: 1,
username: 1,
'profile.notifs': 1,
'profile.resid_province': 1,
'profile.notif_idCities': 1,
'profile.notif_provinces': 1,
'profile.notif_regions': 1,
@@ -939,6 +945,10 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass,
shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
// 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) &&
user.profile.notif_provinces && user.profile.notif_provinces.some(r => arrprovinces.indexOf(r) >= 0)) {
send = true;

View File

@@ -4696,13 +4696,21 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, v
try {
try {
if (recUserSave && recUser.profile && recUser.profile.notifs && recUser.profile.notifs.length <= 0) {
recUser.profile.notifs = shared_consts.DEFAULT_NOTIFS_USER;
await recUserSave.save();
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 }});
}
} catch (e) {
console.error('Err addExtraInfo notifs ', e);
}
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);
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;
} catch (e) {
@@ -4808,9 +4799,48 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, v
};
UserSchema.statics.updateVersion = async function (userversion, recUser) {
const { MySkill } = require('../models/myskill');
const { MyGood } = require('../models/mygood');
const { City } = require('../models/city');
if (userversion < 603) {
recUser.profile.notifs.push( { dir: 11, value: 1 })
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 })
}
// 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 }});
}