2022-07-21 00:21:03 +02:00
|
|
|
const mongoose = require('mongoose').set('debug', false);
|
2022-07-10 01:25:19 +02:00
|
|
|
const Schema = mongoose.Schema;
|
|
|
|
|
|
|
|
|
|
mongoose.Promise = global.Promise;
|
2022-07-21 00:21:03 +02:00
|
|
|
mongoose.level = 'F';
|
2022-07-10 01:25:19 +02:00
|
|
|
|
2022-07-23 17:48:33 +02:00
|
|
|
const i18n = require('i18n');
|
|
|
|
|
|
2022-07-21 00:21:03 +02:00
|
|
|
const {ObjectID} = require('mongodb');
|
2022-07-10 01:25:19 +02:00
|
|
|
|
2022-07-23 17:48:33 +02:00
|
|
|
const shared_consts = require('../tools/shared_nodejs');
|
|
|
|
|
|
|
|
|
|
const globalTables = require('../tools/globalTables');
|
|
|
|
|
|
|
|
|
|
const tools = require('../tools/general');
|
|
|
|
|
|
2022-07-10 01:25:19 +02:00
|
|
|
// Resolving error Unknown modifier: $pushAll
|
|
|
|
|
mongoose.plugin(schema => {
|
2022-07-21 00:21:03 +02:00
|
|
|
schema.options.usePushEach = true;
|
2022-07-10 01:25:19 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const sendNotifSchema = new Schema({
|
|
|
|
|
idapp: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
2022-07-23 17:48:33 +02:00
|
|
|
typedir: {
|
|
|
|
|
type: Number,
|
|
|
|
|
},
|
|
|
|
|
typeid: {
|
2022-07-10 01:25:19 +02:00
|
|
|
type: Number,
|
|
|
|
|
},
|
|
|
|
|
sender: { // mittente
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
dest: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
2022-07-26 15:46:39 +02:00
|
|
|
title: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
2022-07-10 01:25:19 +02:00
|
|
|
descr: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
2022-07-23 17:48:33 +02:00
|
|
|
openUrl: {
|
2022-07-21 00:21:03 +02:00
|
|
|
type: String,
|
|
|
|
|
},
|
2022-07-10 01:25:19 +02:00
|
|
|
datenotif: {
|
|
|
|
|
type: Date,
|
|
|
|
|
},
|
|
|
|
|
status: {
|
|
|
|
|
type: Number,
|
|
|
|
|
},
|
|
|
|
|
read: {
|
|
|
|
|
type: Boolean,
|
2022-07-21 00:21:03 +02:00
|
|
|
default: false,
|
2022-07-10 01:25:19 +02:00
|
|
|
},
|
2022-07-23 17:48:33 +02:00
|
|
|
tablerec: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
idrec: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
2022-07-10 01:25:19 +02:00
|
|
|
deleted: {
|
|
|
|
|
type: Boolean,
|
2022-07-21 00:21:03 +02:00
|
|
|
default: false,
|
2022-07-10 01:25:19 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2022-07-21 00:21:03 +02:00
|
|
|
sendNotifSchema.statics.setNotifAsRead = function(idapp, username, idnotif) {
|
|
|
|
|
const SendNotif = this;
|
2022-07-10 01:25:19 +02:00
|
|
|
|
2022-07-21 00:21:03 +02:00
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
if (idnotif) {
|
|
|
|
|
return SendNotif.findOneAndUpdate({
|
|
|
|
|
$and: [
|
|
|
|
|
{idapp},
|
|
|
|
|
{dest: username},
|
|
|
|
|
{'_id': idnotif},
|
|
|
|
|
],
|
|
|
|
|
$or: [
|
|
|
|
|
{deleted: {$exists: false}},
|
|
|
|
|
{deleted: {$exists: true, $eq: false}}],
|
|
|
|
|
|
|
|
|
|
}, {$set: {read: true}}, {new: false}).then((ret) => {
|
|
|
|
|
return !!ret;
|
|
|
|
|
}).catch((err) => {
|
|
|
|
|
console.error('err', err);
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-07-23 17:48:33 +02:00
|
|
|
} catch (e) {
|
2022-07-21 00:21:03 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
2022-07-10 01:25:19 +02:00
|
|
|
|
2022-07-21 00:21:03 +02:00
|
|
|
sendNotifSchema.statics.findAllNotifByUsernameIdAndIdApp = function(username, lastdataread, idapp) {
|
2022-07-10 01:25:19 +02:00
|
|
|
const SendNotif = this;
|
|
|
|
|
|
|
|
|
|
return SendNotif.find({
|
|
|
|
|
$and: [
|
2022-07-21 00:21:03 +02:00
|
|
|
{idapp},
|
|
|
|
|
{'dest': username},
|
|
|
|
|
{'datenotif': {$gt: new Date(lastdataread)}},
|
|
|
|
|
],
|
2022-07-26 15:46:39 +02:00
|
|
|
}).lean().sort({datenotif: -1}).then(async (arrnotif) => {
|
2022-07-23 17:48:33 +02:00
|
|
|
// console.log('arrnotif', arrnotif.length);
|
2022-07-26 15:46:39 +02:00
|
|
|
|
|
|
|
|
return this.compileOtherFields(arrnotif);
|
|
|
|
|
|
2022-07-10 01:25:19 +02:00
|
|
|
}).catch((err) => {
|
|
|
|
|
console.error('err', err);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2022-07-23 17:48:33 +02:00
|
|
|
sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
|
|
|
|
|
|
2022-07-26 15:46:39 +02:00
|
|
|
const numchars = 80;
|
|
|
|
|
let newdescr = '';
|
|
|
|
|
let mydescr = '';
|
|
|
|
|
let myidrec = '';
|
|
|
|
|
let userorig = recnotif.sender;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (recnotif.myrectableorig) {
|
|
|
|
|
myidrec = recnotif.myrectableorig._id;
|
|
|
|
|
mydescr = recnotif.myrectableorig.descr ? tools.firstchars(recnotif.myrectableorig.descr, numchars) : '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
recnotif.openUrl = '/mygood/' + myidrec;
|
|
|
|
|
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_BACHECA_NEW_SERVICE) {
|
|
|
|
|
newdescr = i18n.__('<strong>%s</strong> new Service: %s', userorig, mydescr);
|
|
|
|
|
recnotif.openUrl = '/myservice/' + myidrec;
|
|
|
|
|
}
|
|
|
|
|
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_FRIENDS) {
|
|
|
|
|
recnotif.openUrl = '/my/' + userorig;
|
|
|
|
|
if (recnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_NEW_REC) {
|
|
|
|
|
newdescr = i18n.__('<strong>%s</strong> asked you for Friendship', userorig, mydescr);
|
|
|
|
|
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED) {
|
|
|
|
|
newdescr = i18n.__('<strong>%s</strong> accepted your Friendship', userorig, mydescr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!recnotif.descr) {
|
|
|
|
|
recnotif.descr = newdescr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return recnotif;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
sendNotifSchema.statics.compileOtherFields = async function(arrnotif) {
|
|
|
|
|
|
|
|
|
|
const {User} = require('../models/user');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// Fill in the image profile of the semyinders !
|
|
|
|
|
for (const notif of arrnotif) {
|
|
|
|
|
let myimgprofile = await User.findOne({idapp: notif.idapp, username: notif.sender}, {'profile.img': 1}).lean();
|
|
|
|
|
if (myimgprofile && myimgprofile.profile.img)
|
|
|
|
|
notif.myimgsender = 'upload/profile/' + notif.sender + '/' + myimgprofile.profile.img;
|
2022-07-23 17:48:33 +02:00
|
|
|
}
|
2022-07-26 15:46:39 +02:00
|
|
|
|
|
|
|
|
return arrnotif;
|
|
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
return arrnotif;
|
2022-07-23 17:48:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
sendNotifSchema.statics.findLastNotifsByUserIdAndIdApp = function(username, idapp, limit) {
|
2022-07-10 01:25:19 +02:00
|
|
|
const SendNotif = this;
|
|
|
|
|
|
|
|
|
|
return SendNotif.aggregate([
|
|
|
|
|
{
|
|
|
|
|
$match: {
|
|
|
|
|
idapp,
|
|
|
|
|
dest: username,
|
2022-07-21 00:21:03 +02:00
|
|
|
},
|
2022-07-10 01:25:19 +02:00
|
|
|
},
|
2022-07-23 17:48:33 +02:00
|
|
|
{$limit: limit},
|
2022-07-10 01:25:19 +02:00
|
|
|
{
|
2022-07-21 00:21:03 +02:00
|
|
|
$sort: {datenotif: -1},
|
2022-07-10 01:25:19 +02:00
|
|
|
},
|
2022-07-26 15:46:39 +02:00
|
|
|
]).then(async (arrnotif) => {
|
|
|
|
|
return this.compileOtherFields(arrnotif);
|
2022-07-10 01:25:19 +02:00
|
|
|
|
2022-07-21 00:21:03 +02:00
|
|
|
}).catch((err) => {
|
|
|
|
|
console.error(err);
|
|
|
|
|
});
|
2022-07-10 01:25:19 +02:00
|
|
|
|
2022-07-21 00:21:03 +02:00
|
|
|
};
|
2022-07-10 01:25:19 +02:00
|
|
|
|
2022-07-23 17:48:33 +02:00
|
|
|
sendNotifSchema.statics.saveAndSendNotif = function(myrecnotif, req, res, user) {
|
|
|
|
|
|
|
|
|
|
let idapp = req.body.idapp;
|
|
|
|
|
const check = tools.checkUserOk(myrecnotif.sender, user ? myrecnotif.sender : req.user.username, res);
|
|
|
|
|
if (check.exit) return check.ret;
|
|
|
|
|
|
|
|
|
|
myrecnotif._id = new ObjectID();
|
2022-07-26 15:46:39 +02:00
|
|
|
if (!myrecnotif.openUrl) {
|
|
|
|
|
// If not exist, then I set openUrl and description
|
|
|
|
|
myrecnotif = this.getDescrAndLinkByRecNotif(myrecnotif);
|
|
|
|
|
}
|
2022-07-23 17:48:33 +02:00
|
|
|
|
|
|
|
|
return myrecnotif.save().then((writeresult) => {
|
|
|
|
|
let idobj = writeresult._id;
|
|
|
|
|
|
|
|
|
|
myrecnotif._id = idobj;
|
|
|
|
|
|
|
|
|
|
return SendNotif.findById(idobj).lean().then(async (recnotif) => {
|
2022-07-26 15:46:39 +02:00
|
|
|
return await globalTables.sendNotif(myrecnotif.typedir, myrecnotif.typeid, res, idapp, user ? user : req.user, recnotif).
|
|
|
|
|
then((ris) => {
|
|
|
|
|
return recnotif;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
console.log(e.message);
|
|
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
sendNotifSchema.statics.saveNotif = function(myrecnotif) {
|
|
|
|
|
|
|
|
|
|
myrecnotif._id = new ObjectID();
|
|
|
|
|
if (!myrecnotif.openUrl) {
|
|
|
|
|
// If not exist, then I set openUrl and description
|
|
|
|
|
myrecnotif = this.getDescrAndLinkByRecNotif(myrecnotif);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return myrecnotif.save().then((writeresult) => {
|
|
|
|
|
let idobj = writeresult._id;
|
|
|
|
|
|
|
|
|
|
myrecnotif._id = idobj;
|
|
|
|
|
|
|
|
|
|
return SendNotif.findById(idobj).lean().then(async (recnotif) => {
|
|
|
|
|
return recnotif;
|
2022-07-23 17:48:33 +02:00
|
|
|
});
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
console.log(e.message);
|
|
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
sendNotifSchema.statics.getDefaultRec = function(req) {
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
idapp: req.body.idapp,
|
|
|
|
|
typedir: '',
|
|
|
|
|
typeid: '',
|
|
|
|
|
sender: req.user ? req.user.username : '',
|
|
|
|
|
dest: '',
|
|
|
|
|
descr: '',
|
|
|
|
|
openUrl: '',
|
|
|
|
|
datenotif: new Date(),
|
|
|
|
|
status: 0,
|
|
|
|
|
read: false,
|
2022-07-26 15:46:39 +02:00
|
|
|
tablerec: '',
|
|
|
|
|
idrec: 0,
|
2022-07-23 17:48:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
sendNotifSchema.statics.createNewNotification = async function(req, res, table, rec, typedir, typeid) {
|
|
|
|
|
const SendNotif = this;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
let myrecnotif = new SendNotif(this.getDefaultRec(req));
|
|
|
|
|
|
|
|
|
|
myrecnotif.tablerec = table;
|
2022-07-26 15:46:39 +02:00
|
|
|
if (rec && table) {
|
2022-07-23 17:48:33 +02:00
|
|
|
myrecnotif.idrec = rec._id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
myrecnotif.typedir = typedir;
|
|
|
|
|
myrecnotif.typeid = typeid;
|
|
|
|
|
|
|
|
|
|
await SendNotif.sendToTheDestinations(myrecnotif, req, res);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('createNewNotification', e);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-07-26 15:46:39 +02:00
|
|
|
sendNotifSchema.statics.createNewNotifToSingleUser = async function(req, res, usernameDest, onlysave, typedir, typeid) {
|
|
|
|
|
const SendNotif = this;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
let myrecnotif = new SendNotif(this.getDefaultRec(req));
|
|
|
|
|
|
|
|
|
|
myrecnotif.typedir = typedir;
|
|
|
|
|
myrecnotif.typeid = typeid;
|
|
|
|
|
|
|
|
|
|
await SendNotif.sendToSingleUserDest(myrecnotif, req, res, usernameDest, onlysave);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('createNewNotification', e);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-07-23 17:48:33 +02:00
|
|
|
sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotif, req, res) {
|
|
|
|
|
const SendNotif = this;
|
|
|
|
|
|
|
|
|
|
const {User} = require('../models/user');
|
|
|
|
|
|
|
|
|
|
const {City} = require('../models/city');
|
|
|
|
|
const {Province} = require('../models/province');
|
|
|
|
|
|
2022-07-26 15:46:39 +02:00
|
|
|
try {
|
2022-07-23 17:48:33 +02:00
|
|
|
|
2022-07-26 15:46:39 +02:00
|
|
|
// Send only to the destination to reach:
|
|
|
|
|
const userlist = await User.find({
|
|
|
|
|
idapp: myrecnotif.idapp,
|
|
|
|
|
$or: [
|
|
|
|
|
{deleted: {$exists: false}},
|
|
|
|
|
{deleted: {$exists: true, $eq: false}}],
|
|
|
|
|
}, {
|
|
|
|
|
name: 1,
|
|
|
|
|
surname: 1,
|
|
|
|
|
lang: 1,
|
|
|
|
|
username: 1,
|
|
|
|
|
'profile.notifs': 1,
|
|
|
|
|
'profile.notif_idCities': 1,
|
|
|
|
|
'profile.notif_provinces': 1,
|
|
|
|
|
'profile.notif_regions': 1,
|
|
|
|
|
'profile.notif_sectors': 1,
|
|
|
|
|
'profile.notif_sector_goods': 1,
|
|
|
|
|
}).lean();
|
|
|
|
|
|
|
|
|
|
let arrprovinces = [];
|
|
|
|
|
let arrregions = [];
|
|
|
|
|
let idSector = 0;
|
|
|
|
|
|
|
|
|
|
const mytable = globalTables.getTableByTableName(myrecnotif.tablerec);
|
|
|
|
|
|
|
|
|
|
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotif.tablerec) ||
|
|
|
|
|
shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotif.tablerec)) {
|
|
|
|
|
|
|
|
|
|
const myrectableorig = await mytable.findOne({_id: myrecnotif.idrec}).lean();
|
|
|
|
|
if (myrectableorig) {
|
|
|
|
|
for (const city of myrectableorig.idCity) {
|
|
|
|
|
arrprovinces.push(await City.getProvinceByIdCity(city));
|
|
|
|
|
arrregions.push(await City.getRegionByIdCity(city));
|
|
|
|
|
}
|
2022-07-23 17:48:33 +02:00
|
|
|
|
2022-07-26 15:46:39 +02:00
|
|
|
if (myrecnotif.tablerec === shared_consts.TABLES_MYGOODS) {
|
|
|
|
|
idSector = myrectableorig.idSectorGood;
|
|
|
|
|
} else {
|
|
|
|
|
idSector = myrectableorig.idSector;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
myrecnotif.myrectableorig = myrectableorig;
|
2022-07-23 17:48:33 +02:00
|
|
|
}
|
|
|
|
|
|
2022-07-26 15:46:39 +02:00
|
|
|
myrecnotif = this.getDescrAndLinkByRecNotif(myrecnotif);
|
2022-07-23 17:48:33 +02:00
|
|
|
|
2022-07-26 15:46:39 +02:00
|
|
|
for (const user of userlist) {
|
2022-07-23 17:48:33 +02:00
|
|
|
|
2022-07-26 15:46:39 +02:00
|
|
|
if (user.profile.notifs) {
|
|
|
|
|
const usernotifprofile = user.profile.notifs.find((notif) => notif.dir === myrecnotif.typedir);
|
2022-07-23 17:48:33 +02:00
|
|
|
|
2022-07-26 15:46:39 +02:00
|
|
|
let send = false;
|
2022-07-23 17:48:33 +02:00
|
|
|
|
2022-07-26 15:46:39 +02:00
|
|
|
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotif.tablerec) ||
|
|
|
|
|
shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotif.tablerec)) {
|
|
|
|
|
// Estrai la Città, la Provincia e la regione.
|
2022-07-23 17:48:33 +02:00
|
|
|
|
2022-07-26 15:46:39 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_REGION) &&
|
|
|
|
|
user.profile.notif_regions && user.profile.notif_regions.some(r => arrregions.indexOf(r) >= 0)) {
|
|
|
|
|
send = true;
|
|
|
|
|
}
|
2022-07-23 17:48:33 +02:00
|
|
|
|
2022-07-26 15:46:39 +02:00
|
|
|
if (idSector && usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_SECTOR)) {
|
|
|
|
|
// Controlla se è del settore selezionato
|
|
|
|
|
if (myrecnotif.tablerec === shared_consts.TABLES_MYGOODS) {
|
|
|
|
|
if (user.profile.notif_sector_goods) {
|
|
|
|
|
send = send && (user.profile.notif_sector_goods.includes(idSector));
|
|
|
|
|
}
|
|
|
|
|
} else if (user.profile.notif_sectors) {
|
|
|
|
|
send = send && (user.profile.notif_sectors.includes(idSector));
|
2022-07-23 17:48:33 +02:00
|
|
|
}
|
|
|
|
|
}
|
2022-07-26 15:46:39 +02:00
|
|
|
|
2022-07-23 17:48:33 +02:00
|
|
|
}
|
|
|
|
|
|
2022-07-26 15:46:39 +02:00
|
|
|
if (send) {
|
|
|
|
|
myrecnotif.dest = user.username;
|
|
|
|
|
await SendNotif.saveAndSendNotif(myrecnotif, req, res, user);
|
|
|
|
|
}
|
2022-07-23 17:48:33 +02:00
|
|
|
}
|
2022-07-26 15:46:39 +02:00
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('sendToTheDestinations', e);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-07-23 17:48:33 +02:00
|
|
|
|
2022-07-26 15:46:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
sendNotifSchema.statics.sendToSingleUserDest = async function(myrecnotif, req, res, usernameDest, onlysave) {
|
|
|
|
|
const SendNotif = this;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
myrecnotif = this.getDescrAndLinkByRecNotif(myrecnotif);
|
|
|
|
|
|
|
|
|
|
myrecnotif.dest = usernameDest;
|
|
|
|
|
if (onlysave) {
|
|
|
|
|
await SendNotif.saveNotif(myrecnotif);
|
|
|
|
|
} else {
|
|
|
|
|
await SendNotif.saveAndSendNotif(myrecnotif, req, res, user);
|
2022-07-23 17:48:33 +02:00
|
|
|
}
|
2022-07-26 15:46:39 +02:00
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('sendToSingleUserDest', e);
|
|
|
|
|
return false;
|
2022-07-23 17:48:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2022-07-10 01:25:19 +02:00
|
|
|
const SendNotif = mongoose.model('SendNotif', sendNotifSchema);
|
|
|
|
|
|
2022-07-21 00:21:03 +02:00
|
|
|
module.exports = {SendNotif: SendNotif};
|