diff --git a/src/app.ts b/src/app.ts index 7f0e0220..e919c0f7 100644 --- a/src/app.ts +++ b/src/app.ts @@ -66,7 +66,9 @@ async function main() { } }); - const cronTime_Oct = "0 0 1 10 *"; + // const cronTime_Oct = "0 0 1 10 *"; + // Test #1892 + const cronTime_Oct = "0 0 30 10 *"; cron.schedule(cronTime_Oct, async () => { try { const commandController = new CommandController(); diff --git a/src/controllers/ExRetirementController.ts b/src/controllers/ExRetirementController.ts index 7a3292f9..880a8477 100644 --- a/src/controllers/ExRetirementController.ts +++ b/src/controllers/ExRetirementController.ts @@ -100,7 +100,7 @@ export class ExRetirementController extends Controller { } @Get("/document/{documentId}") - async getDocument(@Path("documentId") officerDocumentID: string) { + async getDocument(@Path("documentId") officerDocumentID: string, @Request() req: any) { let retryCount = 0; const maxRetries = 2; while (retryCount < maxRetries) { @@ -118,8 +118,18 @@ export class ExRetirementController extends Controller { headers: { Authorization: `Bearer ${token}`, }, + responseType: "arraybuffer", }); - return res.data; + + if (!req.res.headersSent && !req.res.destroyed) { + // Set response headers + req.res.setHeader("Content-Type", "application/pdf"); + req.res.setHeader("Content-Disposition", `inline; filename="${officerDocumentID}.pdf"`); + req.res.setHeader("Content-Length", res.data.byteLength.toString()); + + req.res.end(Buffer.from(res.data)); + return; + } } catch (error: any) { if (error.response?.status === 500 && retryCount < maxRetries - 1) { TokenCache.delete(`${clientId}:${clientSecret}`); diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index aebd8fa6..e32494c0 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -7365,40 +7365,45 @@ export class ProfileController extends Controller { nodeDnaId: null, type: profile.employeeClass, salary: profile.amount, - posNo: - root?.orgRootShortName && posMaster?.posMasterNo - ? `${root?.orgRootShortName} ${posMaster?.posMasterNo}` - : "", + posNo: null + // root?.orgRootShortName && posMaster?.posMasterNo + // ? `${root?.orgRootShortName} ${posMaster?.posMasterNo}` + // : "", }; if (_profile.child4Id != null) { _profile.node = 4; _profile.nodeId = _profile.child4Id; _profile.nodeDnaId = _profile.child4DnaId; _profile.nodeShortName = _profile.child4ShortName; + _profile.posNo = `${_profile.child4ShortName} ${_profile.posMasterNo}`; } else if (_profile.child3Id != null) { _profile.node = 3; _profile.nodeId = _profile.child3Id; _profile.nodeDnaId = _profile.child3DnaId; _profile.nodeShortName = _profile.child3ShortName; + _profile.posNo = `${_profile.child3ShortName} ${_profile.posMasterNo}`; } else if (_profile.child2Id != null) { _profile.node = 2; _profile.nodeId = _profile.child2Id; _profile.nodeDnaId = _profile.child2DnaId; _profile.nodeShortName = _profile.child2ShortName; + _profile.posNo = `${_profile.child2ShortName} ${_profile.posMasterNo}`; } else if (_profile.child1Id != null) { _profile.node = 1; _profile.nodeId = _profile.child1Id; _profile.nodeDnaId = _profile.child1DnaId; _profile.nodeShortName = _profile.child1ShortName; + _profile.posNo = `${_profile.child1ShortName} ${_profile.posMasterNo}`; } else if (_profile.rootId != null) { _profile.node = 0; _profile.nodeId = _profile.rootId; _profile.nodeDnaId = _profile.rootDnaId; _profile.nodeShortName = _profile.rootShortName; + _profile.posNo = `${_profile.rootShortName} ${_profile.posMasterNo}`; } return new HttpSuccess(_profile); } - + // ขรก. let orgRevisionPublish: any = await this.orgRevisionRepo .createQueryBuilder("orgRevision") .where("orgRevision.orgRevisionIsDraft = false") @@ -7529,10 +7534,10 @@ export class ProfileController extends Controller { nodeDnaId: null, salary: profile ? profile.amount : null, amountSpecial: profile ? profile.amountSpecial : null, - posNo: - root?.orgRootShortName && posMaster?.posMasterNo - ? `${root?.orgRootShortName} ${posMaster?.posMasterNo}` - : "", + posNo: null + // root?.orgRootShortName && posMaster?.posMasterNo + // ? `${root?.orgRootShortName} ${posMaster?.posMasterNo}` + // : "", }; if (_profile.child4Id != null) { @@ -7540,26 +7545,31 @@ export class ProfileController extends Controller { _profile.nodeId = _profile.child4Id; _profile.nodeDnaId = _profile.child4DnaId; _profile.nodeShortName = _profile.child4ShortName; + _profile.posNo = `${_profile.child4ShortName} ${posMaster?.posMasterNo}`; } else if (_profile.child3Id != null) { _profile.node = 3; _profile.nodeId = _profile.child3Id; _profile.nodeDnaId = _profile.child3DnaId; _profile.nodeShortName = _profile.child3ShortName; + _profile.posNo = `${_profile.child3ShortName} ${posMaster?.posMasterNo}`; } else if (_profile.child2Id != null) { _profile.node = 2; _profile.nodeId = _profile.child2Id; _profile.nodeDnaId = _profile.child2DnaId; _profile.nodeShortName = _profile.child2ShortName; + _profile.posNo = `${_profile.child2ShortName} ${posMaster?.posMasterNo}`; } else if (_profile.child1Id != null) { _profile.node = 1; _profile.nodeId = _profile.child1Id; _profile.nodeDnaId = _profile.child1DnaId; _profile.nodeShortName = _profile.child1ShortName; + _profile.posNo = `${_profile.child1ShortName} ${posMaster?.posMasterNo}`; } else if (_profile.rootId != null) { _profile.node = 0; _profile.nodeId = _profile.rootId; _profile.nodeDnaId = _profile.rootDnaId; _profile.nodeShortName = _profile.rootShortName; + _profile.posNo = `${_profile.rootShortName} ${posMaster?.posMasterNo}`; } return new HttpSuccess(_profile); } diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 3ce5a3e0..dad205a4 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -3588,36 +3588,41 @@ export class ProfileEmployeeController extends Controller { nodeDnaId: null, salary: profile ? profile.amount : null, amountSpecial: profile ? profile.amountSpecial : null, - posNo: - root?.orgRootShortName && posMaster?.posMasterNo - ? `${root?.orgRootShortName} ${posMaster?.posMasterNo}` - : "", + posNo: null + // root?.orgRootShortName && posMaster?.posMasterNo + // ? `${root?.orgRootShortName} ${posMaster?.posMasterNo}` + // : "", }; if (_profile.child4Id != null) { _profile.node = 4; _profile.nodeId = _profile.child4Id; _profile.nodeDnaId = _profile.child4DnaId; _profile.nodeShortName = _profile.child4ShortName; + _profile.posNo = `${_profile.child4ShortName} ${_profile.posMasterNo}`; } else if (_profile.child3Id != null) { _profile.node = 3; _profile.nodeId = _profile.child3Id; _profile.nodeDnaId = _profile.child3DnaId; _profile.nodeShortName = _profile.child3ShortName; + _profile.posNo = `${_profile.child3ShortName} ${_profile.posMasterNo}`; } else if (_profile.child2Id != null) { _profile.node = 2; _profile.nodeId = _profile.child2Id; _profile.nodeDnaId = _profile.child2DnaId; _profile.nodeShortName = _profile.child2ShortName; + _profile.posNo = `${_profile.child2ShortName} ${_profile.posMasterNo}`; } else if (_profile.child1Id != null) { _profile.node = 1; _profile.nodeId = _profile.child1Id; _profile.nodeDnaId = _profile.child1DnaId; _profile.nodeShortName = _profile.child1ShortName; + _profile.posNo = `${_profile.child1ShortName} ${_profile.posMasterNo}`; } else if (_profile.rootId != null) { _profile.node = 0; _profile.nodeId = _profile.rootId; _profile.nodeDnaId = _profile.rootDnaId; _profile.nodeShortName = _profile.rootShortName; + _profile.posNo = `${_profile.rootShortName} ${_profile.posMasterNo}`; } return new HttpSuccess(_profile); }