From c5b54d55dee13afb6e2e5aaa931bb1131918f0f6 Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Sun, 28 Sep 2025 14:24:46 +0700 Subject: [PATCH] api add permission org --- src/controllers/OrganizationController.ts | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 20511811..5ad7c11c 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -30,6 +30,7 @@ import { checkQueueInProgress, setLogDataDiff } from "../interfaces/utils"; import { sendToQueueOrg, sendToQueueOrgDraft } from "../services/rabbitmq"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; +import { PermissionOrg } from "../entities/PermissionOrg"; @Route("api/v1/org") @Tags("Organization") @@ -49,6 +50,7 @@ export class OrganizationController extends Controller { private profileRepo = AppDataSource.getRepository(Profile); private posTypeRepository = AppDataSource.getRepository(PosType); private posLevelRepository = AppDataSource.getRepository(PosLevel); + private permissionOrgRepository = AppDataSource.getRepository(PermissionOrg); /** * API ล้างข้อมูล @@ -7869,4 +7871,48 @@ export class OrganizationController extends Controller { posLevelNameOrder: posLevel.map((x) => x.posLevelName), }); } + + /** + * API เพิ่มสิทธิ์โครงสร้าง + * + * @summary - เพิ่มสิทธิ์โครงสร้าง (ADMIN) + * + */ + @Get("root/add/permission/{child1Id}") + async addRootPermission(@Path() child1Id: string, @Request() request: RequestWithUser) { + const profiles = await this.profileRepo.find({ + where: { + keycloak: Not(IsNull()), + current_holders: { + orgChild1Id: child1Id, + }, + }, + }); + const orgRoots = await this.orgRootRepository.find({ + where: { + orgRevision: { + orgRevisionIsDraft: true, + orgRevisionIsCurrent: false, + }, + }, + }); + + for await (const root of orgRoots) { + const _permissionOrg = profiles.map((profile) => { + const permission = new PermissionOrg(); + permission.orgRootId = root.id; + permission.profileId = profile.id; + permission.createdUserId = request.user.sub; + permission.createdFullName = request.user.name; + permission.lastUpdateUserId = request.user.sub; + permission.lastUpdateFullName = request.user.name; + permission.createdAt = new Date(); + permission.lastUpdatedAt = new Date(); + return permission; + }); + await this.permissionOrgRepository.save(_permissionOrg); + } + + return new HttpSuccess(); + } }