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";
|
} 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,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue