From e31e98b316fd32393ba9eb9114fd63e5ee84acbd Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 6 Mar 2025 13:00:02 +0700 Subject: [PATCH] job --- src/app.ts | 15 ++++++++++++++- src/controllers/ProfileSalaryController.ts | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/app.ts b/src/app.ts index fbd6df0d..5c10c6ef 100644 --- a/src/app.ts +++ b/src/app.ts @@ -12,7 +12,7 @@ import { RegisterRoutes } from "./routes"; import { OrganizationController } from "./controllers/OrganizationController"; import logMiddleware from "./middlewares/logs"; import { CommandController } from "./controllers/CommandController"; - +import { ProfileSalaryController } from "./controllers/ProfileSalaryController"; import { WebSocketServer } from "ws"; import http from "http"; @@ -85,6 +85,19 @@ async function main() { } }); + const cronTime_Tenure = "0 0 * * *"; + cron.schedule(cronTime_Tenure, async () => { + try { + const profileSalaryController = new ProfileSalaryController(); + await profileSalaryController.cronjobTenurePositionOfficer(); + await profileSalaryController.cronjobTenureLevelOfficer(); + await profileSalaryController.cronjobTenurePositionEmployee(); + await profileSalaryController.cronjobTenureLevelEmployee(); + } catch (error) { + console.error("Error executing function from controller:", error); + } + }); + // app.listen(APP_PORT, APP_HOST, () => console.log(`Listening on: http://localhost:${APP_PORT}`)); // app.listen( // APP_PORT, diff --git a/src/controllers/ProfileSalaryController.ts b/src/controllers/ProfileSalaryController.ts index 29d4dd9b..b0d128ba 100644 --- a/src/controllers/ProfileSalaryController.ts +++ b/src/controllers/ProfileSalaryController.ts @@ -86,7 +86,7 @@ export class ProfileSalaryController extends Controller { await this.positionEmployeeRepo.clear(); const profile = await this.profileEmployeeRepo.find(); for await (const x of profile) { - const position = await AppDataSource.query("CALL GetProfileSalaryPosition(?)", [x.id]); + const position = await AppDataSource.query("CALL GetProfileEmployeeSalaryPosition(?)", [x.id]); const _position = position.length > 0 ? position[0] : []; const mapPosition = _position.length > 1 @@ -176,7 +176,7 @@ export class ProfileSalaryController extends Controller { await this.levelEmployeeRepo.clear(); const profile = await this.profileEmployeeRepo.find({ relations: ["posLevel"] }); for await (const x of profile) { - const positionLevel = await AppDataSource.query("CALL GetProfileSalaryLevel(?)", [x.id]); + const positionLevel = await AppDataSource.query("CALL GetProfileEmployeeSalaryLevel(?)", [x.id]); const _positionLevel = positionLevel.length > 0 ? positionLevel[0] : []; const mapPositionLevel = _positionLevel.length > 1