feat: mark read endpoint
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 6s

This commit is contained in:
Methapon2001 2025-03-05 15:17:23 +07:00
parent c0bc31714e
commit 071262a85a

View file

@ -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}")