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}")