diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eaf0932..c233bec 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: - uses: actions/setup-node@v4 with: node-version: "18.x" - cache: 'yarn' + cache: "yarn" - name: Install dependencies run: yarn - name: Build diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 040636d..71c3e34 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -12,7 +12,7 @@ jobs: - uses: actions/setup-node@v4 with: node-version: "18.x" - cache: 'yarn' + cache: "yarn" - name: Install dependencies run: yarn - name: Run ESLint diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml index 701d6da..e27ed9e 100644 --- a/.github/workflows/prettier.yml +++ b/.github/workflows/prettier.yml @@ -12,7 +12,7 @@ jobs: - uses: actions/setup-node@v4 with: node-version: "18.x" - cache: 'yarn' + cache: "yarn" - name: Install dependencies run: yarn - name: Run Prettier diff --git a/src/database.ts b/src/database.ts index e555647..abc635c 100644 --- a/src/database.ts +++ b/src/database.ts @@ -14,7 +14,8 @@ import { SubscriptionSchema, } from "./services/subscription/subscription-schema"; import { - NotificationsSchema, NotificationsValidator + NotificationsSchema, + NotificationsValidator, } from "./services/notifications/notifications-schema"; mongoose.set("toObject", { versionKey: false }); @@ -60,5 +61,9 @@ export const Database = { RegistrationSchema, RegistrationValidator ), - NOTIFICATIONS: initializeModel("notifications", NotificationsSchema, NotificationsValidator), + NOTIFICATIONS: initializeModel( + "notifications", + NotificationsSchema, + NotificationsValidator + ), }; diff --git a/src/services/notifications/notifications-router.ts b/src/services/notifications/notifications-router.ts index 6b5fda9..9224c3f 100644 --- a/src/services/notifications/notifications-router.ts +++ b/src/services/notifications/notifications-router.ts @@ -9,24 +9,26 @@ const notificationsRouter = Router(); // Register user’s device identifier under their userId notificationsRouter.post( - "/", + "/", RoleChecker([Role.enum.USER], false), async (req, res, next) => { - try { - const notificationEnrollmentData = NotificationsValidator.parse(req.body); + try { + const notificationEnrollmentData = NotificationsValidator.parse( + req.body + ); - // Upsert the user-device mapping info - await Database.NOTIFICATIONS.findOneAndUpdate( - { userId: notificationEnrollmentData.userId }, - { deviceId: notificationEnrollmentData.deviceId }, - { upsert: true, new: true } - ); + // Upsert the user-device mapping info + await Database.NOTIFICATIONS.findOneAndUpdate( + { userId: notificationEnrollmentData.userId }, + { deviceId: notificationEnrollmentData.deviceId }, + { upsert: true, new: true } + ); - return res.status(StatusCodes.OK).json(notificationEnrollmentData); - - } catch (error) { - next(error); + return res.status(StatusCodes.OK).json(notificationEnrollmentData); + } catch (error) { + next(error); + } } -}); +); -export default notificationsRouter; \ No newline at end of file +export default notificationsRouter; diff --git a/src/services/notifications/notifications-schema.ts b/src/services/notifications/notifications-schema.ts index 0a81492..0bcea79 100644 --- a/src/services/notifications/notifications-schema.ts +++ b/src/services/notifications/notifications-schema.ts @@ -13,4 +13,4 @@ const NotificationsSchema = new mongoose.Schema({ deviceId: { type: String, required: true }, }); -export { NotificationsSchema, NotificationsValidator }; \ No newline at end of file +export { NotificationsSchema, NotificationsValidator };