Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/api/controllers/NotifController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions src/services/NotifService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
32 changes: 32 additions & 0 deletions swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
Loading