refactor: response result
This commit is contained in:
parent
34af1f9dcd
commit
53c0c0fce9
1 changed files with 13 additions and 2 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue