From 3c0d83631f62b6e1acf2fdcae8eb7f50f18275d2 Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Wed, 5 Mar 2025 17:48:31 +0700 Subject: [PATCH] fixing bug --- src/controllers/ProfileSalaryController.ts | 34 ++++++++++++---------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/controllers/ProfileSalaryController.ts b/src/controllers/ProfileSalaryController.ts index 92c077f6..aea03341 100644 --- a/src/controllers/ProfileSalaryController.ts +++ b/src/controllers/ProfileSalaryController.ts @@ -39,7 +39,9 @@ export class ProfileSalaryController extends Controller { @Get("XXX") public async cronjobTenurePositionOfficer() { let data: any = []; - const profile = await this.profileRepo.find({where:{id: "09e89026-c420-4136-bd9e-7e408f530b69"}}) + const profile = await this.profileRepo.find({ + where: { id: "09e89026-c420-4136-bd9e-7e408f530b69" }, + }); await Promise.all( profile.map(async (x) => { const sql_mode = await AppDataSource.query( @@ -49,22 +51,21 @@ export class ProfileSalaryController extends Controller { const _position = position.length > 0 ? position[0] : []; const mapPosition = _position.length > 1 - ? _position.slice(1) - .map((curr: any, index: number) => ({ + ? _position.slice(1).map((curr: any, index: number) => ({ days_diff: curr.days_diff, positionName: _position[index]?.positionName, - })) + })) : []; const calDayDiff = mapPosition .filter((curr: any) => curr.positionName == x.position) .reduce( (acc: any, curr: any) => { - acc.days_diff += Number(curr.days_diff) || 0; + acc.days_diff += Number(curr.days_diff) || 0; return acc; }, - { days_diff: 0} + { days_diff: 0 }, ); - console.log("==========> ", calDayDiff) + console.log("==========> ", calDayDiff); const _mapData = { profileId: x.id, positionName: x.position, @@ -72,13 +73,13 @@ export class ProfileSalaryController extends Controller { Years: null, Months: null, Days: null, - } + }; data.push(_mapData); - }) + }), // await this.positionOfficerRepo.save(data); ); - + return new HttpSuccess(); } @Get("user") @@ -216,12 +217,13 @@ export class ProfileSalaryController extends Controller { // year: curr.Years ? Math.floor(Number(curr.Years)) : 0, // month: curr.Months ? Math.floor(Number(curr.Months)) : 0, // day: curr.Days ? Math.floor(Number(curr.Days)) : 0, - name: !_posLevel[index]?.positionType - ? `ระดับ ${_posLevel[index]?.positionCee.trim()}` - : _posLevel[index]?.positionType == "บริหาร" || - _posLevel[index]?.positionType == "อำนวยการ" - ? `${_posLevel[index]?.positionType}${_posLevel[index]?.positionLevel}` - : _posLevel[index]?.positionLevel, + name: + !_posLevel[index]?.positionType && _posLevel[index]?.positionCee + ? `ระดับ ${_posLevel[index]?.positionCee.trim()}` + : _posLevel[index]?.positionType == "บริหาร" || + _posLevel[index]?.positionType == "อำนวยการ" + ? `${_posLevel[index]?.positionType}${_posLevel[index]?.positionLevel}` + : _posLevel[index]?.positionLevel, })) : [];