mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
feat: add swagger docs for responses
This commit is contained in:
@@ -16,13 +16,17 @@ import {
|
||||
ApiParam,
|
||||
ApiOkResponse,
|
||||
ApiNotFoundResponse,
|
||||
ApiExtraModels,
|
||||
getSchemaPath,
|
||||
} from '@nestjs/swagger';
|
||||
import { CurrenciesApplication } from './CurrenciesApplication.service';
|
||||
import { CreateCurrencyDto } from './dtos/CreateCurrency.dto';
|
||||
import { EditCurrencyDto } from './dtos/EditCurrency.dto';
|
||||
import { CurrencyResponseDto } from './dtos/CurrencyResponse.dto';
|
||||
|
||||
@ApiTags('Currencies')
|
||||
@Controller('/currencies')
|
||||
@ApiExtraModels(CurrencyResponseDto)
|
||||
export class CurrenciesController {
|
||||
constructor(private readonly currenciesApp: CurrenciesApplication) {}
|
||||
|
||||
@@ -31,6 +35,9 @@ export class CurrenciesController {
|
||||
@ApiBody({ type: CreateCurrencyDto })
|
||||
@ApiCreatedResponse({
|
||||
description: 'The currency has been successfully created.',
|
||||
schema: {
|
||||
$ref: getSchemaPath(CurrencyResponseDto),
|
||||
},
|
||||
})
|
||||
@ApiBadRequestResponse({ description: 'Invalid input data.' })
|
||||
create(@Body() dto: CreateCurrencyDto) {
|
||||
@@ -41,7 +48,12 @@ export class CurrenciesController {
|
||||
@ApiOperation({ summary: 'Edit an existing currency' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Currency ID' })
|
||||
@ApiBody({ type: EditCurrencyDto })
|
||||
@ApiOkResponse({ description: 'The currency has been successfully updated.' })
|
||||
@ApiOkResponse({
|
||||
description: 'The currency has been successfully updated.',
|
||||
schema: {
|
||||
$ref: getSchemaPath(CurrencyResponseDto),
|
||||
},
|
||||
})
|
||||
@ApiNotFoundResponse({ description: 'Currency not found.' })
|
||||
@ApiBadRequestResponse({ description: 'Invalid input data.' })
|
||||
edit(@Param('id') id: number, @Body() dto: EditCurrencyDto) {
|
||||
@@ -59,7 +71,15 @@ export class CurrenciesController {
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'Get all currencies' })
|
||||
@ApiOkResponse({ description: 'List of all currencies.' })
|
||||
@ApiOkResponse({
|
||||
description: 'List of all currencies.',
|
||||
schema: {
|
||||
type: 'array',
|
||||
items: {
|
||||
$ref: getSchemaPath(CurrencyResponseDto),
|
||||
},
|
||||
},
|
||||
})
|
||||
findAll() {
|
||||
return this.currenciesApp.getCurrencies();
|
||||
}
|
||||
@@ -71,7 +91,12 @@ export class CurrenciesController {
|
||||
type: String,
|
||||
description: 'Currency code',
|
||||
})
|
||||
@ApiOkResponse({ description: 'The currency details.' })
|
||||
@ApiOkResponse({
|
||||
description: 'The currency details.',
|
||||
schema: {
|
||||
$ref: getSchemaPath(CurrencyResponseDto),
|
||||
},
|
||||
})
|
||||
@ApiNotFoundResponse({ description: 'Currency not found.' })
|
||||
findOne(@Param('currencyCode') currencyCode: string) {
|
||||
return this.currenciesApp.getCurrency(currencyCode);
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class CurrencyResponseDto {
|
||||
@ApiProperty({
|
||||
description: 'The unique identifier of the currency',
|
||||
example: 1,
|
||||
})
|
||||
id: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'The name of the currency',
|
||||
example: 'US Dollar',
|
||||
})
|
||||
currencyName: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'The code of the currency',
|
||||
example: 'USD',
|
||||
})
|
||||
currencyCode: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'The sign/symbol of the currency',
|
||||
example: '$',
|
||||
})
|
||||
currencySign: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Whether this is the base currency for the organization',
|
||||
example: true,
|
||||
})
|
||||
isBaseCurrency: boolean;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'The creation timestamp',
|
||||
example: '2024-03-20T10:00:00Z',
|
||||
})
|
||||
createdAt: Date;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'The last update timestamp',
|
||||
example: '2024-03-20T10:00:00Z',
|
||||
})
|
||||
updatedAt: Date;
|
||||
}
|
||||
Reference in New Issue
Block a user