From 09c47361f1aabb6b95b779154df15f9af2ac7556 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 17 Jul 2024 16:35:50 +0700 Subject: [PATCH] fix search --- .../ProfileChangeNameController.ts | 28 +++++++++---------- src/controllers/ProfileController.ts | 8 ++++++ src/controllers/ProfileEmployeeController.ts | 3 +- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/controllers/ProfileChangeNameController.ts b/src/controllers/ProfileChangeNameController.ts index f963c424..f4238fe1 100644 --- a/src/controllers/ProfileChangeNameController.ts +++ b/src/controllers/ProfileChangeNameController.ts @@ -147,13 +147,13 @@ export class ProfileChangeNameController extends Controller { profile.prefix = body.prefix ?? profile.prefix; await this.profileRepository.save(profile); - // ปิดไว้ก่อนเพราะ error ต้องใช้ keycloak ที่มีสิทธิ์ในการ update - // if (profile != null && profile.keycloak != null) { - // const result = await updateName(profile.keycloak, profile.firstName, profile.lastName); - // if (!result) { - // throw new Error(result.errorMessage); - // } - // } + // ปิดไว้ก่อนเพราะ error ต้องใช้ keycloak ที่มีสิทธิ์ในการ update //update 17/07 + if (profile != null && profile.keycloak != null) { + const result = await updateName(profile.keycloak, profile.firstName, profile.lastName); + if (!result) { + throw new Error(result.errorMessage); + } + } return new HttpSuccess(data.id); } @@ -200,13 +200,13 @@ export class ProfileChangeNameController extends Controller { await this.profileRepository.save(profile); } - // ปิดไว้ก่อนเพราะ error ต้องใช้ keycloak ที่มีสิทธิ์ในการ update - // if (profile != null && profile.keycloak != null) { - // const result = await updateName(profile.keycloak, profile.firstName, profile.lastName); - // if (!result) { - // throw new Error(result.errorMessage); - // } - // } + // ปิดไว้ก่อนเพราะ error ต้องใช้ keycloak ที่มีสิทธิ์ในการ update //update 17/07 + if (profile != null && profile.keycloak != null) { + const result = await updateName(profile.keycloak, profile.firstName, profile.lastName); + if (!result) { + throw new Error(result.errorMessage); + } + } return new HttpSuccess(); } diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 8825a413..d57fe4cb 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -57,6 +57,7 @@ import { Prefixe } from "../entities/Prefixe"; import { ProfileInsignia } from "../entities/ProfileInsignia"; import { ProfileDisciplineHistory } from "../entities/ProfileDisciplineHistory"; import { ProfileLeave } from "../entities/ProfileLeave"; +import { updateName } from "../keycloak"; @Route("api/v1/org/profile") @Tags("Profile") @@ -2321,6 +2322,13 @@ export class ProfileController extends Controller { record.dateRetireLaw = calculateRetireLaw(record.birthDate); await this.profileRepo.save(record); + if (record != null && record.keycloak != null) { + const result = await updateName(record.keycloak, record.firstName, record.lastName); + if (!result) { + throw new Error(result.errorMessage); + } + } + return new HttpSuccess(); } diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 1dcbb224..a5e65b86 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -1329,7 +1329,8 @@ export class ProfileEmployeeController extends Controller { .map((x) => x.next_holderId), }); }), - ) + ) + .andWhere("profileEmployee.employeeClass = :employeeClass", {employeeClass:"PERM"}) .skip((requestBody.page - 1) * requestBody.pageSize) .take(requestBody.pageSize) .getManyAndCount();