diff --git a/src/app.ts b/src/app.ts index d4906096..360977a7 100644 --- a/src/app.ts +++ b/src/app.ts @@ -5,7 +5,7 @@ import express from "express"; import swaggerUi from "swagger-ui-express"; import swaggerDocument from "./swagger.json"; import * as cron from "node-cron"; -import { init as rabbitmqInit } from './services/rabbitmq'; +import { init as rabbitmqInit } from "./services/rabbitmq"; import error from "./middlewares/error"; import { AppDataSource } from "./database/data-source"; import { RegisterRoutes } from "./routes"; @@ -26,7 +26,7 @@ async function main() { ); app.use(express.json()); app.use(express.urlencoded({ extended: true })); - app.use(logMiddleware); + // app.use(logMiddleware); app.use("/", express.static("static")); app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument)); @@ -75,7 +75,7 @@ async function main() { } } - runMessageQueue() + runMessageQueue(); } main(); diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 85b2c98e..8f291634 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -1013,9 +1013,11 @@ export class CommandController extends Controller { if (command.commandExcecuteDate == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบวันที่คำสั่งมีผล"); - let profiles = command.commandRecives - .filter((x) => x.profileId != null) - .map(async (x) => x.profileId); + let profiles = command && command.commandRecives.length > 0 + ? command.commandRecives + .filter((x) => x.profileId != null) + .map((x) => x.profileId) + : []; await new CallAPI() .PostData(request, "/placement/noti/profiles", { diff --git a/src/controllers/WorkflowController.ts b/src/controllers/WorkflowController.ts index 468aa20b..5e5837aa 100644 --- a/src/controllers/WorkflowController.ts +++ b/src/controllers/WorkflowController.ts @@ -10,63 +10,100 @@ import { StateOperator } from "../entities/StateOperator"; import { StateOperatorUser } from "../entities/StateOperatorUser"; import CallAPI from "../interfaces/call-api"; import { Profile } from "../entities/Profile"; +import { StateUserComment } from "../entities/StateUserComment"; +import { MetaWorkflow } from "../entities/MetaWorkflow"; +import { MetaState } from "../entities/MetaState"; +import { MetaStateOperator } from "../entities/MetaStateOperator"; @Route("api/v1/org/workflow") -@Tags("AuthRole") +@Tags("Workflow") @Security("bearerAuth") export class WorkflowController extends Controller { private workflowRepo = AppDataSource.getRepository(Workflow); private stateRepo = AppDataSource.getRepository(State); private stateOperatorRepo = AppDataSource.getRepository(StateOperator); private stateOperatorUserRepo = AppDataSource.getRepository(StateOperatorUser); + private stateUserCommentRepo = AppDataSource.getRepository(StateUserComment); private profileRepo = AppDataSource.getRepository(Profile); - @Post("check-workflow") + private metaWorkflowRepo = AppDataSource.getRepository(MetaWorkflow); + private metaStateRepo = AppDataSource.getRepository(MetaState); + private metaStateOperatorRepo = AppDataSource.getRepository(MetaStateOperator); + + @Post("add-workflow") public async checkWorkflow( @Request() req: RequestWithUser, @Body() body: { + refId: string; sysName: string; posLevelName: string; posTypeName: string; - profiles: { - profile: string; - operator: string; - order: number; - }[]; }, ) { - const workflow = await this.workflowRepo.findOne({ + const profile = await this.profileRepo.findOne({ + where: { + keycloak: req.user.sub, + }, + }); + if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งาน"); + + const metaWorkflow = await this.metaWorkflowRepo.findOne({ where: { sysName: body.sysName, posLevelName: body.posLevelName, posTypeName: body.posTypeName, }, - relations: ["states"], }); - if (!workflow) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบกระบวนการนี้ได้"); + if (!metaWorkflow) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบกระบวนการนี้ได้"); + + const meta = { + createdUserId: req.user.sub, + createdFullName: req.user.name, + lastUpdateUserId: req.user.sub, + lastUpdateFullName: req.user.name, + createdAt: new Date(), + lastUpdatedAt: new Date(), + }; + const workflow = new Workflow(); + Object.assign(workflow, { ...metaWorkflow, id: undefined, ...meta }); + this.workflowRepo.save(workflow); + const metaState = await this.metaStateRepo.find({ + where: { + metaWorkflowId: metaWorkflow.id, + }, + }); + await Promise.all( - body.profiles.map(async (item) => { - const operatoeUser = new StateOperatorUser(); - operatoeUser.profile = item.profile; - operatoeUser.operator = item.operator.trim().toLocaleUpperCase(); - operatoeUser.order = item.order; - operatoeUser.workflowId = workflow.id; - operatoeUser.createdUserId = req.user.sub; - operatoeUser.createdFullName = req.user.name; - operatoeUser.createdAt = new Date(); - operatoeUser.lastUpdateUserId = req.user.sub; - operatoeUser.lastUpdateFullName = req.user.name; - operatoeUser.lastUpdatedAt = new Date(); - await this.stateOperatorUserRepo.save(operatoeUser); + metaState.map(async (item) => { + const state = new State(); + Object.assign(state, { ...item, id: undefined, workflowId: workflow.id, ...meta }); + await this.stateRepo.save(state); + const metaStateOperator = await this.metaStateOperatorRepo.find({ + where: { + metaStateId: item.id, + }, + }); + await Promise.all( + metaStateOperator.map(async (item) => { + const stateOperator = new StateOperator(); + Object.assign(stateOperator, { ...item, id: undefined, stateId: state.id, ...meta }); + await this.stateOperatorRepo.save(stateOperator); + }), + ); }), ); - return new HttpSuccess({ + + const stateOperatorUser = new StateOperatorUser(); + Object.assign(stateOperatorUser, { + profileId: profile.id, + operator: "OWNER", + order: 1, workflowId: workflow.id, - stateId: workflow.states.sort((a, b) => a.order - b.order)[0].id, - // stateName: workflow.states.sort((a, b) => a.order - b.order)[0].name, - // stateType: workflow.states.sort((a, b) => a.order - b.order)[0].type, + ...meta, }); + await this.stateOperatorUserRepo.save(stateOperatorUser); + return new HttpSuccess(); } @Post("check-iscan") @@ -76,18 +113,18 @@ export class WorkflowController extends Controller { body: { workflowId: string; stateId: string; - profile: string; + profileId: string; action: string; }, ) { const stateOperatorUser = await this.stateOperatorUserRepo.findOne({ where: { - profile: body.profile, + profileId: body.profileId, workflowId: body.workflowId, }, }); if (!stateOperatorUser) - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่สามารถดำเนินการกระบวนการนี้ได้"); + throw new HttpError(HttpStatus.NOT_FOUND, "ผู้ใช้งานนี้ไม่มีหน้าที่ในกระบวนการนี้"); const operator = await this.stateOperatorRepo.findOne({ where: { @@ -95,7 +132,7 @@ export class WorkflowController extends Controller { state: { id: body.stateId, workflow: { id: body.workflowId } }, }, }); - if (!operator) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (!operator) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่สามารถดำเนินการกระบวนการนี้ได้"); let isCan = false; switch (body.action.trim().toLocaleUpperCase()) { @@ -125,38 +162,111 @@ export class WorkflowController extends Controller { } } - @Post("check-iscan-all") - public async checkIsCanAll( + @Post("check-state-now") + public async checkStateNow( @Request() req: RequestWithUser, @Body() body: { - workflowId: string; - stateId: string; + refId: string; + system: string; }, ) { - const profile = await this.profileRepo.findOne({ + const workflow = await this.workflowRepo.findOne({ where: { - keycloak: req.user.sub, + refId: body.refId, + system: body.system, }, + relations: ["stateOperatorUsers"], }); - if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (!workflow) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่สามารถดำเนินการกระบวนการนี้ได้"); + + const state = await this.stateRepo.findOne({ + where: { + id: workflow.stateId, + }, + relations: ["stateOperators"], + }); + if (!state) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลขั้นตอนการอนุมัติ"); + return new HttpSuccess({ + stateId: state.id, + stateNo: state.order, + stateName: state.name, + }); + } + + @Post("check-user-now") + public async checkUserNow( + @Request() req: RequestWithUser, + @Body() + body: { + refId: string; + system: string; + }, + ) { const stateOperatorUser = await this.stateOperatorUserRepo.findOne({ where: { - profile: profile.id, - workflowId: body.workflowId, + workflow: { + refId: body.refId, + system: body.system, + }, + profile: { + keycloak: req.user.sub, + }, }, + relations: ["workflow"], }); if (!stateOperatorUser) - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่สามารถดำเนินการกระบวนการนี้ได้"); + throw new HttpError(HttpStatus.NOT_FOUND, "ผู้ใช้งานนี้ไม่มีหน้าที่ในกระบวนการนี้"); const operator = await this.stateOperatorRepo.findOne({ where: { operator: stateOperatorUser.operator, - state: { id: body.stateId, workflow: { id: body.workflowId } }, + stateId: stateOperatorUser.workflow.stateId, }, + relations: ["state"], }); - if (!operator) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - return new HttpSuccess(operator); + if (!operator) + throw new HttpError(HttpStatus.NOT_FOUND, "ผู้ใช้งานนี้ไม่มีหน้าที่ในขั้นตอนนี้"); + return new HttpSuccess({ + stateId: operator.state.id, + stateNo: operator.state.order, + stateName: operator.state.name, + operator: operator.operator, + can_view: operator.canView, + can_update: operator.canUpdate, + can_operate: operator.canOperate, + can_change_state: operator.canChangeState, + can_delete: operator.canDelete, + can_cancel: operator.canCancel, + }); + } + + @Post("check-state-all") + public async checkStateAll( + @Request() req: RequestWithUser, + @Body() + body: { + refId: string; + system: string; + }, + ) { + const state = await this.stateRepo.find({ + where: { + workflow: { + refId: body.refId, + system: body.system, + }, + }, + order: { order: "ASC", stateUserComments: { order: "ASC" } }, + relations: ["stateUserComments"], + }); + const _state = state.map((x) => ({ + stateId: x.id, + stateNo: x.order, + stateName: x.name, + stateUserComments: x.stateUserComments, + })); + return new HttpSuccess(_state); } @Post("state-next") @@ -164,16 +274,40 @@ export class WorkflowController extends Controller { @Request() req: RequestWithUser, @Body() body: { - stateId: string; + refId: string; + system: string; }, ) { + const stateOperatorUser = await this.stateOperatorUserRepo.findOne({ + where: { + workflow: { + refId: body.refId, + system: body.system, + }, + profile: { + keycloak: req.user.sub, + }, + }, + }); + if (!stateOperatorUser) + throw new HttpError(HttpStatus.NOT_FOUND, "ผู้ใช้งานนี้ไม่มีหน้าที่ในกระบวนการนี้"); + + const workflow = await this.workflowRepo.findOne({ + where: { + refId: body.refId, + system: body.system, + }, + relations: ["stateOperatorUsers"], + }); + if (!workflow) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่สามารถดำเนินการกระบวนการนี้ได้"); + const state = await this.stateRepo.findOne({ where: { - id: body.stateId, + id: workflow.stateId, }, - relations: ["stateOperators", "workflow", "workflow.stateOperatorUsers"], + relations: ["stateOperators"], }); - if (!state) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (!state) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลขั้นตอนการอนุมัติ"); const _state = await this.stateRepo.findOne({ where: { order: state.order + 1, @@ -182,7 +316,7 @@ export class WorkflowController extends Controller { relations: ["stateOperators"], }); //noti - let profileNow = state.workflow.stateOperatorUsers + let profileNow = workflow.stateOperatorUsers .filter((x) => state.stateOperators.map((s) => s.operator).includes(x.operator)) .map((x) => x.profile); await new CallAPI() @@ -199,7 +333,7 @@ export class WorkflowController extends Controller { console.error("Error calling API:", error); }); if (_state != null) { - let profileNext = state.workflow.stateOperatorUsers + let profileNext = workflow.stateOperatorUsers .filter((x) => _state.stateOperators.map((s) => s.operator).includes(x.operator)) .map((x) => x.profile); await new CallAPI() @@ -215,10 +349,13 @@ export class WorkflowController extends Controller { .catch((error) => { console.error("Error calling API:", error); }); + workflow.stateId = _state.id; + await this.workflowRepo.save(workflow); } return new HttpSuccess({ stateId: _state?.id || null, + stateNo: _state?.order || null, stateName: _state?.name || null, stateType: _state?.type || null, }); @@ -237,7 +374,7 @@ export class WorkflowController extends Controller { id: body.stateId, }, }); - if (!state) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (!state) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลขั้นตอนการอนุมัติ"); const _state = await this.stateRepo.findOne({ where: { order: state.order - 1, @@ -247,8 +384,158 @@ export class WorkflowController extends Controller { return new HttpSuccess({ stateId: _state?.id || null, + stateNo: _state?.order || null, stateName: _state?.name || null, stateType: _state?.type || null, }); } + + @Post("add-step") + public async addStep( + @Request() req: RequestWithUser, + @Body() + body: { + stateId: string; + profileId: string; + isAcceptSetting: boolean; + isApproveSetting: boolean; + isReasonSetting: boolean; + }, + ) { + const profile = await this.profileRepo.findOne({ + where: { + id: body.profileId, + }, + }); + if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบผู้ใช้งานนี้"); + const state = await this.stateRepo.findOne({ + where: { + id: body.stateId, + }, + relations: ["stateUserComments"], + }); + if (!state) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลขั้นตอนการอนุมัติ"); + + const stateUserComment = new StateUserComment(); + stateUserComment.order = state.stateUserComments.length + 1; + stateUserComment.stateId = body.stateId; + stateUserComment.profileId = body.profileId; + stateUserComment.isAcceptSetting = body.isAcceptSetting; + stateUserComment.isApproveSetting = body.isApproveSetting; + stateUserComment.isReasonSetting = body.isReasonSetting; + stateUserComment.createdUserId = req.user.sub; + stateUserComment.createdFullName = req.user.name; + stateUserComment.createdAt = new Date(); + stateUserComment.lastUpdateUserId = req.user.sub; + stateUserComment.lastUpdateFullName = req.user.name; + stateUserComment.lastUpdatedAt = new Date(); + await this.stateUserCommentRepo.save(stateUserComment); + + await new CallAPI() + .PostData(req, "/placement/noti/profiles", { + subject: `ได้รับรายการ`, + body: `ได้รับรายการ`, + receiverUserIds: [body.profileId], + payload: "", //แนบไฟล์ + isSendMail: true, + isSendInbox: true, + isSendNotification: true, + }) + .catch((error) => { + console.error("Error calling API:", error); + }); + + return new HttpSuccess(); + } + + @Post("comment") + public async createcomment( + @Request() req: RequestWithUser, + @Body() + body: { + stateId: string; + isAccept?: boolean | null; + isApprove?: boolean | null; + reason?: string | null; + }, + ) { + const profile = await this.profileRepo.findOne({ + where: { + keycloak: req.user.sub, + }, + }); + if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งาน"); + const state = await this.stateRepo.findOne({ + where: { + id: body.stateId, + }, + }); + if (!state) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลขั้นตอนการอนุมัติ"); + let _null: any = null; + const stateUserComment = new StateUserComment(); + stateUserComment.stateId = body.stateId; + stateUserComment.profileId = profile.id; + stateUserComment.isAccept = body.isAccept == null ? _null : body.isAccept; + stateUserComment.isApprove = body.isApprove == null ? _null : body.isAccept; + stateUserComment.reason = body.reason == null ? _null : body.isAccept; + stateUserComment.createdUserId = req.user.sub; + stateUserComment.createdFullName = req.user.name; + stateUserComment.createdAt = new Date(); + stateUserComment.lastUpdateUserId = req.user.sub; + stateUserComment.lastUpdateFullName = req.user.name; + stateUserComment.lastUpdatedAt = new Date(); + await this.stateUserCommentRepo.save(stateUserComment); + + return new HttpSuccess(); + } + + @Post("comment-state") + public async getCommentState( + @Request() req: RequestWithUser, + @Body() + body: { + stateId: string; + }, + ) { + const state = await this.stateRepo.findOne({ + where: { + id: body.stateId, + }, + order: { stateUserComments: { order: "ASC" } }, + relations: ["stateUserComments"], + }); + if (!state) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลขั้นตอนการอนุมัติ"); + + return new HttpSuccess(state.stateUserComments); + } + + @Post("comment-state-user") + public async getCommentStateUser( + @Request() req: RequestWithUser, + @Body() + body: { + stateId: string; + }, + ) { + const stateUserComment = await this.stateUserCommentRepo.findOne({ + where: { + profile: { + keycloak: req.user.sub, + }, + stateId: body.stateId, + }, + }); + + return new HttpSuccess({ + isAccept: stateUserComment?.isAccept || null, + isApprove: stateUserComment?.isApprove || null, + reason: stateUserComment?.reason || null, + isAcceptSetting: stateUserComment?.isAcceptSetting || null, + isApproveSetting: stateUserComment?.isApproveSetting || null, + isReasonSetting: stateUserComment?.isReasonSetting || null, + order: stateUserComment?.order || null, + stateId: stateUserComment?.stateId || null, + profileId: stateUserComment?.profileId || null, + }); + } } diff --git a/src/entities/MetaState.ts b/src/entities/MetaState.ts index fa2cf5ec..fbf61ce7 100644 --- a/src/entities/MetaState.ts +++ b/src/entities/MetaState.ts @@ -1,8 +1,7 @@ import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; import { MetaStateOperator } from "./MetaStateOperator"; -import { Workflow } from "./Workflow"; -import { metaWorkflow } from "./MetaWorkflow"; +import { MetaWorkflow } from "./MetaWorkflow"; @Entity("metaState") export class MetaState extends EntityBase { @@ -37,9 +36,9 @@ export class MetaState extends EntityBase { }) metaWorkflowId: string; - @ManyToOne(() => metaWorkflow, (metaWorkflow) => metaWorkflow.metaStates) + @ManyToOne(() => MetaWorkflow, (metaWorkflow) => metaWorkflow.metaStates) @JoinColumn({ name: "metaWorkflowId" }) - metaWorkflow: metaWorkflow; + metaWorkflow: MetaWorkflow; @OneToMany(() => MetaStateOperator, (metaStateOperator) => metaStateOperator.metaState) metaStateOperators: MetaStateOperator[]; diff --git a/src/entities/MetaWorkflow.ts b/src/entities/MetaWorkflow.ts index e787457c..defcd6d5 100644 --- a/src/entities/MetaWorkflow.ts +++ b/src/entities/MetaWorkflow.ts @@ -3,7 +3,7 @@ import { EntityBase } from "./base/Base"; import { MetaState } from "./MetaState"; @Entity("metaWorkflow") -export class metaWorkflow extends EntityBase { +export class MetaWorkflow extends EntityBase { @Column({ nullable: true, comment: "ชื่อ flow", diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index 0978f528..6b1cdec3 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -32,6 +32,8 @@ import { ProfileDevelopment } from "./ProfileDevelopment"; import { PermissionOrg } from "./PermissionOrg"; import { CommandSend } from "./CommandSend"; import { DevelopmentRequest } from "./DevelopmentRequest"; +import { StateOperatorUser } from "./StateOperatorUser"; +import { StateUserComment } from "./StateUserComment"; @Entity("profile") export class Profile extends EntityBase { @@ -378,6 +380,12 @@ export class Profile extends EntityBase { @OneToMany(() => CommandSend, (v) => v.profile) commandSends: CommandSend[]; + @OneToMany(() => StateOperatorUser, (v) => v.profile) + stateOperatorUsers: StateOperatorUser[]; + + @OneToMany(() => StateUserComment, (v) => v.profile) + stateUserComments: StateUserComment[]; + @ManyToOne(() => PosLevel, (posLevel) => posLevel.profiles) @JoinColumn({ name: "posLevelId" }) posLevel: PosLevel; diff --git a/src/entities/State.ts b/src/entities/State.ts index 949f0167..fb16afc9 100644 --- a/src/entities/State.ts +++ b/src/entities/State.ts @@ -2,6 +2,7 @@ import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; import { StateOperator } from "./StateOperator"; import { Workflow } from "./Workflow"; +import { StateUserComment } from "./StateUserComment"; @Entity("state") export class State extends EntityBase { @@ -42,4 +43,7 @@ export class State extends EntityBase { @OneToMany(() => StateOperator, (stateOperator) => stateOperator.state) stateOperators: StateOperator[]; + + @OneToMany(() => StateUserComment, (stateUserComment) => stateUserComment.state) + stateUserComments: StateUserComment[]; } diff --git a/src/entities/StateOperatorUser.ts b/src/entities/StateOperatorUser.ts index 5c890dd7..d9f2d6a8 100644 --- a/src/entities/StateOperatorUser.ts +++ b/src/entities/StateOperatorUser.ts @@ -2,6 +2,7 @@ import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; import { StateOperator } from "./StateOperator"; import { Workflow } from "./Workflow"; +import { Profile } from "./Profile"; @Entity("stateOperatorUser") export class StateOperatorUser extends EntityBase { @@ -13,14 +14,6 @@ export class StateOperatorUser extends EntityBase { }) operator: string; - @Column({ - nullable: true, - comment: "", - length: 255, - default: null, - }) - profile: string; - @Column({ nullable: true, comment: "ลำดับ", @@ -47,4 +40,17 @@ export class StateOperatorUser extends EntityBase { @ManyToOne(() => Workflow, (workflow) => workflow.stateOperatorUsers) @JoinColumn({ name: "workflowId" }) workflow: Workflow; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง profile", + type: "uuid", + default: null, + }) + profileId: string; + + @ManyToOne(() => Profile, (profile) => profile.stateOperatorUsers) + @JoinColumn({ name: "profileId" }) + profile: Profile; } diff --git a/src/entities/StateUserComment.ts b/src/entities/StateUserComment.ts new file mode 100644 index 00000000..516ac146 --- /dev/null +++ b/src/entities/StateUserComment.ts @@ -0,0 +1,79 @@ +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { State } from "./State"; +import { Profile } from "./Profile"; + +@Entity("stateUserComment") +export class StateUserComment extends EntityBase { + @Column({ + nullable: true, + comment: "เลือกรับทราบ", + default: null, + }) + isAccept: boolean; + + @Column({ + nullable: true, + comment: "เลือกพิจารณา", + default: null, + }) + isApprove: boolean; + + @Column({ + nullable: true, + comment: "แสดงความคิดเห็น", + length: 255, + default: null, + }) + reason: string; + + @Column({ + comment: "เลือกรับทราบ", + default: false, + }) + isAcceptSetting: boolean; + + @Column({ + comment: "เลือกพิจารณา", + default: false, + }) + isApproveSetting: boolean; + + @Column({ + comment: "แสดงความคิดเห็น", + default: false, + }) + isReasonSetting: boolean; + + @Column({ + nullable: true, + comment: "ลำดับ", + default: null, + }) + order: number; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง state", + default: null, + }) + stateId: string; + + @ManyToOne(() => State, (state) => state.stateUserComments) + @JoinColumn({ name: "stateId" }) + state: State; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง profile", + type: "uuid", + default: null, + }) + profileId: string; + + @ManyToOne(() => Profile, (profile) => profile.stateUserComments) + @JoinColumn({ name: "profileId" }) + profile: Profile; +} diff --git a/src/entities/Workflow.ts b/src/entities/Workflow.ts index c41d442c..0c6090d6 100644 --- a/src/entities/Workflow.ts +++ b/src/entities/Workflow.ts @@ -5,6 +5,22 @@ import { StateOperatorUser } from "./StateOperatorUser"; @Entity("workflow") export class Workflow extends EntityBase { + @Column({ + nullable: true, + comment: "refIdw", + length: 255, + default: null, + }) + refId: string; + + @Column({ + nullable: true, + comment: "system", + length: 255, + default: null, + }) + system: string; + @Column({ nullable: true, comment: "ชื่อ flow", @@ -40,6 +56,14 @@ export class Workflow extends EntityBase { }) posLevelName: string; + @Column({ + nullable: true, + comment: "id state", + length: 100, + default: null, + }) + stateId: string; + @Column({ nullable: true, comment: "ชื่อประเภท", diff --git a/src/migration/1729044078594-add_table_workflow5.ts b/src/migration/1729044078594-add_table_workflow5.ts new file mode 100644 index 00000000..eaf2f203 --- /dev/null +++ b/src/migration/1729044078594-add_table_workflow5.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableWorkflow51729044078594 implements MigrationInterface { + name = 'AddTableWorkflow51729044078594' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`workflow\` ADD \`stateId\` varchar(100) NULL COMMENT 'id state'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`workflow\` DROP COLUMN \`stateId\``); + } + +} diff --git a/src/migration/1729047708690-add_table_workflow6.ts b/src/migration/1729047708690-add_table_workflow6.ts new file mode 100644 index 00000000..f50923c2 --- /dev/null +++ b/src/migration/1729047708690-add_table_workflow6.ts @@ -0,0 +1,26 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableWorkflow61729047708690 implements MigrationInterface { + name = 'AddTableWorkflow61729047708690' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` CHANGE \`profile\` \`profileId\` varchar(255) NULL`); + await queryRunner.query(`CREATE TABLE \`stateUserComment\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`isAccept\` tinyint NULL COMMENT 'เลือกรับทราบ', \`isApprove\` tinyint NULL COMMENT 'เลือกพิจารณา', \`reason\` varchar(255) NULL COMMENT 'แสดงความคิดเห็น', \`isAcceptSetting\` tinyint NOT NULL COMMENT 'เลือกรับทราบ' DEFAULT 0, \`isApproveSetting\` tinyint NOT NULL COMMENT 'เลือกพิจารณา' DEFAULT 0, \`isReasonSetting\` tinyint NOT NULL COMMENT 'แสดงความคิดเห็น' DEFAULT 0, \`order\` int NULL COMMENT 'ลำดับ', \`stateId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง state', \`profileId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง profile', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` DROP COLUMN \`profileId\``); + await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` ADD \`profileId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง profile'`); + await queryRunner.query(`ALTER TABLE \`stateUserComment\` ADD CONSTRAINT \`FK_f6ed25f165eb356ea5499484452\` FOREIGN KEY (\`stateId\`) REFERENCES \`state\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`stateUserComment\` ADD CONSTRAINT \`FK_f83cf9aef7ece2cddc2bb7c5a55\` FOREIGN KEY (\`profileId\`) REFERENCES \`profile\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` ADD CONSTRAINT \`FK_f64285e5016ad2932f38c8687a1\` FOREIGN KEY (\`profileId\`) REFERENCES \`profile\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` DROP FOREIGN KEY \`FK_f64285e5016ad2932f38c8687a1\``); + await queryRunner.query(`ALTER TABLE \`stateUserComment\` DROP FOREIGN KEY \`FK_f83cf9aef7ece2cddc2bb7c5a55\``); + await queryRunner.query(`ALTER TABLE \`stateUserComment\` DROP FOREIGN KEY \`FK_f6ed25f165eb356ea5499484452\``); + await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` DROP COLUMN \`profileId\``); + await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` ADD \`profileId\` varchar(255) NULL`); + await queryRunner.query(`DROP TABLE \`stateUserComment\``); + await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` CHANGE \`profileId\` \`profile\` varchar(255) NULL`); + } + +} diff --git a/src/migration/1729055668134-add_table_workflow7.ts b/src/migration/1729055668134-add_table_workflow7.ts new file mode 100644 index 00000000..d9f4d32f --- /dev/null +++ b/src/migration/1729055668134-add_table_workflow7.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableWorkflow71729055668134 implements MigrationInterface { + name = 'AddTableWorkflow71729055668134' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`workflow\` ADD \`refId\` varchar(255) NULL COMMENT 'refIdw'`); + await queryRunner.query(`ALTER TABLE \`workflow\` ADD \`system\` varchar(255) NULL COMMENT 'system'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`workflow\` DROP COLUMN \`system\``); + await queryRunner.query(`ALTER TABLE \`workflow\` DROP COLUMN \`refId\``); + } + +}