diff --git a/package-lock.json b/package-lock.json index cbd97229..c2d3cc29 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@nestjs/platform-express": "^10.3.9", "@tsoa/runtime": "^6.0.0", + "axios": "^1.7.2", "cors": "^2.8.5", "dotenv": "^16.3.1", "express": "^4.18.2", @@ -648,6 +649,11 @@ "resolved": "https://registry.npmjs.org/async/-/async-0.2.10.tgz", "integrity": "sha512-eAkdoKxU6/LkKDBzLpT+t6Ff5EtfSF4wx1WfJiPEEV7WNLnDaRXk0oVysiEPm262roaachGexwUv94WhSgN5TQ==" }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, "node_modules/available-typed-arrays": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz", @@ -659,6 +665,16 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/axios": { + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz", + "integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -1106,6 +1122,17 @@ "resolved": "https://registry.npmjs.org/colors-console/-/colors-console-1.0.3.tgz", "integrity": "sha512-Q31K32UwadWqAxs+Iu46gNm4HJqUwrTJT2zen5NnhkKE5w7uqeZQZiuODUOxM/zOtHfiUTkia0io6zbN/VcCUQ==" }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", @@ -1271,6 +1298,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/denque": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz", @@ -1662,6 +1697,25 @@ "node": ">= 0.8" } }, + "node_modules/follow-redirects": { + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/for-each": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", @@ -1685,6 +1739,19 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", @@ -3319,6 +3386,11 @@ "node": ">= 0.10" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/pstree.remy": { "version": "1.1.8", "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", diff --git a/package.json b/package.json index b70950d1..6a7eb347 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "dependencies": { "@nestjs/platform-express": "^10.3.9", "@tsoa/runtime": "^6.0.0", + "axios": "^1.7.2", "cors": "^2.8.5", "dotenv": "^16.3.1", "express": "^4.18.2", diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 5616bd50..def15132 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -58,6 +58,7 @@ import { UpdateEmploymentProfileEmployee, } from "../entities/ProfileEmployeeEmployment"; import { ProfileEmployeeEmploymentHistory } from "../entities/ProfileEmployeeEmploymentHistory"; +import CallAPI from "../interfaces/call-api"; @Route("api/v1/org/profile-employee") @Tags("ProfileEmployee") @@ -2853,4 +2854,60 @@ export class ProfileEmployeeController extends Controller { }); return new HttpSuccess(profiles); } + + /** + * API ออกคำสั่งลูกจ้าง + * + * @summary ORG_038 - ออกคำสั่งลูกจ้าง (ADMIN) # + * + */ + @Post("report/resume") + async doneReport( + @Body() + body: { + result: { + id: string; + personId: string; + templateDoc: string; + amount: string; + positionSalaryAmount: string; + mouthSalaryAmount: string; + refCommandNo: string; + }[]; + }, + @Request() request: { user: Record }, + ) { + await Promise.all( + body.result.map(async (v) => { + const profile = await this.profileRepo.findOne({ + where: { + id: v.id, + }, + relations: ["posType", "posLevel"], + }); + if (profile != null) { + await new CallAPI() + .PostData(request, "org/profile/salary", { + profileId: profile.id, + date: new Date(), + amount: v.amount, + positionSalaryAmount: v.positionSalaryAmount, + mouthSalaryAmount: v.mouthSalaryAmount, + posNo: profile.posMasterNoTemp, + position: profile.positionTemp, + positionType: profile.posTypeNameTemp, + positionLevel: profile.posLevelNameTemp, + refCommandNo: v.refCommandNo, + templateDoc: v.templateDoc, + }) + .then(async (x) => { + profile.statusTemp = "DONE"; + profile.employeeClass = "TEMP"; + await this.profileRepo.save(profile); + }); + } + }), + ); + return new HttpSuccess(); + } } diff --git a/src/entities/ProfileChangePosition.ts b/src/entities/ProfileChangePosition.ts index 575f1cd6..f7f40f06 100644 --- a/src/entities/ProfileChangePosition.ts +++ b/src/entities/ProfileChangePosition.ts @@ -31,6 +31,8 @@ export class ProfileChangePosition extends EntityBase { @Column({ nullable: true, comment: "ข้อมูลหน่วยงานเดิม เงินเดือน", type: "double", default: null }) amountOld: number; + @Column({ nullable: true, type: "datetime", comment: "ดำรงตำแหน่งในระดับปัจจุบันเมื่อ", default: null }) + dateCurrent: Date @Column({ nullable: true, comment: "profile Id", default: null }) profileId: string; @@ -222,7 +224,7 @@ export class ProfileItem { positionLevelOld: string | null; positionNumberOld: string | null; organizationOld: string | null; - organizationPositionOld: string | null; + organizationPositionOld?: string | null; amountOld: number | null; educationOld: string | null; rootOld: string | null; @@ -255,7 +257,7 @@ export type UpdateProfileChangePosition = { positionLevelOld: string; positionNumberOld: string; amountOld: number; - dateCurrent : Date | null + dateCurrent : Date; reason: string | null; }; diff --git a/src/interfaces/call-api.ts b/src/interfaces/call-api.ts new file mode 100644 index 00000000..4cbd1a5a --- /dev/null +++ b/src/interfaces/call-api.ts @@ -0,0 +1,51 @@ +import { + Controller, + Request, + Get, + Post, + Put, + Delete, + Patch, + Route, + Security, + Tags, + Path, +} from "tsoa"; +import axios from "axios"; + +class CallAPI { + //Get + public async GetData(request: any, @Path() path: any) { + const token = request.headers.authorization; + const url = process.env.API + path; + try { + const response = await axios.get(url, { + headers: { + Authorization: `${token}`, + "Content-Type": "application/json", + }, + }); + return response.data.result; + } catch (error) { + throw error; + } + } + //Post + public async PostData(request: any, @Path() path: any, sendData: any) { + const token = request.headers.authorization; + const url = process.env.API + path; + try { + const response = await axios.post(url, sendData, { + headers: { + Authorization: `${token}`, + "Content-Type": "application/json", + }, + }); + return response.data.result; + } catch (error) { + throw error; + } + } +} + +export default CallAPI; diff --git a/src/migration/1718248767175-update_table_profilechange_add_current.ts b/src/migration/1718248767175-update_table_profilechange_add_current.ts new file mode 100644 index 00000000..05b38d4a --- /dev/null +++ b/src/migration/1718248767175-update_table_profilechange_add_current.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableProfilechangeAddCurrent1718248767175 implements MigrationInterface { + name = 'UpdateTableProfilechangeAddCurrent1718248767175' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileChangePosition\` ADD \`dateCurrent\` datetime NULL COMMENT 'ดำรงตำแหน่งในระดับปัจจุบันเมื่อ'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileChangePosition\` DROP COLUMN \`dateCurrent\``); + } + +}