From f0db968b20b453ea9a1335b6d263a9dae8d706bf Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 5 Mar 2025 11:16:18 +0700 Subject: [PATCH] feat: add permission query to noti --- prisma/schema.prisma | 4 ++++ src/controllers/00-notification-controller.ts | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 5cfd276..671b21d 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -21,6 +21,9 @@ model Notification { groupReceiver NotificationGroup[] + registeredBranchId String? + registeredBranch Branch? @relation(fields: [registeredBranchId], references: [id]) + receiver User? @relation(name: "NotificationReceiver", fields: [receiverId], references: [id], onDelete: Cascade) receiverId String? @@ -313,6 +316,7 @@ model Branch { quotation Quotation[] workflowTemplate WorkflowTemplate[] taskOrder TaskOrder[] + notification Notification[] } model BranchBank { diff --git a/src/controllers/00-notification-controller.ts b/src/controllers/00-notification-controller.ts index ee20e50..00baff7 100644 --- a/src/controllers/00-notification-controller.ts +++ b/src/controllers/00-notification-controller.ts @@ -19,10 +19,14 @@ import { Prisma } from "@prisma/client"; import { queryOrNot } from "../utils/relation"; import { notFoundError } from "../utils/error"; import dayjs from "dayjs"; +import HttpError from "../interfaces/http-error"; +import { createPermCondition } from "../services/permission"; type NotificationCreate = {}; type NotificationUpdate = {}; +const permissionCondCompany = createPermCondition((_) => true); + @Route("/api/v1/notification") @Tags("Notification") export class NotificationController extends Controller { @@ -46,7 +50,10 @@ export class NotificationController extends Controller { OR: [ { receiverId: req.user.sub }, req.user.roles.length > 0 - ? { groupReceiver: { some: { name: { in: req.user.roles } } } } + ? { + groupReceiver: { some: { name: { in: req.user.roles } } }, + registeredBranch: { OR: permissionCondCompany(req.user) }, + } : {}, ], }, @@ -97,8 +104,9 @@ export class NotificationController extends Controller { async createNotification(@Request() req: RequestWithUser, @Body() body: NotificationCreate) { // TODO: implement - this.setStatus(HttpStatus.CREATED); - return {}; + // this.setStatus(HttpStatus.CREATED); + + throw new HttpError(HttpStatus.NOT_IMPLEMENTED, "Not implemented.", "notImplemented"); } @Put("{notificationId}") @@ -110,7 +118,7 @@ export class NotificationController extends Controller { ) { // TODO: implement - return {}; + throw new HttpError(HttpStatus.NOT_IMPLEMENTED, "Not implemented.", "notImplemented"); } @Delete("{notificationId}")