diff --git a/src/controllers/00-notification-controller.ts b/src/controllers/00-notification-controller.ts index a2034de..d8285f4 100644 --- a/src/controllers/00-notification-controller.ts +++ b/src/controllers/00-notification-controller.ts @@ -99,26 +99,36 @@ export class NotificationController extends Controller { return record; } - @Post() + @Post("notification/mark-read") @Security("keycloak") - async createNotification(@Request() req: RequestWithUser, @Body() body: NotificationCreate) { - // TODO: implement + async markRead(@Request() req: RequestWithUser, @Body() body?: { id: string[] }) { + const record = await prisma.notification.findMany({ + where: { + id: body ? { in: body.id } : undefined, + OR: !body + ? [ + { receiverId: req.user.sub }, + req.user.roles.length > 0 + ? { + groupReceiver: { some: { name: { in: req.user.roles } } }, + registeredBranch: { OR: permissionCondCompany(req.user) }, + } + : {}, + ] + : undefined, + }, + }); - // this.setStatus(HttpStatus.CREATED); - - throw new HttpError(HttpStatus.NOT_IMPLEMENTED, "Not implemented.", "notImplemented"); - } - - @Put("{notificationId}") - @Security("keycloak") - async updateNotification( - @Request() req: RequestWithUser, - @Path() notificationId: string, - @Body() body: NotificationUpdate, - ) { - // TODO: implement - - throw new HttpError(HttpStatus.NOT_IMPLEMENTED, "Not implemented.", "notImplemented"); + await prisma.$transaction( + record.map((v) => + prisma.notification.update({ + where: { id: v.id }, + data: { + readByUser: { connect: { id: req.user.sub } }, + }, + }), + ), + ); } @Delete("{notificationId}")