Merge branch 'develop' of github.com:Frappet/bma-ehr-salary into develop
This commit is contained in:
commit
4d24a34674
7 changed files with 76 additions and 21 deletions
12
src/app.ts
12
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,
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -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 },
|
||||
|
|
|
|||
|
|
@ -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({
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -876,4 +876,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
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue