- Introduced Jurisdiction and RuleCategory entities along with their respective values. - Implemented service methods for managing rule categories and values. - Updated MasterDataService to include seeding logic for jurisdictions and rule categories. - Added DTOs for creating and updating rule categories and values. feat(policy-engine): enhance policy management with new entities and operations - Created Policy, PolicyRule, PolicyAction, PolicyTargetAudience, and RuleCondition entities. - Implemented create, update, and delete operations for policies and their associated rules and actions. - Added enums for PolicyStatus and AudienceType to manage policy states and target audiences. - Developed DTOs for creating and updating policies with nested structures for rules and audiences.
290 lines
9.7 KiB
TypeScript
290 lines
9.7 KiB
TypeScript
import { Controller, Get, Post, Put, Delete, Param, Body } from '@nestjs/common';
|
|
import { ApiBody, ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
import { MasterDataService } from './master-data.service';
|
|
import { CreateMasterDataDto } from './dto/create-master-data.dto';
|
|
import { UpdateMasterDataDto } from './dto/update-master-data.dto';
|
|
import { CreateRuleCategoryDto } from './dto/create-rule-category.dto';
|
|
import { UpdateRuleCategoryDto } from './dto/update-rule-category.dto';
|
|
import { CreateRuleCategoryValueDto } from './dto/create-rule-category-value.dto';
|
|
import { UpdateRuleCategoryValueDto } from './dto/update-rule-category-value.dto';
|
|
import { CreateOperatorDto } from './dto/create-operator.dto';
|
|
import { UpdateOperatorDto } from './dto/update-operator.dto';
|
|
|
|
@ApiTags('master-data')
|
|
@Controller('master-data')
|
|
export class MasterDataController {
|
|
constructor(private readonly masterDataService: MasterDataService) {}
|
|
|
|
@Get('rule-categories')
|
|
@ApiOperation({ summary: 'Get all rule categories' })
|
|
@ApiResponse({ status: 200, description: 'List of rule categories' })
|
|
async findAllRuleCategories() {
|
|
return this.masterDataService.findAllRuleCategories();
|
|
}
|
|
|
|
@Get('rule-categories/:id')
|
|
@ApiOperation({ summary: 'Get one rule category' })
|
|
@ApiParam({ name: 'id', type: String, description: 'Rule category id' })
|
|
@ApiResponse({ status: 200, description: 'Rule category found' })
|
|
async findOneRuleCategory(@Param('id') id: string) {
|
|
return this.masterDataService.findOneRuleCategory(id);
|
|
}
|
|
|
|
@Post('rule-categories')
|
|
@ApiOperation({ summary: 'Create a rule category' })
|
|
@ApiBody({
|
|
type: CreateRuleCategoryDto,
|
|
description: 'Rule category payload',
|
|
examples: {
|
|
default: {
|
|
value: {
|
|
code: 'fare-type',
|
|
name: 'Fare Type',
|
|
description: 'Fare-related rule categories',
|
|
displayOrder: 1,
|
|
isActive: true,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
@ApiResponse({ status: 201, description: 'Rule category created' })
|
|
async createRuleCategory(@Body() createDto: CreateRuleCategoryDto) {
|
|
return this.masterDataService.createRuleCategory(createDto);
|
|
}
|
|
|
|
@Put('rule-categories/:id')
|
|
@ApiOperation({ summary: 'Update a rule category' })
|
|
@ApiParam({ name: 'id', type: String, description: 'Rule category id' })
|
|
@ApiBody({
|
|
type: UpdateRuleCategoryDto,
|
|
description: 'Rule category update payload',
|
|
examples: {
|
|
default: {
|
|
value: {
|
|
name: 'Fare Type',
|
|
description: 'Updated fare rule category',
|
|
displayOrder: 2,
|
|
isActive: true,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
@ApiResponse({ status: 200, description: 'Rule category updated' })
|
|
async updateRuleCategory(
|
|
@Param('id') id: string,
|
|
@Body() updateDto: UpdateRuleCategoryDto,
|
|
) {
|
|
return this.masterDataService.updateRuleCategory(id, updateDto);
|
|
}
|
|
|
|
@Delete('rule-categories/:id')
|
|
@ApiOperation({ summary: 'Delete a rule category' })
|
|
@ApiParam({ name: 'id', type: String, description: 'Rule category id' })
|
|
@ApiResponse({ status: 200, description: 'Rule category deleted' })
|
|
async removeRuleCategory(@Param('id') id: string) {
|
|
return this.masterDataService.removeRuleCategory(id);
|
|
}
|
|
|
|
@Get('rule-category-values')
|
|
@ApiOperation({ summary: 'Get all rule category values' })
|
|
@ApiResponse({ status: 200, description: 'List of rule category values' })
|
|
async findAllRuleCategoryValues() {
|
|
return this.masterDataService.findAllRuleCategoryValues();
|
|
}
|
|
|
|
@Get('rule-category-values/:code')
|
|
@ApiOperation({ summary: 'Get rule category values by category code' })
|
|
@ApiParam({ name: 'code', type: String, description: 'Rule category code' })
|
|
@ApiResponse({ status: 200, description: 'Rule category values for the requested code' })
|
|
async findRuleCategoryValuesByCode(@Param('code') code: string) {
|
|
return this.masterDataService.findRuleCategoryValuesByCode(code);
|
|
}
|
|
|
|
@Get('rule-category-values/:id')
|
|
@ApiOperation({ summary: 'Get one rule category value' })
|
|
@ApiParam({ name: 'id', type: String, description: 'Rule category value id' })
|
|
@ApiResponse({ status: 200, description: 'Rule category value found' })
|
|
async findOneRuleCategoryValue(@Param('id') id: string) {
|
|
return this.masterDataService.findOneRuleCategoryValue(id);
|
|
}
|
|
|
|
@Post('rule-category-values')
|
|
@ApiOperation({ summary: 'Create a rule category value' })
|
|
@ApiBody({
|
|
type: CreateRuleCategoryValueDto,
|
|
description: 'Rule category value payload',
|
|
examples: {
|
|
default: {
|
|
value: {
|
|
categoryId: '00000000-0000-0000-0000-000000000000',
|
|
code: 'economy',
|
|
value: 'Economy',
|
|
displayOrder: 1,
|
|
isActive: true,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
@ApiResponse({ status: 201, description: 'Rule category value created' })
|
|
async createRuleCategoryValue(@Body() createDto: CreateRuleCategoryValueDto) {
|
|
return this.masterDataService.createRuleCategoryValue(createDto);
|
|
}
|
|
|
|
@Put('rule-category-values/:id')
|
|
@ApiOperation({ summary: 'Update a rule category value' })
|
|
@ApiParam({ name: 'id', type: String, description: 'Rule category value id' })
|
|
@ApiBody({
|
|
type: UpdateRuleCategoryValueDto,
|
|
description: 'Rule category value update payload',
|
|
examples: {
|
|
default: {
|
|
value: {
|
|
value: 'Premium Economy',
|
|
displayOrder: 2,
|
|
isActive: true,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
@ApiResponse({ status: 200, description: 'Rule category value updated' })
|
|
async updateRuleCategoryValue(
|
|
@Param('id') id: string,
|
|
@Body() updateDto: UpdateRuleCategoryValueDto,
|
|
) {
|
|
return this.masterDataService.updateRuleCategoryValue(id, updateDto);
|
|
}
|
|
|
|
@Delete('rule-category-values/:id')
|
|
@ApiOperation({ summary: 'Delete a rule category value' })
|
|
@ApiParam({ name: 'id', type: String, description: 'Rule category value id' })
|
|
@ApiResponse({ status: 200, description: 'Rule category value deleted' })
|
|
async removeRuleCategoryValue(@Param('id') id: string) {
|
|
return this.masterDataService.removeRuleCategoryValue(id);
|
|
}
|
|
|
|
@Get('operators')
|
|
@ApiOperation({ summary: 'Get all operators' })
|
|
@ApiResponse({ status: 200, description: 'List of operators' })
|
|
async findAllOperators() {
|
|
return this.masterDataService.findAllOperators();
|
|
}
|
|
|
|
@Get('operators/:id')
|
|
@ApiOperation({ summary: 'Get one operator' })
|
|
@ApiParam({ name: 'id', type: String, description: 'Operator id' })
|
|
@ApiResponse({ status: 200, description: 'Operator found' })
|
|
async findOneOperator(@Param('id') id: string) {
|
|
return this.masterDataService.findOneOperator(id);
|
|
}
|
|
|
|
@Post('operators')
|
|
@ApiOperation({ summary: 'Create an operator' })
|
|
@ApiBody({
|
|
type: CreateOperatorDto,
|
|
description: 'Operator payload',
|
|
examples: {
|
|
default: {
|
|
value: {
|
|
code: 'EQ',
|
|
name: 'Equals',
|
|
symbol: '=',
|
|
displayOrder: 1,
|
|
isActive: true,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
@ApiResponse({ status: 201, description: 'Operator created' })
|
|
async createOperator(@Body() createDto: CreateOperatorDto) {
|
|
return this.masterDataService.createOperator(createDto);
|
|
}
|
|
|
|
@Put('operators/:id')
|
|
@ApiOperation({ summary: 'Update an operator' })
|
|
@ApiParam({ name: 'id', type: String, description: 'Operator id' })
|
|
@ApiBody({
|
|
type: UpdateOperatorDto,
|
|
description: 'Operator update payload',
|
|
examples: {
|
|
default: {
|
|
value: {
|
|
name: 'Equals',
|
|
symbol: '=',
|
|
displayOrder: 1,
|
|
isActive: true,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
@ApiResponse({ status: 200, description: 'Operator updated' })
|
|
async updateOperator(@Param('id') id: string, @Body() updateDto: UpdateOperatorDto) {
|
|
return this.masterDataService.updateOperator(id, updateDto);
|
|
}
|
|
|
|
@Delete('operators/:id')
|
|
@ApiOperation({ summary: 'Delete an operator' })
|
|
@ApiParam({ name: 'id', type: String, description: 'Operator id' })
|
|
@ApiResponse({ status: 200, description: 'Operator deleted' })
|
|
async removeOperator(@Param('id') id: string) {
|
|
return this.masterDataService.removeOperator(id);
|
|
}
|
|
|
|
@Get('jurisdictions')
|
|
@ApiOperation({ summary: 'Get all jurisdictions' })
|
|
@ApiResponse({ status: 200, description: 'List of jurisdictions' })
|
|
async findAllJurisdictions() {
|
|
return this.masterDataService.findAll('JURISDICTION');
|
|
}
|
|
|
|
@Get('jurisdictions/:id')
|
|
@ApiOperation({ summary: 'Get one jurisdiction' })
|
|
@ApiParam({ name: 'id', type: String, description: 'Jurisdiction id' })
|
|
@ApiResponse({ status: 200, description: 'Jurisdiction found' })
|
|
async findOneJurisdiction(@Param('id') id: string) {
|
|
return this.masterDataService.findOne('JURISDICTION', id);
|
|
}
|
|
|
|
// Example: POST /master-data/REGION
|
|
@Post(':category')
|
|
async create(
|
|
@Param('category') category: string,
|
|
@Body() createDto: CreateMasterDataDto,
|
|
) {
|
|
return this.masterDataService.create(category, createDto);
|
|
}
|
|
|
|
// Example: GET /master-data/REGION
|
|
@Get(':category')
|
|
async findAll(@Param('category') category: string) {
|
|
return this.masterDataService.findAll(category);
|
|
}
|
|
|
|
// Example: GET /master-data/REGION/uuid
|
|
@Get(':category/:id')
|
|
async findOne(
|
|
@Param('category') category: string,
|
|
@Param('id') id: string,
|
|
) {
|
|
return this.masterDataService.findOne(category, id);
|
|
}
|
|
|
|
// Example: PUT /master-data/REGION/uuid
|
|
@Put(':category/:id')
|
|
async update(
|
|
@Param('category') category: string,
|
|
@Param('id') id: string,
|
|
@Body() updateDto: UpdateMasterDataDto,
|
|
) {
|
|
return this.masterDataService.update(category, id, updateDto);
|
|
}
|
|
|
|
// Example: DELETE /master-data/REGION/uuid
|
|
@Delete(':category/:id')
|
|
async remove(
|
|
@Param('category') category: string,
|
|
@Param('id') id: string,
|
|
) {
|
|
return this.masterDataService.remove(category, id);
|
|
}
|
|
}
|