feat: add permission query to noti

This commit is contained in:
Methapon2001 2025-03-05 11:16:18 +07:00
parent 53c0c0fce9
commit f0db968b20
2 changed files with 16 additions and 4 deletions

View file

@ -21,6 +21,9 @@ model Notification {
groupReceiver NotificationGroup[] groupReceiver NotificationGroup[]
registeredBranchId String?
registeredBranch Branch? @relation(fields: [registeredBranchId], references: [id])
receiver User? @relation(name: "NotificationReceiver", fields: [receiverId], references: [id], onDelete: Cascade) receiver User? @relation(name: "NotificationReceiver", fields: [receiverId], references: [id], onDelete: Cascade)
receiverId String? receiverId String?
@ -313,6 +316,7 @@ model Branch {
quotation Quotation[] quotation Quotation[]
workflowTemplate WorkflowTemplate[] workflowTemplate WorkflowTemplate[]
taskOrder TaskOrder[] taskOrder TaskOrder[]
notification Notification[]
} }
model BranchBank { model BranchBank {

View file

@ -19,10 +19,14 @@ import { Prisma } from "@prisma/client";
import { queryOrNot } from "../utils/relation"; import { queryOrNot } from "../utils/relation";
import { notFoundError } from "../utils/error"; import { notFoundError } from "../utils/error";
import dayjs from "dayjs"; import dayjs from "dayjs";
import HttpError from "../interfaces/http-error";
import { createPermCondition } from "../services/permission";
type NotificationCreate = {}; type NotificationCreate = {};
type NotificationUpdate = {}; type NotificationUpdate = {};
const permissionCondCompany = createPermCondition((_) => true);
@Route("/api/v1/notification") @Route("/api/v1/notification")
@Tags("Notification") @Tags("Notification")
export class NotificationController extends Controller { export class NotificationController extends Controller {
@ -46,7 +50,10 @@ export class NotificationController extends Controller {
OR: [ OR: [
{ receiverId: req.user.sub }, { receiverId: req.user.sub },
req.user.roles.length > 0 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) { async createNotification(@Request() req: RequestWithUser, @Body() body: NotificationCreate) {
// TODO: implement // TODO: implement
this.setStatus(HttpStatus.CREATED); // this.setStatus(HttpStatus.CREATED);
return {};
throw new HttpError(HttpStatus.NOT_IMPLEMENTED, "Not implemented.", "notImplemented");
} }
@Put("{notificationId}") @Put("{notificationId}")
@ -110,7 +118,7 @@ export class NotificationController extends Controller {
) { ) {
// TODO: implement // TODO: implement
return {}; throw new HttpError(HttpStatus.NOT_IMPLEMENTED, "Not implemented.", "notImplemented");
} }
@Delete("{notificationId}") @Delete("{notificationId}")