260228:1427 20260228:14:00 workflow update
All checks were successful
Build and Deploy / deploy (push) Successful in 2m37s

This commit is contained in:
admin
2026-02-28 14:27:33 +07:00
parent 276d06e950
commit efd5183906
6 changed files with 73 additions and 33 deletions

View File

@@ -52,12 +52,26 @@ export class WorkflowEngineController {
return this.workflowService.createDefinition(dto);
}
@Get('definitions')
@ApiOperation({ summary: 'ดึง Workflow Definition ทั้งหมด' })
@RequirePermission('system.manage_all')
async getDefinitions() {
return this.workflowService.getDefinitions();
}
@Get('definitions/:id')
@ApiOperation({ summary: 'ดึง Workflow Definition ด้วย ID' })
@RequirePermission('system.manage_all')
async getDefinitionById(@Param('id') id: string) {
return this.workflowService.getDefinitionById(id);
}
@Patch('definitions/:id')
@ApiOperation({ summary: 'แก้ไข Workflow Definition (Re-compile DSL)' })
@RequirePermission('system.manage_all')
async updateDefinition(
@Param('id') id: string,
@Body() dto: UpdateWorkflowDefinitionDto,
@Body() dto: UpdateWorkflowDefinitionDto
) {
return this.workflowService.update(id, dto);
}
@@ -81,7 +95,7 @@ export class WorkflowEngineController {
async processTransition(
@Param('id') instanceId: string,
@Body() dto: WorkflowTransitionDto,
@Request() req: any,
@Request() req: any
) {
// ดึง User ID จาก Token (req.user มาจาก JwtStrategy)
const userId = req.user?.userId;
@@ -91,7 +105,7 @@ export class WorkflowEngineController {
dto.action,
userId,
dto.comment,
dto.payload,
dto.payload
);
}

View File

@@ -121,6 +121,33 @@ export class WorkflowEngineService {
return this.workflowDefRepo.save(definition);
}
/**
* ดึง Workflow Definition ทั้งหมด (เฉพาะ Version ล่าสุดของแต่ละ Workflow Code)
*/
async getDefinitions(): Promise<WorkflowDefinition[]> {
// หา version ล่าสุดของแต่ละ workflow_code
// ใช้ query builder เพื่อ group by และหา max version
const latestDefinitions = await this.workflowDefRepo
.createQueryBuilder('def')
.where(
'def.version = (SELECT MAX(sub.version) FROM workflow_definitions sub WHERE sub.workflow_code = def.workflow_code)',
)
.getMany();
return latestDefinitions;
}
/**
* ดึง Workflow Definition ตาม ID หรือ Code
*/
async getDefinitionById(id: string): Promise<WorkflowDefinition> {
const definition = await this.workflowDefRepo.findOne({ where: { id } });
if (!definition) {
throw new NotFoundException(`Workflow Definition with ID "${id}" not found`);
}
return definition;
}
/**
* ดึง Action ที่ทำได้ ณ State ปัจจุบัน
*/