From 2f0d86ed58eb417cd9063ce2d89827dfa8bf12bd Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 18 Apr 2025 11:15:53 +0700 Subject: [PATCH] checkpoint --- src/controllers/SalaryPeriodController.ts | 27 ++++++++++++++--------- src/interfaces/call-api.ts | 3 +++ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index c037c7d..3cde762 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -2496,25 +2496,25 @@ export class SalaryPeriodController extends Controller { await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee, { data: request }); await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee, { data: request }); let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id"); - let total = 10000; + let total = 1000; // let _orgProfiles = await new CallAPI().PostData(request, "/org/unauthorize/salary/gen", { let _orgProfiles = await new CallAPI().PostData(request, "/org/unauthorize/new-salary/gen", { page: 1, - pageSize: 10000, + pageSize: 1000, keyword: "", year: salaryPeriod.year, period: salaryPeriod.period, }); let orgProfiles = _orgProfiles.data; total = _orgProfiles.total; - if (total > 10000) { - const page = Math.ceil(total / 10000); + if (total > 1000) { + const page = Math.ceil(total / 1000); for (let index = 2; index <= page; index++) { await new CallAPI() // .PostData(request, "/org/unauthorize/salary/gen", { .PostData(request, "/org/unauthorize/new-salary/gen", { page: index, - pageSize: 10000, + pageSize: 1000, keyword: "", year: salaryPeriod.year, period: salaryPeriod.period, @@ -2524,7 +2524,7 @@ export class SalaryPeriodController extends Controller { }); } } - total = 10000; + total = 1000; let orgProfileEmployees: any; let _orgProfileEmployees = await new CallAPI().PostData( request, @@ -2532,7 +2532,7 @@ export class SalaryPeriodController extends Controller { "/org/unauthorize/new-salary/employee/gen", { page: 1, - pageSize: 10000, + pageSize: 1000, keyword: "", year: salaryPeriod.year, period: salaryPeriod.period, @@ -2540,14 +2540,14 @@ export class SalaryPeriodController extends Controller { ); orgProfileEmployees = _orgProfileEmployees.data; total = _orgProfileEmployees.total; - if (total > 10000) { - const page = Math.ceil(total / 10000); + if (total > 1000) { + const page = Math.ceil(total / 1000); for (let index = 2; index <= page; index++) { await new CallAPI() // .PostData(request, "/org/unauthorize/salary/employee/gen", { .PostData(request, "/org/unauthorize/new-salary/employee/gen", { page: index, - pageSize: 10000, + pageSize: 1000, keyword: "", year: salaryPeriod.year, period: salaryPeriod.period, @@ -2630,6 +2630,7 @@ export class SalaryPeriodController extends Controller { }), ); if (salaryPeriod.period != "SPECIAL") { + console.log(`step1`) await Promise.all( orgProfiles.map(async (profile: any) => { let group = "GROUP1"; @@ -2643,6 +2644,7 @@ export class SalaryPeriodController extends Controller { ) { group = "GROUP2"; } + console.log(`step2`) const salaryOrgNew = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriod.id, @@ -2651,8 +2653,9 @@ export class SalaryPeriodController extends Controller { group: group, }, }); - + console.log(`step3`) if (salaryOrgNew != null) { + console.log(`step4`) let salaryProfileNew = Object.assign(new SalaryProfile(), profile); delete salaryProfileNew.id; @@ -2668,6 +2671,7 @@ export class SalaryPeriodController extends Controller { salaryProfileNew.lastUpdatedAt = new Date(); if (snapshot == "SNAP2") { + console.log(`step5`) const salaryOrgOld = await this.salaryOrgRepository.find({ where: { salaryPeriodId: salaryPeriod.id, snapshot: "SNAP1" }, }); @@ -2688,6 +2692,7 @@ export class SalaryPeriodController extends Controller { salaryProfileNew.isReserve = salaryOld == null ? false : salaryOld.isReserve; salaryProfileNew.isRetired = salaryOld == null ? false : salaryOld.isRetired; } + console.log(`step6`) await this.salaryProfileRepository.save(salaryProfileNew, { data: request }); setLogDataDiff(request, { before: beforeSalaryProfileNew, after: salaryProfileNew }); console.log(`✅ [SNAP: ${snapshot}] บันทึก SalaryProfile: ${salaryProfileNew.citizenId} (${salaryProfileNew.fullName ?? "-"})`); diff --git a/src/interfaces/call-api.ts b/src/interfaces/call-api.ts index 73f6c90..c0042fd 100644 --- a/src/interfaces/call-api.ts +++ b/src/interfaces/call-api.ts @@ -27,6 +27,8 @@ class CallAPI { api_key: process.env.API_KEY, }, }); + console.log("getting data..."); + if(log) addLogSequence(request, { action: "request", status: "success", @@ -64,6 +66,7 @@ class CallAPI { api_key: process.env.API_KEY, }, }); + console.log("processing data..."); addLogSequence(request, { action: "request", status: "success",