2024-10-29 15:21:09 +07:00
|
|
|
import {
|
|
|
|
|
Body,
|
|
|
|
|
Controller,
|
|
|
|
|
Delete,
|
|
|
|
|
Get,
|
|
|
|
|
Path,
|
|
|
|
|
Post,
|
|
|
|
|
Put,
|
|
|
|
|
Query,
|
|
|
|
|
Request,
|
|
|
|
|
Route,
|
|
|
|
|
Security,
|
|
|
|
|
Tags,
|
|
|
|
|
} from "tsoa";
|
|
|
|
|
import { RequestWithUser } from "../interfaces/user";
|
|
|
|
|
import HttpStatus from "../interfaces/http-status";
|
2024-10-30 13:48:18 +07:00
|
|
|
import prisma from "../db";
|
|
|
|
|
import { Prisma } from "@prisma/client";
|
|
|
|
|
import { queryOrNot } from "../utils/relation";
|
2024-10-29 15:21:09 +07:00
|
|
|
|
|
|
|
|
type NotificationCreate = {};
|
|
|
|
|
type NotificationUpdate = {};
|
|
|
|
|
|
|
|
|
|
@Route("/api/v1/notification")
|
|
|
|
|
@Tags("Notification")
|
|
|
|
|
export class NotificationController extends Controller {
|
|
|
|
|
@Get()
|
|
|
|
|
@Security("keycloak")
|
|
|
|
|
async getNotificationList(
|
|
|
|
|
@Request() req: RequestWithUser,
|
|
|
|
|
@Query() page: number = 1,
|
|
|
|
|
@Query() pageSize: number = 30,
|
|
|
|
|
@Query() query = "",
|
|
|
|
|
) {
|
2024-10-30 13:48:18 +07:00
|
|
|
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 }),
|
|
|
|
|
]);
|
2024-10-29 15:21:09 +07:00
|
|
|
|
|
|
|
|
return {
|
2024-10-30 13:48:18 +07:00
|
|
|
result,
|
2024-10-29 15:21:09 +07:00
|
|
|
page,
|
|
|
|
|
pageSize,
|
|
|
|
|
total,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get("{notificationId}")
|
|
|
|
|
@Security("keycloak")
|
|
|
|
|
async getNotification(@Request() req: RequestWithUser, @Path() notificationId: string) {
|
|
|
|
|
// TODO: implement
|
|
|
|
|
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post()
|
|
|
|
|
@Security("keycloak")
|
|
|
|
|
async createNotification(@Request() req: RequestWithUser, @Body() body: NotificationCreate) {
|
|
|
|
|
// TODO: implement
|
|
|
|
|
|
|
|
|
|
this.setStatus(HttpStatus.CREATED);
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Put("{notificationId}")
|
|
|
|
|
@Security("keycloak")
|
|
|
|
|
async updateNotification(
|
|
|
|
|
@Request() req: RequestWithUser,
|
|
|
|
|
@Path() notificationId: string,
|
|
|
|
|
@Body() body: NotificationUpdate,
|
|
|
|
|
) {
|
|
|
|
|
// TODO: implement
|
|
|
|
|
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Delete("{notificationId}")
|
|
|
|
|
@Security("keycloak")
|
|
|
|
|
async deleteNotification(@Request() req: RequestWithUser, @Path() notificationId: string) {
|
|
|
|
|
// TODO: implement
|
|
|
|
|
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
}
|