Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop
This commit is contained in:
commit
c50ea8c3cd
4 changed files with 50 additions and 9 deletions
18
src/app.ts
18
src/app.ts
|
|
@ -4,11 +4,11 @@ import cors from "cors";
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import swaggerUi from "swagger-ui-express";
|
import swaggerUi from "swagger-ui-express";
|
||||||
import swaggerDocument from "./swagger.json";
|
import swaggerDocument from "./swagger.json";
|
||||||
import * as cron from 'node-cron';
|
import * as cron from "node-cron";
|
||||||
import error from "./middlewares/error";
|
import error from "./middlewares/error";
|
||||||
import { AppDataSource } from "./database/data-source";
|
import { AppDataSource } from "./database/data-source";
|
||||||
import { RegisterRoutes } from "./routes";
|
import { RegisterRoutes } from "./routes";
|
||||||
|
import { OrganizationController } from "./controllers/OrganizationController";
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
await AppDataSource.initialize();
|
await AppDataSource.initialize();
|
||||||
|
|
@ -30,10 +30,16 @@ async function main() {
|
||||||
app.use(error);
|
app.use(error);
|
||||||
const APP_HOST = process.env.APP_HOST || "0.0.0.0";
|
const APP_HOST = process.env.APP_HOST || "0.0.0.0";
|
||||||
const APP_PORT = +(process.env.APP_PORT || 3000);
|
const APP_PORT = +(process.env.APP_PORT || 3000);
|
||||||
|
|
||||||
// cron.schedule('*/10 * * * * *', () => {
|
const cronTime = "0 0 * * * *"; // ตั้งเวลาทุกวันเวลา 00:00:00
|
||||||
// console.log("cron job....")
|
cron.schedule(cronTime, async () => {
|
||||||
// });
|
try {
|
||||||
|
const orgController = new OrganizationController();
|
||||||
|
await orgController.cronjobRevision();
|
||||||
|
} 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, APP_HOST, () => console.log(`Listening on: http://localhost:${APP_PORT}`));
|
||||||
app.listen(
|
app.listen(
|
||||||
|
|
|
||||||
|
|
@ -1320,4 +1320,39 @@ export class OrganizationController extends Controller {
|
||||||
await this.orgRevisionRepository.save(orgRevisionDraft);
|
await this.orgRevisionRepository.save(orgRevisionDraft);
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cronjob
|
||||||
|
*/
|
||||||
|
async cronjobRevision() {
|
||||||
|
|
||||||
|
const today = new Date();
|
||||||
|
today.setHours(0, 0, 0, 0); // Set time to the beginning of the day
|
||||||
|
const orgRevisionPublish = await this.orgRevisionRepository
|
||||||
|
.createQueryBuilder("orgRevision")
|
||||||
|
.where("orgRevision.orgRevisionIsDraft = false")
|
||||||
|
.andWhere("orgRevision.orgRevisionIsCurrent = true")
|
||||||
|
.getOne();
|
||||||
|
|
||||||
|
const orgRevisionDraft = await this.orgRevisionRepository
|
||||||
|
.createQueryBuilder("orgRevision")
|
||||||
|
.where("orgRevision.orgRevisionIsDraft = true")
|
||||||
|
.andWhere("orgRevision.orgRevisionIsCurrent = false")
|
||||||
|
.andWhere("DATE(orgRevision.orgPublishDate) = :today", { today })
|
||||||
|
.getOne();
|
||||||
|
if (!orgRevisionDraft) {
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
if (orgRevisionPublish) {
|
||||||
|
orgRevisionPublish.orgRevisionIsDraft = false;
|
||||||
|
orgRevisionPublish.orgRevisionIsCurrent = false;
|
||||||
|
await this.orgRevisionRepository.save(orgRevisionPublish);
|
||||||
|
|
||||||
|
}
|
||||||
|
orgRevisionDraft.orgRevisionIsCurrent = true;
|
||||||
|
orgRevisionDraft.orgRevisionIsDraft = false;
|
||||||
|
await this.orgRevisionRepository.save(orgRevisionDraft);
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ export class Position extends EntityBase {
|
||||||
comment: "ตำแหน่งทางการบริหาร",
|
comment: "ตำแหน่งทางการบริหาร",
|
||||||
default: null,
|
default: null,
|
||||||
})
|
})
|
||||||
posExecutiveId: string;
|
posExecutiveId: string | null;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
|
|
|
||||||
|
|
@ -51,14 +51,14 @@ export class Profile extends EntityBase {
|
||||||
length: 40,
|
length: 40,
|
||||||
comment: "ไอดีระดับตำแหน่ง",
|
comment: "ไอดีระดับตำแหน่ง",
|
||||||
})
|
})
|
||||||
posLevelId: string;
|
posLevelId: string | null;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
length: 40,
|
length: 40,
|
||||||
comment: "ไอดีประเภทตำแหน่",
|
comment: "ไอดีประเภทตำแหน่",
|
||||||
})
|
})
|
||||||
posTypeId: string;
|
posTypeId: string | null;
|
||||||
|
|
||||||
// @Column({
|
// @Column({
|
||||||
// nullable: true,
|
// nullable: true,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue