diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 32cc5881..61db3922 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -2589,7 +2589,13 @@ export class CommandController extends Controller { } //ถ้ามีอยู่แล้วให้ใช้อันเดิม else { - // const _roleKeycloaks = await getRoleMappings(checkUser[0].id); + const rolesData = await getRoleMappings(checkUser[0].id); + if(rolesData) { + const _roleKeycloak = await this.roleKeycloakRepo.find({ + where: { name: In(rolesData.map((x:any) => x.name)) } + }); + profile.roleKeycloaks = _roleKeycloak && _roleKeycloak.length > 0 ? _roleKeycloak : []; + } profile.keycloak = checkUser[0].id; } profile.amount = item.amount ?? _null; @@ -3942,6 +3948,13 @@ export class CommandController extends Controller { profile.keycloak = userKeycloakId && typeof userKeycloakId === "string" ? userKeycloakId : ""; } else { + const rolesData = await getRoleMappings(checkUser[0].id); + if(rolesData) { + const _roleKeycloak = await this.roleKeycloakRepo.find({ + where: { name: In(rolesData.map((x:any) => x.name)) } + }); + profile.roleKeycloaks = _roleKeycloak && _roleKeycloak.length > 0 ? _roleKeycloak : []; + } profile.keycloak = checkUser[0].id; } @@ -4339,6 +4352,13 @@ export class CommandController extends Controller { // End Create Keycloak } else { + const rolesData = await getRoleMappings(checkUser[0].id); + if(rolesData) { + const _roleKeycloak = await this.roleKeycloakRepo.find({ + where: { name: In(rolesData.map((x:any) => x.name)) } + }); + profile.roleKeycloaks = _roleKeycloak && _roleKeycloak.length > 0 ? _roleKeycloak : []; + } profile.keycloak = checkUser[0].id; }