From b177c0f7533a3cc1103e1b8a609d45e491ddf27d Mon Sep 17 00:00:00 2001 From: Kai Patragnoni Date: Fri, 21 Nov 2025 14:07:44 -0500 Subject: [PATCH 1/2] Add markAsRead endpoint --- src/api/controllers/NotifController.ts | 5 +++++ src/services/NotifService.ts | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/api/controllers/NotifController.ts b/src/api/controllers/NotifController.ts index 94650a8..48b6533 100644 --- a/src/api/controllers/NotifController.ts +++ b/src/api/controllers/NotifController.ts @@ -46,6 +46,11 @@ export class NotifController { return this.notifService.sendRequestMatchNotification(matchRequest); } + @Post('markAsRead/id/:id') + async markAsRead(@CurrentUser() user: UserModel, @Params() params: { id: string }) { + return this.notifService.markAsRead(user.firebaseUid, params.id); + } + @Delete('id/:id') async deleteNotification(@CurrentUser() user: UserModel, @Params() params: { id: string }) { return this.notifService.deleteNotification(user.firebaseUid, params.id); diff --git a/src/services/NotifService.ts b/src/services/NotifService.ts index f95e58e..d89121d 100644 --- a/src/services/NotifService.ts +++ b/src/services/NotifService.ts @@ -275,6 +275,20 @@ export class NotifService { }); } + async markAsRead(userId: string, notifId: string) { + return this.transactions.readWrite(async (transactionalEntityManager) => { + const notifRepository = Repositories.notification(transactionalEntityManager); + const notif = await notifRepository.findOne({ where: { id: notifId } }); + if (!notif) { + throw new NotFoundError("Notification not found"); + } + if (notif.userId !== userId) { + throw new NotFoundError("Notification not found"); + } + return await notifRepository.markAsRead(notifId); + }); + } + async deleteNotification(userId: string, notifId: string) { return this.transactions.readWrite(async (transactionalEntityManager) => { const notifRepository = Repositories.notification(transactionalEntityManager); From a1c3d6f492f1892fc209ec6847190a40d906ccaa Mon Sep 17 00:00:00 2001 From: Kai Patragnoni Date: Fri, 21 Nov 2025 14:12:17 -0500 Subject: [PATCH 2/2] Added markAsRead to swagger docs --- swagger.json | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/swagger.json b/swagger.json index f6fa5c3..fd8d5ce 100644 --- a/swagger.json +++ b/swagger.json @@ -1462,6 +1462,38 @@ } } }, + "/notif/markAsRead/id/{id}": { + "post": { + "summary": "Mark notification as read", + "tags": ["Notification"], + "security": [{ "bearerAuth": [] }], + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "schema": { + "type": "string", + "format": "uuid" + }, + "description": "Notification ID" + } + ], + "responses": { + "200": { + "description": "Notification marked as read successfully", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Notification" } + } + } + }, + "404": { + "description": "Notification not found" + } + } + } + }, "/request": { "get": { "tags": ["Request"],