Skip to content

Commit

Permalink
fix(swagger): errors schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
Ealenn committed Jun 25, 2022
1 parent 29077cf commit 1145f4e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 22 deletions.
6 changes: 1 addition & 5 deletions core/src/controllers/account/account.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ export class AccountController {
@Public()
@Post('register')
@ApiResponse({ status: 201, type: ProfileResponseBody })
@ApiResponse({
status: 400,
description: 'Bad Request',
type: ErrorsRequestBody,
})
@ApiResponse({ status: 400, description: 'Bad Request', type: ErrorsRequestBody })
@ApiResponse({ status: 409, description: 'Conflict' })
async register(@Body() registerRequestBody: RegisterRequestBody) {
const createUser: User = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class FavoritesVarietiesController {

@Delete(':varietyId')
@ApiResponse({ status: 200 })
@ApiResponse({ status: 404, description: 'Not Found', type: ErrorsRequestBody })
@ApiResponse({ status: 404, description: 'Not Found' })
async deleteFavorite(@Response() res: Res, @Request() req, @Param('varietyId') varietyId: string) {
const favorite = await this.favoritesService.deleteVariety(varietyId, req.user);
if (!favorite) {
Expand Down Expand Up @@ -80,7 +80,7 @@ export class FavoritesVarietiesController {

@Get(':varietyId')
@ApiResponse({ status: 200, type: FavoriteVarietyResponseBody })
@ApiResponse({ status: 404, description: 'Not Found', type: ErrorsRequestBody })
@ApiResponse({ status: 404, description: 'Not Found' })
async getFavoriteVariety(@Response() res: Res, @Request() req, @Param('varietyId') varietyId: string) {
const favorite = await this.favoritesService.getVariety(varietyId, req.user);
if (!favorite) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/controllers/floors/floors.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class FloorsController {
@Delete(':floorId')
@Roles(Role.ADMIN)
@ApiResponse({ status: 403, description: 'Forbidden', type: ErrorsRequestBody })
@ApiResponse({ status: 404, description: 'Not Found', type: ErrorsRequestBody })
@ApiResponse({ status: 404, description: 'Not Found' })
@ApiResponse({ status: 200, type: FloorResponseBody })
async deletePlant(@Response() res: Res, @Request() req, @Param('floorId') plantId: string) {
const floor = await this.floorsService.deleteFloor(plantId);
Expand All @@ -68,7 +68,7 @@ export class FloorsController {

@Get(':floorId')
@ApiResponse({ status: 200, type: FloorResponseBody })
@ApiResponse({ status: 404, description: 'Not Found', type: ErrorsRequestBody })
@ApiResponse({ status: 404, description: 'Not Found' })
async getFloorById(@Response() res: Res, @Param('floorId') floorId: string) {
const floor = await this.floorsService.findOneById(floorId);
if (!floor) {
Expand Down
6 changes: 3 additions & 3 deletions core/src/controllers/models/errors.response.body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export class ErrorsRequestMessageBody {
@ApiProperty()
property: string;

@ApiProperty({ isArray: true, type: ErrorsRequestMessageBody })
children: ErrorsRequestMessageBody[];
@ApiProperty({ isArray: true })
children: Record<string, string>[];

@ApiProperty()
constraints: Record<string, string>;
Expand All @@ -22,7 +22,7 @@ export class ErrorsRequestBody {
statusCode: number;

@ApiProperty({ isArray: true, type: ErrorsRequestMessageBody })
messages: ErrorsRequestMessageBody[];
message: ErrorsRequestMessageBody[];

@ApiProperty()
error: string;
Expand Down
6 changes: 3 additions & 3 deletions core/src/controllers/plants/plants.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export class PlantsController {

@Delete(':plantId')
@Roles(Role.ADMIN)
@ApiResponse({ status: 403, description: 'Forbidden', type: ErrorsRequestBody })
@ApiResponse({ status: 404, description: 'Not Found', type: ErrorsRequestBody })
@ApiResponse({ status: 403, description: 'Forbidden' })
@ApiResponse({ status: 404, description: 'Not Found' })
@ApiResponse({ status: 200, type: PlantResponseBody })
async deletePlant(@Request() req, @Param('plantId') plantId: string) {
const plant = await this.plantsService.deletePlant(plantId);
Expand All @@ -67,7 +67,7 @@ export class PlantsController {

@Get(':plantId')
@ApiResponse({ status: 200, type: PlantResponseBody })
@ApiResponse({ status: 404, description: 'Not Found', type: ErrorsRequestBody })
@ApiResponse({ status: 404, description: 'Not Found' })
async getPlantById(@Response() res: Res, @Param('plantId') plantId: string) {
const plant = await this.plantsService.findOneById(plantId);
if (!plant) {
Expand Down
11 changes: 4 additions & 7 deletions core/src/controllers/varieties/varieties.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ export class VarietiesController {
@Roles(Role.ADMIN)
@ApiResponse({ status: 403, description: 'Forbidden' })
@ApiResponse({ status: 201, type: VarietyResponseBody })
@ApiResponse({
status: 400,
description: 'Bad Request',
type: ErrorsRequestBody,
})
@ApiResponse({ status: 400, description: 'Bad Request', type: ErrorsRequestBody })
async createVariety(@Request() req, @Body() createVarietyRequestBody: CreateVarietyRequestBody) {
const createVariety: Variety = {
...createVarietyRequestBody,
Expand All @@ -65,8 +61,8 @@ export class VarietiesController {

@Delete(':varietyId')
@Roles(Role.ADMIN)
@ApiResponse({ status: 403, description: 'Forbidden', type: ErrorsRequestBody })
@ApiResponse({ status: 404, description: 'Not Found', type: ErrorsRequestBody })
@ApiResponse({ status: 403, description: 'Forbidden' })
@ApiResponse({ status: 404, description: 'Not Found' })
@ApiResponse({ status: 200, type: VarietyResponseBody })
async deletePlant(@Request() req, @Param('varietyId') varietyId: string) {
const variety = await this.varietiesService.delete(varietyId);
Expand All @@ -79,6 +75,7 @@ export class VarietiesController {

@Get(':varietyId')
@ApiResponse({ status: 200, type: VarietyResponseBody })
@ApiResponse({ status: 404, description: 'Not Found' })
async getVarietyById(@Response() res: Res, @Param('varietyId') varietyId: string) {
const plant = await this.varietiesService.findOneById(varietyId);
if (!plant) {
Expand Down

0 comments on commit 1145f4e

Please sign in to comment.