fix emp temp and add script clear org dna at keycloak
This commit is contained in:
parent
b714dfe239
commit
49a8494a8d
3 changed files with 363 additions and 57 deletions
|
|
@ -187,6 +187,48 @@ export class KeycloakSyncController extends Controller {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear org DNA attributes for profiles (Admin only)
|
||||
*
|
||||
* @summary Clear org DNA attributes in Keycloak for given profiles (ADMIN)
|
||||
*
|
||||
* @description
|
||||
* This endpoint will:
|
||||
* - Clear all org DNA fields (orgRootDnaId, orgChild1-4DnaId) by setting them to empty strings
|
||||
* - Use when an employee leaves their position (current_holderId becomes null)
|
||||
*
|
||||
* @param {request} request Request body containing profileIds array and profileType
|
||||
*/
|
||||
@Post("clear-org-dna")
|
||||
async clearOrgDna(
|
||||
@Body() request: { profileIds: string[]; profileType: "PROFILE" | "PROFILE_EMPLOYEE" },
|
||||
) {
|
||||
const { profileIds, profileType } = request;
|
||||
|
||||
// Validate profileIds
|
||||
if (!profileIds || profileIds.length === 0) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "profileIds ต้องไม่ว่างเปล่า");
|
||||
}
|
||||
|
||||
// Validate profileType
|
||||
if (!["PROFILE", "PROFILE_EMPLOYEE"].includes(profileType)) {
|
||||
throw new HttpError(
|
||||
HttpStatus.BAD_REQUEST,
|
||||
"profileType ต้องเป็น PROFILE หรือ PROFILE_EMPLOYEE เท่านั้น",
|
||||
);
|
||||
}
|
||||
|
||||
const result = await this.keycloakAttributeService.clearOrgDnaAttributes(
|
||||
profileIds,
|
||||
profileType,
|
||||
);
|
||||
|
||||
return new HttpSuccess({
|
||||
message: "Clear org DNA attributes เสร็จสิ้น",
|
||||
...result,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Batch sync all users (Admin only)
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue