From 6ed7265094760ba9f7e91c36d82624b725e0c2bf Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 28 Feb 2024 14:18:07 +0700 Subject: [PATCH] no message --- src/controllers/SalaryPeriodController.ts | 79 ++++++++++++++--------- src/interfaces/call-api.ts | 8 ++- 2 files changed, 56 insertions(+), 31 deletions(-) diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index e29c9ef..db17580 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -775,13 +775,37 @@ export class SalaryPeriodController extends Controller { await this.salaryOrgRepository.remove(salaryOrg); await this.salaryProfileRepository.remove(salaryProfile); + console.log("11111111111111111111111"); let orgs = await new CallAPI().GetData(request, "org/active/root/id"); - let orgProfiles = await new CallAPI().PostData(request, "org/profile/salary/gen", { - page: 1, - pageSize: 100, - keyword: "", - }); + 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); + for (let index = 2; index <= page; index++) { + await new CallAPI() + .PostData(request, "org/profile/salary/gen", { + page: index, + pageSize: 100, + keyword: "", + }) + .then((x) => { + Array.prototype.push.apply(orgProfiles, x.data); + }); + } + } + console.log("44444444444444444444444"); let revisionId = await new CallAPI().GetData(request, "org/revision/latest"); + console.log("55555555555555555555555"); salaryPeriod.revisionId = revisionId; await this.salaryPeriodRepository.save(salaryPeriod); @@ -882,42 +906,39 @@ export class SalaryPeriodController extends Controller { */ async CronjobSalaryPeriod() { const current = new Date(); - let salaryPeriod: any + let salaryPeriod: any; // console.log(current.getDate(), current.getMonth() , current.getFullYear()) - if(current.getDate() == 1 && current.getMonth() == 2){ - salaryPeriod = await this.salaryPeriodRepository.findOne({ - where: { + if (current.getDate() == 1 && current.getMonth() == 2) { + salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { year: current.getFullYear(), period: "MAR", - isActive: true - } + isActive: true, + }, }); - } - else if(current.getDate() == 1 && current.getMonth() == 3){ - salaryPeriod = await this.salaryPeriodRepository.findOne({ - where: { + } else if (current.getDate() == 1 && current.getMonth() == 3) { + salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { year: current.getFullYear(), period: "APR", - isActive: true - } + isActive: true, + }, }); - } - else if(current.getDate() == 1 && current.getMonth() == 8){ - salaryPeriod = await this.salaryPeriodRepository.findOne({ - where: { + } else if (current.getDate() == 1 && current.getMonth() == 8) { + salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { year: current.getFullYear(), period: "SEP", - isActive: true - } + isActive: true, + }, }); - } - else if(current.getDate() == 1 && current.getMonth() == 9){ - salaryPeriod = await this.salaryPeriodRepository.findOne({ - where: { + } else if (current.getDate() == 1 && current.getMonth() == 9) { + salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { year: current.getFullYear(), period: "OCT", - isActive: true - } + isActive: true, + }, }); } } diff --git a/src/interfaces/call-api.ts b/src/interfaces/call-api.ts index 579e386..86ed525 100644 --- a/src/interfaces/call-api.ts +++ b/src/interfaces/call-api.ts @@ -17,7 +17,7 @@ class CallAPI { //Get public async GetData(request: any, @Path() path: any) { const token = request.headers.authorization; - const url = process.env.ORG_API + path; + const url = process.env.API + path; try { const response = await axios.get(url, { headers: { @@ -33,8 +33,11 @@ class CallAPI { //Post public async PostData(request: any, @Path() path: any, sendData: any) { const token = request.headers.authorization; - const url = process.env.ORG_API + path; + const url = process.env.API + path; try { + console.log("response"); + console.log(url); + console.log("response"); const response = await axios.post(url, { headers: { Authorization: `Bearer ${token}`, @@ -42,6 +45,7 @@ class CallAPI { }, json: sendData, }); + console.log(response); return response.data.result; } catch (error) { throw error;