dry-node
Version:
Initialiseur de structure Node Express typée et modulaire
44 lines (35 loc) • 1.52 kB
JavaScript
const DryFormatDateFunction = require("./dry-format-date.function");
const DryNotificationTypeModel = require("../../dry-module/dry-group-event/dry-notification/model/dry-notification-type.model");
const DryNotificationModel = require("../../dry-module/dry-group-event/dry-notification/model/dry-notification.model");
async function DrySaveNotification(idNotificationType, user) {
let notification = {};
notification.notificationType = await DryNotificationTypeModel.findOne({
id: idNotificationType,
});
/** new connexion ${date} **/
if (notification?.notificationType?.id === 2) {
let date = " " + DryFormatDateFunction(new Date());
notification.message = notification.notificationType.message.replace(
"${date}",
date
);
} else if (notification.notificationType?.id === 8) {
/** Profile consulté ${user} **/
} else if (notification.notificationType?.id === 15) {
/** vaccin rappel ${vaccinName= ${vaccinDate} **/
} else if (notification.notificationType?.id === 16) {
/** booking rappel ${bookingDate} **/
} else {
notification.message = notification.notificationType?.message;
}
notification.user = user._id;
notification.label = notification.notificationType?.label;
notification.icon = notification.notificationType?.icon;
notification.isRead = false;
try {
await DryNotificationModel.create(notification);
} catch (e) {
console.error(e);
}
}
module.exports = DrySaveNotification;