This commit is contained in:
parent
880c249975
commit
4ef29ad4db
1 changed files with 15 additions and 1 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue