diff --git a/src/controllers/00-notification-controller.ts b/src/controllers/00-notification-controller.ts index 0e27847..ee20e50 100644 --- a/src/controllers/00-notification-controller.ts +++ b/src/controllers/00-notification-controller.ts @@ -18,6 +18,7 @@ import prisma from "../db"; import { Prisma } from "@prisma/client"; import { queryOrNot } from "../utils/relation"; import { notFoundError } from "../utils/error"; +import dayjs from "dayjs"; type NotificationCreate = {}; type NotificationUpdate = {}; @@ -50,14 +51,24 @@ export class NotificationController extends Controller { ], }, ], + NOT: { + readByUser: { some: { id: req.user.sub } }, + createdAt: dayjs().subtract(7, "days").toDate(), + }, }; const [result, total] = await prisma.$transaction([ - prisma.notification.findMany({ where }), + prisma.notification.findMany({ where, include: { readByUser: true } }), prisma.notification.count({ where }), ]); return { - result, + result: result.map((v) => ({ + id: v.id, + title: v.title, + detail: v.detail, + createdAt: v.createdAt, + read: v.readByUser.some((v) => v.id === req.user.sub), + })), page, pageSize, total,