From 53c0c0fce9cdc6f67f1632fa5b27f5dc03e4656f Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 5 Mar 2025 11:04:21 +0700 Subject: [PATCH] refactor: response result --- src/controllers/00-notification-controller.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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,