feat(ExRetirment):get document
This commit is contained in:
parent
6fab6c724e
commit
0300e61be5
1 changed files with 35 additions and 1 deletions
|
|
@ -68,7 +68,8 @@ export class ExRetirementController extends Controller {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถขอ Token ได้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถขอ Token ได้");
|
||||||
}
|
}
|
||||||
|
|
||||||
const scope = requestBody.type === "officer" ? "getOfficerRetireData" : "";
|
// const scope = requestBody.type === "officer" ? "getOfficerRetireData" : "";
|
||||||
|
const scope = "getOfficerRetireData";
|
||||||
const startRecord = requestBody.page !== 1 ? (requestBody.page - 1) * 25 : 0;
|
const startRecord = requestBody.page !== 1 ? (requestBody.page - 1) * 25 : 0;
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
@ -78,6 +79,7 @@ export class ExRetirementController extends Controller {
|
||||||
formData.append("citizenID", requestBody.citizenID);
|
formData.append("citizenID", requestBody.citizenID);
|
||||||
formData.append("firstNameTH", requestBody.firstNameTH);
|
formData.append("firstNameTH", requestBody.firstNameTH);
|
||||||
formData.append("lastNameTH", requestBody.lastNameTH);
|
formData.append("lastNameTH", requestBody.lastNameTH);
|
||||||
|
formData.append("officerTypeID", requestBody.type === "officer" ? "1" : "2");
|
||||||
|
|
||||||
const res = await axios.post(API_URL_BANGKOK + "/getData", formData, {
|
const res = await axios.post(API_URL_BANGKOK + "/getData", formData, {
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -96,6 +98,38 @@ export class ExRetirementController extends Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get("/document/{documentId}")
|
||||||
|
async getDocument(@Path("documentId") officerDocumentID: 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 formData = new FormData();
|
||||||
|
formData.append("scope", "getOfficerRetireFile");
|
||||||
|
formData.append("officerDocumentID", officerDocumentID);
|
||||||
|
|
||||||
|
const res = await axios.post(API_URL_BANGKOK + "/getData", formData, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
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 ได้");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getToken(ClientID: string, ClientSecret: string): Promise<string> {
|
async function getToken(ClientID: string, ClientSecret: string): Promise<string> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue