feat: add swagger docs for responses

This commit is contained in:
Ahmed Bouhuolia
2025-06-16 13:50:30 +02:00
parent 88ef60ef28
commit c4668d7d22
30 changed files with 1363 additions and 64 deletions

View File

@@ -8,22 +8,42 @@ import {
Put,
} from '@nestjs/common';
import { TaxRatesApplication } from './TaxRate.application';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import {
ApiExtraModels,
ApiOperation,
ApiResponse,
ApiTags,
getSchemaPath,
} from '@nestjs/swagger';
import { CreateTaxRateDto, EditTaxRateDto } from './dtos/TaxRate.dto';
import { TaxRateResponseDto } from './dtos/TaxRateResponse.dto';
@Controller('tax-rates')
@ApiTags('Tax Rates')
@ApiExtraModels(TaxRateResponseDto)
export class TaxRatesController {
constructor(private readonly taxRatesApplication: TaxRatesApplication) {}
@Post()
@ApiOperation({ summary: 'Create a new tax rate.' })
@ApiResponse({
status: 201,
description: 'The tax rate has been successfully created.',
schema: { $ref: getSchemaPath(TaxRateResponseDto) },
})
public createTaxRate(@Body() createTaxRateDTO: CreateTaxRateDto) {
return this.taxRatesApplication.createTaxRate(createTaxRateDTO);
}
@Put(':id')
@ApiOperation({ summary: 'Edit the given tax rate.' })
@ApiResponse({
status: 200,
description: 'The tax rate has been successfully updated.',
schema: {
$ref: getSchemaPath(TaxRateResponseDto),
},
})
public editTaxRate(
@Param('id') taxRateId: number,
@Body() editTaxRateDTO: EditTaxRateDto,
@@ -33,30 +53,68 @@ export class TaxRatesController {
@Delete(':id')
@ApiOperation({ summary: 'Delete the given tax rate.' })
@ApiResponse({
status: 200,
description: 'The tax rate has been successfully deleted.',
schema: {
$ref: getSchemaPath(TaxRateResponseDto),
},
})
public deleteTaxRate(@Param('id') taxRateId: number) {
return this.taxRatesApplication.deleteTaxRate(taxRateId);
}
@Get(':id')
@ApiOperation({ summary: 'Retrieves the tax rate details.' })
@ApiResponse({
status: 200,
description: 'The tax rate details have been successfully retrieved.',
schema: {
$ref: getSchemaPath(TaxRateResponseDto),
},
})
public getTaxRate(@Param('id') taxRateId: number) {
return this.taxRatesApplication.getTaxRate(taxRateId);
}
@Get()
@ApiOperation({ summary: 'Retrieves the tax rates.' })
@ApiResponse({
status: 200,
description: 'The tax rates have been successfully retrieved.',
schema: {
type: 'array',
items: {
$ref: getSchemaPath(TaxRateResponseDto),
},
},
})
public getTaxRates() {
return this.taxRatesApplication.getTaxRates();
}
@Put(':id/activate')
@ApiOperation({ summary: 'Activate the given tax rate.' })
@ApiResponse({
status: 200,
description: 'The tax rate has been successfully activated.',
schema: {
$ref: getSchemaPath(TaxRateResponseDto),
},
})
public activateTaxRate(@Param('id') taxRateId: number) {
return this.taxRatesApplication.activateTaxRate(taxRateId);
}
@Put(':id/inactivate')
@ApiOperation({ summary: 'Inactivate the given tax rate.' })
@ApiResponse({
status: 200,
description: 'The tax rate has been successfully inactivated.',
schema: {
$ref: getSchemaPath(TaxRateResponseDto),
},
})
public inactivateTaxRate(@Param('id') taxRateId: number) {
return this.taxRatesApplication.inactivateTaxRate(taxRateId);
}