diff --git a/src/services/notifications/notifications-router.ts b/src/services/notifications/notifications-router.ts index 9224c3f..9249e18 100644 --- a/src/services/notifications/notifications-router.ts +++ b/src/services/notifications/notifications-router.ts @@ -10,16 +10,18 @@ const notificationsRouter = Router(); // Register user’s device identifier under their userId notificationsRouter.post( "/", - RoleChecker([Role.enum.USER], false), + RoleChecker([Role.enum.USER]), async (req, res, next) => { try { const notificationEnrollmentData = NotificationsValidator.parse( req.body ); + const payload = res.locals.payload; + // Upsert the user-device mapping info await Database.NOTIFICATIONS.findOneAndUpdate( - { userId: notificationEnrollmentData.userId }, + { userId: payload.userId }, { deviceId: notificationEnrollmentData.deviceId }, { upsert: true, new: true } ); diff --git a/src/services/notifications/notifications-schema.ts b/src/services/notifications/notifications-schema.ts index 0bcea79..ab04c4f 100644 --- a/src/services/notifications/notifications-schema.ts +++ b/src/services/notifications/notifications-schema.ts @@ -3,7 +3,7 @@ import { z } from "zod"; // Zod schema for notifications const NotificationsValidator = z.object({ - userId: z.string(), + userId: z.coerce.string().regex(/user[0-9]*/), deviceId: z.string(), });