From b91a217229540db8af57ab16c24cf63938782f56 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 28 Feb 2024 11:22:42 +0700 Subject: [PATCH 1/8] no message --- src/controllers/SalaryPeriodController.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index d59ed83..ff4597b 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -751,13 +751,13 @@ export class SalaryPeriodController extends Controller { * @summary SLR_020 - รายการรอบเงินเดือน #20 * */ - @Get("snapshot/{snaphot}/{salaryPeriodId}") + @Get("snapshot/{snapshot}/{salaryPeriodId}") async SnapshotSalary( - @Path() snaphot: string, + @Path() snapshot: string, salaryPeriodId: string, @Request() request: { user: Record }, ) { - snaphot = snaphot.toLocaleUpperCase(); + snapshot = snapshot.toLocaleUpperCase(); const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId }, }); @@ -766,7 +766,7 @@ export class SalaryPeriodController extends Controller { } const salaryOrg = await this.salaryOrgRepository.find({ - where: { salaryPeriodId: salaryPeriod.id, snapshot: snaphot }, + where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot }, }); const salaryProfile = await this.salaryProfileRepository.find({ where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) }, @@ -788,7 +788,7 @@ export class SalaryPeriodController extends Controller { salaryOrgNew.status = "PENDING"; salaryOrgNew.rootId = rootId; salaryOrgNew.revisionId = salaryPeriod.revisionId; - salaryOrgNew.snapshot = snaphot; + salaryOrgNew.snapshot = snapshot; salaryOrgNew.group = "GROUP1"; salaryOrgNew.createdUserId = request.user.sub; salaryOrgNew.createdFullName = request.user.name; @@ -802,9 +802,9 @@ export class SalaryPeriodController extends Controller { ); let salaryProfileOld: SalaryProfile[] = []; - if (snaphot == "SNAP2") { + if (snapshot == "SNAP2") { const salaryOrgOld = await this.salaryOrgRepository.findOne({ - where: { salaryPeriodId: salaryPeriod.id, snapshot: snaphot }, + where: { salaryPeriodId: salaryPeriod.id, snapshot: "SNAP1" }, relations: ["salaryProfiles"], }); if (salaryOrgOld != null) salaryProfileOld = salaryOrgOld.salaryProfiles; @@ -827,7 +827,7 @@ export class SalaryPeriodController extends Controller { where: { salaryPeriodId: salaryPeriod.id, rootId: profile.rootId, - snapshot: snaphot, + snapshot: snapshot, group: group, }, }); @@ -841,7 +841,7 @@ export class SalaryPeriodController extends Controller { salaryProfileNew.lastUpdateUserId = request.user.sub; salaryProfileNew.lastUpdateFullName = request.user.name; - if (snaphot == "SNAP2") { + if (snapshot == "SNAP2") { const salaryOld = salaryProfileOld.find( (x) => x.citizenId == salaryProfileNew.citizenId, ); @@ -857,7 +857,7 @@ export class SalaryPeriodController extends Controller { ); const salaryOrgNew = await this.salaryOrgRepository.find({ - where: { salaryPeriodId: salaryPeriod.id, snapshot: snaphot }, + where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot }, relations: ["salaryProfiles"], }); await Promise.all( From b93fb6c1e5c1aa1c699648bf45444e7e2821ab86 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 28 Feb 2024 11:27:52 +0700 Subject: [PATCH 2/8] no message --- src/controllers/SalaryPeriodController.ts | 7 ++-- src/interfaces/call-api.ts | 49 ++++++++++++++--------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index ff4597b..83035d0 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -27,6 +27,7 @@ import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import { Salarys } from "../entities/Salarys"; import { SalaryRanks } from "../entities/SalaryRanks"; +import CallAPI from "../interfaces/call-api"; @Route("api/v1/salary/period") @Tags("Salary") @@ -774,9 +775,9 @@ export class SalaryPeriodController extends Controller { await this.salaryOrgRepository.remove(salaryOrg); await this.salaryProfileRepository.remove(salaryProfile); - let orgs: any; - let orgProfiles: any; - let revisionId: any; + let orgs = await new CallAPI().GetData(request, "org/active/root/id"); + let orgProfiles = await new CallAPI().GetData(request, "org/profile/salary/gen"); + let revisionId = await new CallAPI().GetData(request, "org/revision/latest"); salaryPeriod.revisionId = revisionId; await this.salaryPeriodRepository.save(salaryPeriod); diff --git a/src/interfaces/call-api.ts b/src/interfaces/call-api.ts index 49473f0..ddf535e 100644 --- a/src/interfaces/call-api.ts +++ b/src/interfaces/call-api.ts @@ -1,24 +1,35 @@ -import { Controller, Request, Get, Post, Put, Delete, Patch, Route, Security, Tags, Path } from "tsoa"; -import axios from 'axios'; +import { + Controller, + Request, + Get, + Post, + Put, + Delete, + Patch, + Route, + Security, + Tags, + Path, +} from "tsoa"; +import axios from "axios"; class CallAPI { - //Get - public async GetData(request: any, @Path() path: any) { - const token = request.headers.authorization; - const url = process.env.ORG_API+path; - try { - const response = await axios.get(url, { - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'application/json' - } - }); - return response.data; - } catch (error) { - throw error; - } + //Get + public async GetData(request: any, @Path() path: any) { + const token = request.headers.authorization; + const url = process.env.ORG_API + path; + try { + const response = await axios.get(url, { + headers: { + Authorization: `Bearer ${token}`, + "Content-Type": "application/json", + }, + }); + return response.data.result; + } catch (error) { + throw error; } - + } } -export default CallAPI; \ No newline at end of file +export default CallAPI; From 382866d1cdc1858e3edfc59e9763fce7cdf53495 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 28 Feb 2024 13:16:01 +0700 Subject: [PATCH 3/8] Cronjob SalaryPeriod --- src/app.ts | 12 +++++- src/controllers/SalaryPeriodController.ts | 45 +++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/app.ts b/src/app.ts index 6efbcf9..b0180b1 100644 --- a/src/app.ts +++ b/src/app.ts @@ -8,6 +8,7 @@ import * as cron from "node-cron"; import error from "./middlewares/error"; import { AppDataSource } from "./database/data-source"; import { RegisterRoutes } from "./routes"; +import { SalaryPeriodController } from "./controllers/SalaryPeriodController"; async function main() { await AppDataSource.initialize(); @@ -25,11 +26,20 @@ async function main() { app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument)); RegisterRoutes(app); - + app.use(error); const APP_HOST = process.env.APP_HOST || "0.0.0.0"; const APP_PORT = +(process.env.APP_PORT || 3000); + const cronTime = "0 1 * * *"; // ตั้งเวลาทุกวันเวลา 01:00:00 + cron.schedule(cronTime, async () => { + try { + const salaryPeriod = new SalaryPeriodController(); + await salaryPeriod.CronjobSalaryPeriod(); + } catch (error) { + console.error("Error executing function from controller:", error); + } + }); app.listen( APP_PORT, APP_HOST, diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index 83035d0..910d0b5 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -872,4 +872,49 @@ export class SalaryPeriodController extends Controller { return new HttpSuccess(); } + + /** + * Cronjob SalaryPeriod + */ + async CronjobSalaryPeriod() { + const current = new Date(); + let salaryPeriod: any + // console.log(current.getDate(), current.getMonth() , current.getFullYear()) + if(current.getDate() == 1 && current.getMonth() == 2){ + salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + year: current.getFullYear(), + period: "MAR", + isActive: true + } + }); + } + else if(current.getDate() == 1 && current.getMonth() == 3){ + salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + year: current.getFullYear(), + period: "APR", + isActive: true + } + }); + } + else if(current.getDate() == 1 && current.getMonth() == 8){ + salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + year: current.getFullYear(), + period: "SEP", + isActive: true + } + }); + } + else if(current.getDate() == 1 && current.getMonth() == 9){ + salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + year: current.getFullYear(), + period: "OCT", + isActive: true + } + }); + } + } } From 74349d93c4817a2662913cd842ef028d460a3585 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 28 Feb 2024 13:35:08 +0700 Subject: [PATCH 4/8] =?UTF-8?q?=E0=B8=A5=E0=B8=9A=20caption=20"=E0=B9=84?= =?UTF-8?q?=E0=B8=AD=E0=B8=94=E0=B8=B5"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/PosLevelController.ts | 10 +++++----- src/controllers/PosTypeController.ts | 8 ++++---- src/controllers/ReportController.ts | 2 +- src/controllers/SalaryController.ts | 8 ++++---- src/controllers/SalaryPeriodController.ts | 6 +++--- src/controllers/SalaryRankController.ts | 6 +++--- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/controllers/PosLevelController.ts b/src/controllers/PosLevelController.ts index 1f51b5a..51cd00a 100644 --- a/src/controllers/PosLevelController.ts +++ b/src/controllers/PosLevelController.ts @@ -66,7 +66,7 @@ export class PosLevelController extends Controller { if (!chkPosTypeId) { throw new HttpError( HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูล posTypeId ไอดีนี้ : " + requestBody.posTypeId, + "ไม่พบข้อมูลประเภทตำแหน่งนี้" ); } @@ -122,7 +122,7 @@ export class PosLevelController extends Controller { ) { const posLevel = await this.posLevelRepository.findOne({ where: { id } }); if (!posLevel) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้"); } const chkPosTypeId = await this.posTypeRepository.findOne({ @@ -133,7 +133,7 @@ export class PosLevelController extends Controller { if (!chkPosTypeId) { throw new HttpError( HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูล posTypeId ไอดีนี้ : " + requestBody.posTypeId, + "ไม่พบข้อมูลระดับตำแหน่งนี้" ); } @@ -180,7 +180,7 @@ export class PosLevelController extends Controller { async deleteLevel(@Path() id: string) { const delPosLevel = await this.posLevelRepository.findOne({ where: { id } }); if (!delPosLevel) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้"); } // try { await this.posLevelRepository.remove(delPosLevel); @@ -217,7 +217,7 @@ export class PosLevelController extends Controller { where: { id: id }, }); if (!getPosType) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้"); } const mapPosLevel = { diff --git a/src/controllers/PosTypeController.ts b/src/controllers/PosTypeController.ts index 72ce810..4004641 100644 --- a/src/controllers/PosTypeController.ts +++ b/src/controllers/PosTypeController.ts @@ -98,7 +98,7 @@ export class PosTypeController extends Controller { ) { const posType = await this.posTypeRepository.findOne({ where: { id } }); if (!posType) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้"); } const chkPosTypeName = await this.posTypeRepository.findOne({ where: { @@ -134,13 +134,13 @@ export class PosTypeController extends Controller { async deleteType(@Path() id: string) { const delPosType = await this.posTypeRepository.findOne({ where: { id } }); if (!delPosType) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้"); } const IdExitsInLevel = await this.posLevelRepository.find({ where: { posTypeId: id }, }); if (IdExitsInLevel.length > 0) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้ เนื่องจาก id ผูกกับ posLevel"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบข้อมูลระดับตำแหน่งนี้"); } // try { @@ -182,7 +182,7 @@ export class PosTypeController extends Controller { where: { id: id }, }); if (!getPosType) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทต"); } const mapGetPosType = { diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 5646cac..2ed861f 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -53,7 +53,7 @@ export class ReportController extends Controller { where: { id: id } }); if (!salarys) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้"); } const posType = await this.poTypeRepository.findOne({ where: { id: salarys.posTypeId }, diff --git a/src/controllers/SalaryController.ts b/src/controllers/SalaryController.ts index 237d605..a4842eb 100644 --- a/src/controllers/SalaryController.ts +++ b/src/controllers/SalaryController.ts @@ -132,7 +132,7 @@ export class Salary extends Controller { where: { id: id }, }); if (!chk_Salary) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้"); } if (chk_Salary.isActive && !requestBody.isActive) { @@ -205,7 +205,7 @@ export class Salary extends Controller { where: { id: id }, }); if (!chk_Salary) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้"); } if (chk_Salary.isActive) { throw new HttpError( @@ -259,7 +259,7 @@ export class Salary extends Controller { ], }); if (!salary) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้"); } return new HttpSuccess(salary); // } catch (error: any) { @@ -354,7 +354,7 @@ export class Salary extends Controller { }); if (!salary) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเงินเดือนจากไอดีนี้ : " + body.id); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้"); } const salaryRank = await this.salaryRankRepository.find({ diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index 910d0b5..6a88bb9 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -626,7 +626,7 @@ export class SalaryPeriodController extends Controller { where: { id: id }, }); if (!chk_SalaryPeriod) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้"); } const chk_toUpper = ["SPECIAL", "APR", "OCT"]; @@ -670,7 +670,7 @@ export class SalaryPeriodController extends Controller { where: { id: id }, }); if (!SalaryPeriod) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้"); } const SalaryOrg = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: SalaryPeriod.id }, @@ -705,7 +705,7 @@ export class SalaryPeriodController extends Controller { ], }); if (!salaryPeriod) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้"); } return new HttpSuccess(salaryPeriod); } diff --git a/src/controllers/SalaryRankController.ts b/src/controllers/SalaryRankController.ts index eb878db..0de9663 100644 --- a/src/controllers/SalaryRankController.ts +++ b/src/controllers/SalaryRankController.ts @@ -52,7 +52,7 @@ export class SalaryRanksController extends Controller { if (!checkSalary) { throw new HttpError( HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลไอดีนี้ : " + requestBody.salaryId, + "ไม่พบข้อมูลผังเงินเดือนนี้" ); } const salaryRank = Object.assign(new SalaryRanks(), requestBody); @@ -84,7 +84,7 @@ export class SalaryRanksController extends Controller { // try { const salaryRank = await this.salaryRankRepository.findOne({ where: { id: id } }); if (!salaryRank) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับผังเงินเดือนนี้"); } salaryRank.lastUpdateUserId = request.user.sub; salaryRank.lastUpdateFullName = request.user.name; @@ -110,7 +110,7 @@ export class SalaryRanksController extends Controller { where: { id }, }); if (!delSalaryRanks) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับผังเงินเดือนนี้"); } await this.salaryRankRepository.delete({ id: id }); return new HttpSuccess(); From 6bca6c5ba5bd1ba2ddfd1cd3613d9631ea6a67ca Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 28 Feb 2024 13:59:03 +0700 Subject: [PATCH 5/8] no message --- src/controllers/SalaryPeriodController.ts | 6 +++++- src/entities/SalaryProfile.ts | 18 ++++++++++++++++++ src/interfaces/call-api.ts | 17 +++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index 83035d0..8257c25 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -776,7 +776,11 @@ export class SalaryPeriodController extends Controller { await this.salaryProfileRepository.remove(salaryProfile); let orgs = await new CallAPI().GetData(request, "org/active/root/id"); - let orgProfiles = await new CallAPI().GetData(request, "org/profile/salary/gen"); + let orgProfiles = await new CallAPI().PostData(request, "org/profile/salary/gen", { + page: 1, + pageSize: 100, + keyword: "", + }); let revisionId = await new CallAPI().GetData(request, "org/revision/latest"); salaryPeriod.revisionId = revisionId; diff --git a/src/entities/SalaryProfile.ts b/src/entities/SalaryProfile.ts index 41bfcdb..ff93597 100644 --- a/src/entities/SalaryProfile.ts +++ b/src/entities/SalaryProfile.ts @@ -309,6 +309,9 @@ export class CreateSalaryProfile { @Column() posLevel: string; + @Column() + posExecutive: string; + @Column() amount: number; @@ -341,4 +344,19 @@ export class CreateSalaryProfile { @Column() child4: string; + + @Column() + isResult: boolean; + + @Column() + isDuration: boolean; + + @Column() + isPunish: boolean; + + @Column() + isRetired: boolean; + + @Column() + isRetired2: boolean; } diff --git a/src/interfaces/call-api.ts b/src/interfaces/call-api.ts index ddf535e..579e386 100644 --- a/src/interfaces/call-api.ts +++ b/src/interfaces/call-api.ts @@ -30,6 +30,23 @@ class CallAPI { throw error; } } + //Post + public async PostData(request: any, @Path() path: any, sendData: any) { + const token = request.headers.authorization; + const url = process.env.ORG_API + path; + try { + const response = await axios.post(url, { + headers: { + Authorization: `Bearer ${token}`, + "Content-Type": "application/json", + }, + json: sendData, + }); + return response.data.result; + } catch (error) { + throw error; + } + } } export default CallAPI; From 6ed7265094760ba9f7e91c36d82624b725e0c2bf Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 28 Feb 2024 14:18:07 +0700 Subject: [PATCH 6/8] 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; From 8339e6ce6d9e45fe9f6adf457c1c4efdf89e8a64 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 28 Feb 2024 14:46:17 +0700 Subject: [PATCH 7/8] 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 'จำนวนคนทั้งหมด'`); + } + +} From 442f2f9a8626e4dc7ddda2e8f0c97a081adc2745 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 28 Feb 2024 16:04:09 +0700 Subject: [PATCH 8/8] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=9F?= =?UTF-8?q?=E0=B8=B4=E0=B8=A7validate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/SalaryPeriodController.ts | 9 ++++++-- src/entities/SalaryProfile.ts | 28 +++++++++++------------ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index 7522dbe..c18f045 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -480,7 +480,8 @@ export class SalaryPeriodController extends Controller { ); } - const salaryProfile = Object.assign(new SalaryProfile(), requestBody); + let salaryProfile: any = Object.assign(new SalaryProfile(), requestBody); + delete salaryProfile.id; salaryProfile.type = salaryProfile.type.toUpperCase(); //Type & Level const type = await this.posTypeRepository.findOne({ @@ -557,7 +558,9 @@ export class SalaryPeriodController extends Controller { : salaryRanks.salaryFullHalf - salaryProfile.amount; salaryProfile.positionSalaryAmount = salaryRanks == null ? 0 : salaryRanks.salaryFullHalf; } else { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง"); + salaryProfile.amountSpecial = 0; + salaryProfile.amountUse = 0; + salaryProfile.positionSalaryAmount = 0; } salaryProfile.salaryOrgId = salaryOrg.id; @@ -807,6 +810,7 @@ export class SalaryPeriodController extends Controller { await Promise.all( orgs.map(async (rootId: string) => { let salaryOrgNew = Object.assign(new SalaryOrg()); + delete salaryOrgNew.id; salaryOrgNew.salaryPeriodId = salaryPeriod.id; salaryOrgNew.status = "PENDING"; salaryOrgNew.rootId = rootId; @@ -857,6 +861,7 @@ export class SalaryPeriodController extends Controller { if (salaryOrgNew != null) { let salaryProfileNew = Object.assign(new SalaryProfile(), profile); + delete profile.id; salaryProfileNew.salaryOrgId = salaryOrgNew.id; salaryProfileNew.revisionId = salaryPeriod.revisionId; salaryProfileNew.createdUserId = request.user.sub; diff --git a/src/entities/SalaryProfile.ts b/src/entities/SalaryProfile.ts index ff93597..f93f68e 100644 --- a/src/entities/SalaryProfile.ts +++ b/src/entities/SalaryProfile.ts @@ -289,16 +289,16 @@ export class CreateSalaryProfile { citizenId: string; @Column() - posMasterNoPrefix: string; + posMasterNoPrefix: string | null; @Column() posMasterNo: number; @Column() - posMasterNoSuffix: string; + posMasterNoSuffix: string | null; @Column() - orgShortName: string; + orgShortName: string | null; @Column() position: string; @@ -310,40 +310,40 @@ export class CreateSalaryProfile { posLevel: string; @Column() - posExecutive: string; + posExecutive: string | null; @Column() amount: number; @Column("uuid") - rootId: string; + rootId: string | null; @Column() - root: string; + root: string | null; @Column("uuid") - child1Id: string; + child1Id: string | null; @Column() - child1: string; + child1: string | null; @Column("uuid") - child2Id: string; + child2Id: string | null; @Column() - child2: string; + child2: string | null; @Column("uuid") - child3Id: string; + child3Id: string | null; @Column() - child3: string; + child3: string | null; @Column("uuid") - child4Id: string; + child4Id: string | null; @Column() - child4: string; + child4: string | null; @Column() isResult: boolean;