UNPKG

@replyke/express

Version:

Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.

28 lines (27 loc) 1.16 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = createNotification; const validateNotificationParams_1 = __importDefault(require("./validateNotificationParams")); const models_1 = require("../models"); const broadcastNotificationCreated_1 = __importDefault(require("./webhooks/broadcastNotificationCreated")); async function createNotification(req, res, params) { setImmediate(async () => { if (!(0, validateNotificationParams_1.default)(params)) { console.error(`Invalid notification data for type: ${params.type}`); return; } // In production this should be active. if (params.userId === params.metadata.initiatorId) return; try { await models_1.AppNotification.create(params); await (0, broadcastNotificationCreated_1.default)(req, res, params); } catch (error) { console.error("Error creating notification:", error); } }); }