diff --git a/src/controllers/00-notification-controller.ts b/src/controllers/00-notification-controller.ts index 1718e04..4fdfce8 100644 --- a/src/controllers/00-notification-controller.ts +++ b/src/controllers/00-notification-controller.ts @@ -14,6 +14,9 @@ import { } from "tsoa"; import { RequestWithUser } from "../interfaces/user"; import HttpStatus from "../interfaces/http-status"; +import prisma from "../db"; +import { Prisma } from "@prisma/client"; +import { queryOrNot } from "../utils/relation"; type NotificationCreate = {}; type NotificationUpdate = {}; @@ -29,12 +32,31 @@ export class NotificationController extends Controller { @Query() pageSize: number = 30, @Query() query = "", ) { - const total = 0; - - // TODO: implement + const where: Prisma.NotificationWhereInput = { + AND: [ + { + OR: queryOrNot<(typeof where)[]>(query, [ + { title: { contains: query } }, + { detail: { contains: query } }, + ]), + }, + { + OR: [ + { receiverId: req.user.sub }, + req.user.roles.length > 0 + ? { groupReceiver: { some: { name: { in: req.user.roles } } } } + : {}, + ], + }, + ], + }; + const [result, total] = await prisma.$transaction([ + prisma.notification.findMany({ where }), + prisma.notification.count({ where }), + ]); return { - result: [], + result, page, pageSize, total,