Files
yara724api/src/workflow-step-management/workflow-step-management.controller.ts
T

251 lines
6.7 KiB
TypeScript

import {
Body,
Controller,
Delete,
Get,
HttpCode,
HttpStatus,
Param,
Patch,
Post,
Query,
} from "@nestjs/common";
import {
ApiBody,
ApiOperation,
ApiParam,
ApiQuery,
ApiResponse,
ApiTags,
} from "@nestjs/swagger";
import { WorkflowStep } from "src/Types&Enums/blame-request-management/blameWorkflow-steps.enum";
import { ClaimWorkflowStep } from "src/Types&Enums/claim-request-management/claim-workflow-steps.enum";
import { CreateWorkflowStepDto } from "./dto/create-workflow-step.dto";
import { UpdateWorkflowStepDto } from "./dto/update-workflow-step.dto";
import {
claimWorkflowStepExamples,
createWorkflowStepExamples,
updateWorkflowStepExamples,
} from "./dto/workflow-step.examples";
import { WorkflowStepManagementService } from "./workflow-step-management.service";
@ApiTags("Workflow Step Management")
@Controller("workflow-step-management")
export class WorkflowStepManagementController {
constructor(
private readonly workflowStepManagementService: WorkflowStepManagementService,
) {}
/**
* Create a new workflow step configuration
*/
@Post()
@HttpCode(HttpStatus.CREATED)
@ApiOperation({
summary: "Create a new workflow step",
description:
"Creates a new workflow step configuration with fields and validation rules",
})
@ApiBody({
type: CreateWorkflowStepDto,
examples: {
...createWorkflowStepExamples,
...claimWorkflowStepExamples,
},
})
@ApiResponse({
status: 201,
description: "Workflow step created successfully",
})
@ApiResponse({ status: 400, description: "Bad request - Invalid input data" })
@ApiResponse({ status: 409, description: "Conflict - Step already exists" })
async create(@Body() createDto: CreateWorkflowStepDto) {
return await this.workflowStepManagementService.create(createDto);
}
/**
* Get all active workflow steps
*/
@Get()
@ApiOperation({
summary: "Get all workflow steps",
description:
"Retrieves all workflow steps, optionally including inactive ones",
})
@ApiQuery({
name: "includeInactive",
required: false,
type: String,
description: 'Set to "true" to include inactive steps',
example: "false",
})
@ApiResponse({
status: 200,
description: "List of workflow steps retrieved successfully",
})
async findAll(@Query("includeInactive") includeInactive?: string) {
if (includeInactive === "true") {
return await this.workflowStepManagementService.findAllIncludingInactive();
}
return await this.workflowStepManagementService.findAll();
}
/**
* Update a workflow step by ID
*/
@Patch(":id")
@ApiOperation({
summary: "Update workflow step by ID",
description: "Updates a workflow step using its database ID",
})
@ApiParam({
name: "id",
description: "Workflow step ID",
example: "507f1f77bcf86cd799439011",
})
@ApiBody({
type: UpdateWorkflowStepDto,
examples: updateWorkflowStepExamples,
})
@ApiResponse({
status: 200,
description: "Workflow step updated successfully",
})
@ApiResponse({ status: 404, description: "Workflow step not found" })
async update(
@Param("id") id: string,
@Body() updateDto: UpdateWorkflowStepDto,
) {
return await this.workflowStepManagementService.update(id, updateDto);
}
/**
* Update a workflow step by key
*/
@Patch("step/:stepKey")
@ApiOperation({
summary: "Update workflow step by key",
description: "Updates a workflow step using its step key from the enum",
})
@ApiParam({
name: "stepKey",
description: "Workflow step key (blame or claim)",
example: "FIRST_VIDEO",
})
@ApiBody({
type: UpdateWorkflowStepDto,
examples: updateWorkflowStepExamples,
})
@ApiResponse({
status: 200,
description: "Workflow step updated successfully",
})
@ApiResponse({ status: 404, description: "Workflow step not found" })
async updateByStepKey(
@Param("stepKey") stepKey: WorkflowStep | ClaimWorkflowStep,
@Body() updateDto: UpdateWorkflowStepDto,
) {
return await this.workflowStepManagementService.updateByStepKey(
stepKey as any,
updateDto,
);
}
/**
* Initialize default workflow steps
*/
@Post("initialize")
@HttpCode(HttpStatus.OK)
@ApiOperation({
summary: "Initialize default workflow steps",
description: "Creates default workflow step configurations for the system",
})
@ApiResponse({
status: 200,
description: "Default steps initialized successfully",
})
async initialize() {
return await this.workflowStepManagementService.initializeDefaultSteps();
}
/**
* Get a specific step by stepKey or stepNumber (intelligent lookup)
*/
@Get("find/:identifier")
@ApiOperation({
summary: "Get workflow step by stepKey or stepNumber",
description:
"Retrieves a workflow step by either its stepKey (enum) or stepNumber. Automatically detects which one is provided.",
})
@ApiParam({
name: "identifier",
description: 'Step key (e.g., "FIRST_VIDEO") or step number (e.g., 3)',
example: "FIRST_VIDEO",
examples: {
byStepKey: {
summary: "By Step Key",
value: "FIRST_VIDEO",
},
byStepNumber: {
summary: "By Step Number",
value: 3,
},
},
})
@ApiResponse({
status: 200,
description: "Workflow step retrieved successfully",
})
@ApiResponse({ status: 404, description: "Workflow step not found" })
async findByStepKeyOrNumber(@Param("identifier") identifier: string) {
return await this.workflowStepManagementService.findByStepKeyOrNumber(
identifier,
);
}
/**
* Get a specific step by ID
*/
@Get(":id")
@ApiOperation({
summary: "Get workflow step by ID",
description: "Retrieves a specific workflow step by its database ID",
})
@ApiParam({
name: "id",
description: "Workflow step ID",
example: "507f1f77bcf86cd799439011",
})
@ApiResponse({
status: 200,
description: "Workflow step retrieved successfully",
})
@ApiResponse({ status: 404, description: "Workflow step not found" })
async findById(@Param("id") id: string) {
return await this.workflowStepManagementService.findById(id);
}
/**
* Soft delete a step
*/
@Delete(":id")
@HttpCode(HttpStatus.OK)
@ApiOperation({
summary: "Delete workflow step",
description: "Soft deletes a workflow step by setting isActive to false",
})
@ApiParam({
name: "id",
description: "Workflow step ID",
example: "507f1f77bcf86cd799439011",
})
@ApiResponse({
status: 200,
description: "Workflow step deleted successfully",
})
@ApiResponse({ status: 404, description: "Workflow step not found" })
async remove(@Param("id") id: string) {
return await this.workflowStepManagementService.remove(id);
}
}