no message
This commit is contained in:
parent
f67dab02a0
commit
2b9cd85532
4 changed files with 111 additions and 63 deletions
|
|
@ -11,6 +11,9 @@ 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("Workflow")
|
||||
|
|
@ -23,52 +26,84 @@ export class WorkflowController extends Controller {
|
|||
private stateUserCommentRepo = AppDataSource.getRepository(StateUserComment);
|
||||
private profileRepo = AppDataSource.getRepository(Profile);
|
||||
|
||||
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: {
|
||||
profileId: 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.profileId = item.profileId;
|
||||
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")
|
||||
|
|
@ -168,24 +203,17 @@ export class WorkflowController extends Controller {
|
|||
system: string;
|
||||
},
|
||||
) {
|
||||
const profile = await this.profileRepo.findOne({
|
||||
where: {
|
||||
keycloak: req.user.sub,
|
||||
},
|
||||
});
|
||||
if (!profile) 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 stateOperatorUser = await this.stateOperatorUserRepo.findOne({
|
||||
where: {
|
||||
workflowId: workflow.id,
|
||||
workflow: {
|
||||
refId: body.refId,
|
||||
system: body.system,
|
||||
},
|
||||
profile: {
|
||||
keycloak: req.user.sub,
|
||||
},
|
||||
},
|
||||
relations: ["workflow"],
|
||||
});
|
||||
if (!stateOperatorUser)
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ผู้ใช้งานนี้ไม่มีหน้าที่ในกระบวนการนี้");
|
||||
|
|
@ -193,7 +221,7 @@ export class WorkflowController extends Controller {
|
|||
const operator = await this.stateOperatorRepo.findOne({
|
||||
where: {
|
||||
operator: stateOperatorUser.operator,
|
||||
stateId: workflow.stateId,
|
||||
stateId: stateOperatorUser.workflow.stateId,
|
||||
},
|
||||
relations: ["state"],
|
||||
});
|
||||
|
|
@ -222,19 +250,14 @@ export class WorkflowController extends Controller {
|
|||
system: string;
|
||||
},
|
||||
) {
|
||||
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.find({
|
||||
where: {
|
||||
workflowId: workflow.id,
|
||||
workflow: {
|
||||
refId: body.refId,
|
||||
system: body.system,
|
||||
},
|
||||
},
|
||||
order: { stateUserComments: { order: "ASC" } },
|
||||
order: { order: "ASC", stateUserComments: { order: "ASC" } },
|
||||
relations: ["stateUserComments"],
|
||||
});
|
||||
const _state = state.map((x) => ({
|
||||
|
|
@ -255,6 +278,20 @@ export class WorkflowController extends Controller {
|
|||
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,
|
||||
|
|
@ -480,15 +517,11 @@ export class WorkflowController extends Controller {
|
|||
stateId: string;
|
||||
},
|
||||
) {
|
||||
const profile = await this.profileRepo.findOne({
|
||||
where: {
|
||||
keycloak: req.user.sub,
|
||||
},
|
||||
});
|
||||
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งาน");
|
||||
const stateUserComment = await this.stateUserCommentRepo.findOne({
|
||||
where: {
|
||||
profileId: profile.id,
|
||||
profile: {
|
||||
keycloak: req.user.sub,
|
||||
},
|
||||
stateId: body.stateId,
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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[];
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
16
src/migration/1729055668134-add_table_workflow7.ts
Normal file
16
src/migration/1729055668134-add_table_workflow7.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class AddTableWorkflow71729055668134 implements MigrationInterface {
|
||||
name = 'AddTableWorkflow71729055668134'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
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<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`workflow\` DROP COLUMN \`system\``);
|
||||
await queryRunner.query(`ALTER TABLE \`workflow\` DROP COLUMN \`refId\``);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue