add function post retire data to exprofile system
This commit is contained in:
parent
648fb33cc2
commit
7423a4f8b5
1 changed files with 62 additions and 0 deletions
|
|
@ -168,3 +168,65 @@ async function getToken(ClientID: string, ClientSecret: string): Promise<string>
|
||||||
return Promise.reject({ message: "Error occurred", error });
|
return Promise.reject({ message: "Error occurred", error });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// function post retire data to exprofile system
|
||||||
|
export async function PostRetireToExprofile(
|
||||||
|
citizenID: string,
|
||||||
|
prefix: string,
|
||||||
|
firstName: string,
|
||||||
|
lastName: string,
|
||||||
|
retireYear: string,
|
||||||
|
positionName: string,
|
||||||
|
positionTypeName: string,
|
||||||
|
positionLevelName: string,
|
||||||
|
retireDate: Date,
|
||||||
|
organizeName: string, // child4Name child3Name child2Name child1Name rootName
|
||||||
|
retireTypeName: string, // เช่น เกษียณ, ขอโอนออก, ลาออก, ปลดออก, ไล่ออก, ...
|
||||||
|
) {
|
||||||
|
let retryCount = 0;
|
||||||
|
const maxRetries = 2;
|
||||||
|
|
||||||
|
while (retryCount < maxRetries) {
|
||||||
|
try {
|
||||||
|
const token = await getToken(clientId, clientSecret);
|
||||||
|
|
||||||
|
if (!token) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถขอ Token ได้");
|
||||||
|
}
|
||||||
|
|
||||||
|
const scope = "importOfficerRetireData";
|
||||||
|
const body = {
|
||||||
|
scope: scope,
|
||||||
|
data: {
|
||||||
|
citizenID: citizenID,
|
||||||
|
prenameTH: prefix,
|
||||||
|
firstNameTH: firstName,
|
||||||
|
lastNameTH: lastName,
|
||||||
|
retireYear,
|
||||||
|
positionNameTH: positionName,
|
||||||
|
positionTypeNameTH: positionTypeName,
|
||||||
|
positionLevelNameTH: positionLevelName,
|
||||||
|
retireDate,
|
||||||
|
organizeNameTH: organizeName,
|
||||||
|
retireTypeNameTH: retireTypeName,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const res = await axios.post(API_URL_BANGKOK + "/importData", body, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.data;
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error.response?.status === 500 && retryCount < maxRetries - 1) {
|
||||||
|
TokenCache.delete(`${clientId}:${clientSecret}`);
|
||||||
|
retryCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ไม่สามารถติดต่อ API ได้");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue