forked from Yara724/api
Enforce claim beneficiary access and retire unused legacy APIs
This commit is contained in:
@@ -1,39 +1,36 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Patch,
|
||||
Param,
|
||||
Controller,
|
||||
Delete,
|
||||
Query,
|
||||
Get,
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
} from '@nestjs/common';
|
||||
import {
|
||||
ApiTags,
|
||||
ApiOperation,
|
||||
ApiResponse,
|
||||
ApiBody,
|
||||
ApiParam,
|
||||
ApiQuery,
|
||||
ApiBearerAuth
|
||||
} from '@nestjs/swagger';
|
||||
import { WorkflowStepManagementService } from './workflow-step-management.service';
|
||||
import { CreateWorkflowStepDto } from './dto/create-workflow-step.dto';
|
||||
import { UpdateWorkflowStepDto } from './dto/update-workflow-step.dto';
|
||||
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';
|
||||
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,
|
||||
bulkUpsertWorkflowStepExamples,
|
||||
validateAccessExamples,
|
||||
claimWorkflowStepExamples,
|
||||
} from './dto/workflow-step.examples';
|
||||
} from "./dto/workflow-step.examples";
|
||||
import { WorkflowStepManagementService } from "./workflow-step-management.service";
|
||||
|
||||
@ApiTags('Workflow Step Management')
|
||||
@Controller('workflow-step-management')
|
||||
@ApiTags("Workflow Step Management")
|
||||
@Controller("workflow-step-management")
|
||||
export class WorkflowStepManagementController {
|
||||
constructor(
|
||||
private readonly workflowStepManagementService: WorkflowStepManagementService,
|
||||
@@ -44,20 +41,24 @@ export class WorkflowStepManagementController {
|
||||
*/
|
||||
@Post()
|
||||
@HttpCode(HttpStatus.CREATED)
|
||||
@ApiOperation({
|
||||
summary: 'Create a new workflow step',
|
||||
description: 'Creates a new workflow step configuration with fields and validation rules'
|
||||
@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
|
||||
}
|
||||
...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' })
|
||||
@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);
|
||||
}
|
||||
@@ -66,20 +67,24 @@ export class WorkflowStepManagementController {
|
||||
* Get all active workflow steps
|
||||
*/
|
||||
@Get()
|
||||
@ApiOperation({
|
||||
summary: 'Get all workflow steps',
|
||||
description: 'Retrieves all workflow steps, optionally including inactive ones'
|
||||
@ApiOperation({
|
||||
summary: "Get all workflow steps",
|
||||
description:
|
||||
"Retrieves all workflow steps, optionally including inactive ones",
|
||||
})
|
||||
@ApiQuery({
|
||||
name: 'includeInactive',
|
||||
required: false,
|
||||
@ApiQuery({
|
||||
name: "includeInactive",
|
||||
required: false,
|
||||
type: String,
|
||||
description: 'Set to "true" to include inactive steps',
|
||||
example: 'false'
|
||||
example: "false",
|
||||
})
|
||||
@ApiResponse({ status: 200, description: 'List of workflow steps retrieved successfully' })
|
||||
async findAll(@Query('includeInactive') includeInactive?: string) {
|
||||
if (includeInactive === 'true') {
|
||||
@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();
|
||||
@@ -88,58 +93,77 @@ export class WorkflowStepManagementController {
|
||||
/**
|
||||
* Update a workflow step by ID
|
||||
*/
|
||||
@Patch(':id')
|
||||
@ApiOperation({
|
||||
summary: 'Update workflow step by ID',
|
||||
description: 'Updates a workflow step using its database 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",
|
||||
})
|
||||
@ApiParam({ name: 'id', description: 'Workflow step ID', example: '507f1f77bcf86cd799439011' })
|
||||
@ApiBody({
|
||||
type: UpdateWorkflowStepDto,
|
||||
examples: updateWorkflowStepExamples
|
||||
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) {
|
||||
@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'
|
||||
@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'
|
||||
@ApiParam({
|
||||
name: "stepKey",
|
||||
description: "Workflow step key (blame or claim)",
|
||||
example: "FIRST_VIDEO",
|
||||
})
|
||||
@ApiBody({
|
||||
type: UpdateWorkflowStepDto,
|
||||
examples: updateWorkflowStepExamples
|
||||
examples: updateWorkflowStepExamples,
|
||||
})
|
||||
@ApiResponse({ status: 200, description: 'Workflow step updated successfully' })
|
||||
@ApiResponse({ status: 404, description: 'Workflow step not found' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: "Workflow step updated successfully",
|
||||
})
|
||||
@ApiResponse({ status: 404, description: "Workflow step not found" })
|
||||
async updateByStepKey(
|
||||
@Param('stepKey') stepKey: WorkflowStep | ClaimWorkflowStep,
|
||||
@Param("stepKey") stepKey: WorkflowStep | ClaimWorkflowStep,
|
||||
@Body() updateDto: UpdateWorkflowStepDto,
|
||||
) {
|
||||
return await this.workflowStepManagementService.updateByStepKey(stepKey as any, updateDto);
|
||||
return await this.workflowStepManagementService.updateByStepKey(
|
||||
stepKey as any,
|
||||
updateDto,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize default workflow steps
|
||||
*/
|
||||
@Post('initialize')
|
||||
@Post("initialize")
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ApiOperation({
|
||||
summary: 'Initialize default workflow steps',
|
||||
description: 'Creates default workflow step configurations for the system'
|
||||
@ApiOperation({
|
||||
summary: "Initialize default workflow steps",
|
||||
description: "Creates default workflow step configurations for the system",
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: "Default steps initialized successfully",
|
||||
})
|
||||
@ApiResponse({ status: 200, description: 'Default steps initialized successfully' })
|
||||
async initialize() {
|
||||
return await this.workflowStepManagementService.initializeDefaultSteps();
|
||||
}
|
||||
@@ -147,207 +171,80 @@ export class WorkflowStepManagementController {
|
||||
/**
|
||||
* 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.'
|
||||
@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',
|
||||
@ApiParam({
|
||||
name: "identifier",
|
||||
description: 'Step key (e.g., "FIRST_VIDEO") or step number (e.g., 3)',
|
||||
example: 'FIRST_VIDEO',
|
||||
example: "FIRST_VIDEO",
|
||||
examples: {
|
||||
byStepKey: {
|
||||
summary: 'By Step Key',
|
||||
value: 'FIRST_VIDEO'
|
||||
summary: "By Step Key",
|
||||
value: "FIRST_VIDEO",
|
||||
},
|
||||
byStepNumber: {
|
||||
summary: 'By Step Number',
|
||||
value: 3
|
||||
}
|
||||
}
|
||||
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);
|
||||
@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'
|
||||
@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) {
|
||||
@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')
|
||||
@Delete(":id")
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ApiOperation({
|
||||
summary: 'Delete workflow step',
|
||||
description: 'Soft deletes a workflow step by setting isActive to false'
|
||||
@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) {
|
||||
@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);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// DEPRECATED ENDPOINTS - Will be removed in future versions
|
||||
// ============================================================
|
||||
|
||||
/**
|
||||
* @deprecated Use individual create endpoint instead
|
||||
* Bulk upsert steps (for initial setup or migrations)
|
||||
*/
|
||||
@Post('bulk-upsert')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ApiOperation({
|
||||
summary: '[DEPRECATED] Bulk upsert workflow steps',
|
||||
description: 'This endpoint is deprecated and will be removed in a future version. Use the individual create endpoint instead.',
|
||||
deprecated: true
|
||||
})
|
||||
@ApiBody({
|
||||
type: [CreateWorkflowStepDto],
|
||||
examples: bulkUpsertWorkflowStepExamples
|
||||
})
|
||||
@ApiResponse({ status: 200, description: 'Steps upserted successfully' })
|
||||
async bulkUpsert(@Body() steps: CreateWorkflowStepDto[]) {
|
||||
return await this.workflowStepManagementService.bulkUpsert(steps);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This endpoint is no longer needed
|
||||
* Validate step access
|
||||
*/
|
||||
@Post('validate-access')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ApiOperation({
|
||||
summary: '[DEPRECATED] Validate step access',
|
||||
description: 'This endpoint is deprecated and will be removed in a future version.',
|
||||
deprecated: true
|
||||
})
|
||||
@ApiBody({
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
stepKey: {
|
||||
type: 'string',
|
||||
description: 'Workflow step key (blame or claim)',
|
||||
example: 'FIRST_VIDEO'
|
||||
},
|
||||
completedSteps: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string'
|
||||
},
|
||||
example: ['CREATED']
|
||||
}
|
||||
}
|
||||
},
|
||||
examples: validateAccessExamples
|
||||
})
|
||||
@ApiResponse({ status: 200, description: 'Validation result returned' })
|
||||
async validateAccess(
|
||||
@Body() body: { stepKey: WorkflowStep | ClaimWorkflowStep; completedSteps: (WorkflowStep | ClaimWorkflowStep)[] },
|
||||
) {
|
||||
return await this.workflowStepManagementService.validateStepAccess(
|
||||
body.stepKey as any,
|
||||
body.completedSteps as any,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This endpoint is no longer needed
|
||||
* Get steps by category
|
||||
*/
|
||||
@Get('category/:category')
|
||||
@ApiOperation({
|
||||
summary: '[DEPRECATED] Get steps by category',
|
||||
description: 'This endpoint is deprecated and will be removed in a future version.',
|
||||
deprecated: true
|
||||
})
|
||||
@ApiParam({
|
||||
name: 'category',
|
||||
description: 'Step category',
|
||||
example: 'FIRST_PARTY',
|
||||
enum: ['INITIAL', 'FIRST_PARTY', 'SECOND_PARTY', 'RESOLUTION']
|
||||
})
|
||||
@ApiResponse({ status: 200, description: 'Steps retrieved successfully' })
|
||||
async findByCategory(@Param('category') category: string) {
|
||||
return await this.workflowStepManagementService.findByCategory(category);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This endpoint is no longer needed
|
||||
* Get next possible steps from current step
|
||||
*/
|
||||
@Get('next-steps/:stepKey')
|
||||
@ApiOperation({
|
||||
summary: '[DEPRECATED] Get next possible steps',
|
||||
description: 'This endpoint is deprecated and will be removed in a future version.',
|
||||
deprecated: true
|
||||
})
|
||||
@ApiParam({
|
||||
name: 'stepKey',
|
||||
description: 'Current workflow step key (blame or claim)',
|
||||
example: 'FIRST_VIDEO'
|
||||
})
|
||||
@ApiResponse({ status: 200, description: 'Next steps retrieved successfully' })
|
||||
async getNextSteps(@Param('stepKey') stepKey: WorkflowStep | ClaimWorkflowStep) {
|
||||
return await this.workflowStepManagementService.getNextSteps(stepKey as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This endpoint is no longer needed
|
||||
* Get step fields (for form generation)
|
||||
*/
|
||||
@Get('fields/:stepKey')
|
||||
@ApiOperation({
|
||||
summary: '[DEPRECATED] Get step fields',
|
||||
description: 'This endpoint is deprecated and will be removed in a future version.',
|
||||
deprecated: true
|
||||
})
|
||||
@ApiParam({
|
||||
name: 'stepKey',
|
||||
description: 'Workflow step key (blame or claim)',
|
||||
example: 'FIRST_VIDEO'
|
||||
})
|
||||
@ApiResponse({ status: 200, description: 'Step fields retrieved successfully' })
|
||||
async getStepFields(@Param('stepKey') stepKey: WorkflowStep | ClaimWorkflowStep) {
|
||||
return await this.workflowStepManagementService.getStepFields(stepKey as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use findById instead
|
||||
* Get a specific step by key
|
||||
*/
|
||||
@Get('step/:stepKey')
|
||||
@ApiOperation({
|
||||
summary: '[DEPRECATED] Get workflow step by key',
|
||||
description: 'This endpoint is deprecated and will be removed in a future version. Use GET /:id instead.',
|
||||
deprecated: true
|
||||
})
|
||||
@ApiParam({
|
||||
name: 'stepKey',
|
||||
description: 'Workflow step key (blame or claim)',
|
||||
example: 'FIRST_VIDEO'
|
||||
})
|
||||
@ApiResponse({ status: 200, description: 'Workflow step retrieved successfully' })
|
||||
@ApiResponse({ status: 404, description: 'Workflow step not found' })
|
||||
async findByStepKey(@Param('stepKey') stepKey: WorkflowStep | ClaimWorkflowStep) {
|
||||
return await this.workflowStepManagementService.findByStepKey(stepKey as any);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user