From 8339e6ce6d9e45fe9f6adf457c1c4efdf89e8a64 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 28 Feb 2024 14:46:17 +0700 Subject: [PATCH] no message --- src/controllers/SalaryPeriodController.ts | 32 ++++++++----------- src/entities/SalaryOrg.ts | 2 ++ src/interfaces/call-api.ts | 7 +--- ...pdate_table_salaryProfile_add_revision3.ts | 16 ++++++++++ 4 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 src/migration/1709105846886-update_table_salaryProfile_add_revision3.ts diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index db17580..7522dbe 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -28,6 +28,7 @@ import { PosLevel } from "../entities/PosLevel"; import { Salarys } from "../entities/Salarys"; import { SalaryRanks } from "../entities/SalaryRanks"; import CallAPI from "../interfaces/call-api"; +import { Int32 } from "typeorm/browser"; @Route("api/v1/salary/period") @Tags("Salary") @@ -772,30 +773,25 @@ export class SalaryPeriodController extends Controller { const salaryProfile = await this.salaryProfileRepository.find({ where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) }, }); - await this.salaryOrgRepository.remove(salaryOrg); await this.salaryProfileRepository.remove(salaryProfile); + await this.salaryOrgRepository.remove(salaryOrg); - console.log("11111111111111111111111"); let orgs = await new CallAPI().GetData(request, "org/active/root/id"); - console.log("22222222222222222222222"); - let orgProfiles: any; - await new CallAPI() - .PostData(request, "org/profile/salary/gen", { - page: 1, - pageSize: 100, - keyword: "", - }) - .then((x) => { - orgProfiles = x.data; - }); - console.log("333333333333333333333"); - if (orgProfiles.total > 100) { - const page = Math.ceil(orgProfiles.total.length / 100); + let total = 1000; + let _orgProfiles = await new CallAPI().PostData(request, "org/profile/salary/gen", { + page: 1, + pageSize: 1000, + keyword: "", + }); + let orgProfiles = _orgProfiles.data; + total = _orgProfiles.total; + if (total > 1000) { + const page = Math.ceil(total / 1000); for (let index = 2; index <= page; index++) { await new CallAPI() .PostData(request, "org/profile/salary/gen", { page: index, - pageSize: 100, + pageSize: 1000, keyword: "", }) .then((x) => { @@ -803,9 +799,7 @@ export class SalaryPeriodController extends Controller { }); } } - console.log("44444444444444444444444"); let revisionId = await new CallAPI().GetData(request, "org/revision/latest"); - console.log("55555555555555555555555"); salaryPeriod.revisionId = revisionId; await this.salaryPeriodRepository.save(salaryPeriod); diff --git a/src/entities/SalaryOrg.ts b/src/entities/SalaryOrg.ts index 4ebad1d..5581190 100644 --- a/src/entities/SalaryOrg.ts +++ b/src/entities/SalaryOrg.ts @@ -37,11 +37,13 @@ export class SalaryOrg extends EntityBase { snapshot: string; @Column({ + default: 0, comment: "จำนวนคนทั้งหมด", }) total: number; @Column({ + default: 0, comment: "15%ของจำนวนคน(จำนวนเต็ม)", }) fifteenPercent: number; diff --git a/src/interfaces/call-api.ts b/src/interfaces/call-api.ts index 86ed525..8608230 100644 --- a/src/interfaces/call-api.ts +++ b/src/interfaces/call-api.ts @@ -35,17 +35,12 @@ class CallAPI { const token = request.headers.authorization; const url = process.env.API + path; try { - console.log("response"); - console.log(url); - console.log("response"); - const response = await axios.post(url, { + const response = await axios.post(url, sendData, { headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json", }, - json: sendData, }); - console.log(response); return response.data.result; } catch (error) { throw error; diff --git a/src/migration/1709105846886-update_table_salaryProfile_add_revision3.ts b/src/migration/1709105846886-update_table_salaryProfile_add_revision3.ts new file mode 100644 index 0000000..cffaf25 --- /dev/null +++ b/src/migration/1709105846886-update_table_salaryProfile_add_revision3.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableSalaryProfileAddRevision31709105846886 implements MigrationInterface { + name = 'UpdateTableSalaryProfileAddRevision31709105846886' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`salaryOrg\` CHANGE \`total\` \`total\` int NOT NULL COMMENT 'จำนวนคนทั้งหมด' DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`salaryOrg\` CHANGE \`fifteenPercent\` \`fifteenPercent\` int NOT NULL COMMENT '15%ของจำนวนคน(จำนวนเต็ม)' DEFAULT '0'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`salaryOrg\` CHANGE \`fifteenPercent\` \`fifteenPercent\` int NOT NULL COMMENT '15%ของจำนวนคน(จำนวนเต็ม)'`); + await queryRunner.query(`ALTER TABLE \`salaryOrg\` CHANGE \`total\` \`total\` int NOT NULL COMMENT 'จำนวนคนทั้งหมด'`); + } + +}