From 4ef29ad4db9e02568a0af0805fce85392734eecc Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Fri, 17 Jul 2026 18:23:08 +0700 Subject: [PATCH] fixed --- src/controllers/UserController.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index 86b44ef4..b5add4be 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -38,6 +38,8 @@ import { import { AppDataSource } from "../database/data-source"; import { Profile } from "../entities/Profile"; import { ProfileEmployee } from "../entities/ProfileEmployee"; +import { PosMaster } from "../entities/PosMaster"; +import { EmployeePosMaster } from "../entities/EmployeePosMaster"; import { RequestWithUser } from "../middlewares/user"; import HttpSuccess from "../interfaces/http-success"; import { Brackets, In, IsNull, Not } from "typeorm"; @@ -70,6 +72,8 @@ function stripLeadingSlash(str: string) { export class KeycloakController extends Controller { private profileRepo = AppDataSource.getRepository(Profile); private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee); + private posMasterRepository = AppDataSource.getRepository(PosMaster); + private employeePosMasterRepository = AppDataSource.getRepository(EmployeePosMaster); private roleKeycloakRepo = AppDataSource.getRepository(RoleKeycloak); @Get("user/{id}") @@ -367,7 +371,6 @@ export class KeycloakController extends Controller { if (!profileEmp) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); profileEmp.roleKeycloaks = profileEmp.roleKeycloaks.filter((x) => x.id != roleId); await this.profileEmpRepo.save(profileEmp); - profileId = profileEmp.id; } else { profile.roleKeycloaks = profile.roleKeycloaks.filter((x) => x.id != roleId); await this.profileRepo.save(profile); @@ -385,6 +388,17 @@ export class KeycloakController extends Controller { if (!result) throw new Error("Failed. Cannot remove user's role."); if (profileId) { + try { + await this.posMasterRepository + .createQueryBuilder() + .update(PosMaster) + .set({ authRoleId: '' }) + .where("current_holderId = :profileId", { profileId }) + .execute(); + } catch (error) { + console.error(`Failed to clear authRoleId on position records for profile ${profileId}:`, error); + } + let redisClient: any; let quitAsync: any; try {