feat: add query notification
This commit is contained in:
parent
2502b7c68f
commit
b4b7d633d1
1 changed files with 26 additions and 4 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue