From 29a57a3f40428787fc684519f31528c66659f6b9 Mon Sep 17 00:00:00 2001 From: divinedab Date: Wed, 24 Apr 2024 00:16:16 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Cleaned=20some=20things?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/notifications/notifications-router.ts | 6 ++++-- src/services/notifications/notifications-schema.ts | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) 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(), });