Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop

This commit is contained in:
Kittapath 2024-02-07 18:53:34 +07:00
commit c50ea8c3cd
4 changed files with 50 additions and 9 deletions

View file

@ -4,11 +4,11 @@ import cors from "cors";
import express from "express";
import swaggerUi from "swagger-ui-express";
import swaggerDocument from "./swagger.json";
import * as cron from 'node-cron';
import * as cron from "node-cron";
import error from "./middlewares/error";
import { AppDataSource } from "./database/data-source";
import { RegisterRoutes } from "./routes";
import { OrganizationController } from "./controllers/OrganizationController";
async function main() {
await AppDataSource.initialize();
@ -30,10 +30,16 @@ async function main() {
app.use(error);
const APP_HOST = process.env.APP_HOST || "0.0.0.0";
const APP_PORT = +(process.env.APP_PORT || 3000);
// cron.schedule('*/10 * * * * *', () => {
// console.log("cron job....")
// });
const cronTime = "0 0 * * * *"; // ตั้งเวลาทุกวันเวลา 00:00:00
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(

View file

@ -1320,4 +1320,39 @@ export class OrganizationController extends Controller {
await this.orgRevisionRepository.save(orgRevisionDraft);
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();
}
}

View file

@ -41,7 +41,7 @@ export class Position extends EntityBase {
comment: "ตำแหน่งทางการบริหาร",
default: null,
})
posExecutiveId: string;
posExecutiveId: string | null;
@Column({
nullable: true,

View file

@ -51,14 +51,14 @@ export class Profile extends EntityBase {
length: 40,
comment: "ไอดีระดับตำแหน่ง",
})
posLevelId: string;
posLevelId: string | null;
@Column({
nullable: true,
length: 40,
comment: "ไอดีประเภทตำแหน่",
})
posTypeId: string;
posTypeId: string | null;
// @Column({
// nullable: true,