feat: add query notification

This commit is contained in:
Methapon Metanipat 2024-10-30 13:48:18 +07:00 committed by Methapon2001
parent 2502b7c68f
commit b4b7d633d1

View file

@ -14,6 +14,9 @@ import {
} from "tsoa"; } from "tsoa";
import { RequestWithUser } from "../interfaces/user"; import { RequestWithUser } from "../interfaces/user";
import HttpStatus from "../interfaces/http-status"; import HttpStatus from "../interfaces/http-status";
import prisma from "../db";
import { Prisma } from "@prisma/client";
import { queryOrNot } from "../utils/relation";
type NotificationCreate = {}; type NotificationCreate = {};
type NotificationUpdate = {}; type NotificationUpdate = {};
@ -29,12 +32,31 @@ export class NotificationController extends Controller {
@Query() pageSize: number = 30, @Query() pageSize: number = 30,
@Query() query = "", @Query() query = "",
) { ) {
const total = 0; const where: Prisma.NotificationWhereInput = {
AND: [
// TODO: implement {
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 { return {
result: [], result,
page, page,
pageSize, pageSize,
total, total,