From f187a2d359ee6fa2957eae6f523609298e6befeb Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sat, 19 Oct 2019 14:10:01 +0300 Subject: [PATCH 1/2] Swagger conflict response annotation --- libs/rucken/core-nestjs/src/controllers/users.controller.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/rucken/core-nestjs/src/controllers/users.controller.ts b/libs/rucken/core-nestjs/src/controllers/users.controller.ts index fad98560..7247e6a2 100644 --- a/libs/rucken/core-nestjs/src/controllers/users.controller.ts +++ b/libs/rucken/core-nestjs/src/controllers/users.controller.ts @@ -34,7 +34,7 @@ export class UsersController { constructor( @Inject(CORE_CONFIG_TOKEN) private readonly coreConfig: ICoreConfig, private readonly service: UsersService - ) {} + ) { } @Roles('isSuperuser') @Permissions('add_user') @@ -45,6 +45,7 @@ export class UsersController { description: 'The record has been successfully created.' }) @ApiResponse({ status: HttpStatus.FORBIDDEN, description: 'Forbidden.' }) + @ApiResponse({ status: HttpStatus.CONFLICT, description: 'Email/username already exists.' }) @Post() async create(@Body() dto: InCreateUserDto) { if (dto.isSuperuser && this.coreConfig.demo) { @@ -71,6 +72,7 @@ export class UsersController { description: 'The record has been successfully updated.' }) @ApiResponse({ status: HttpStatus.FORBIDDEN, description: 'Forbidden.' }) + @ApiResponse({ status: HttpStatus.CONFLICT, description: 'Email/username already exists.' }) @ApiImplicitParam({ name: 'id', type: Number }) @Put(':id') async update(@Param('id', new ParseIntPipe()) id, @Body() dto: InUserDto) { From d6bc919c11adf520fc33b8e76509b5a4be1f3594 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sat, 19 Oct 2019 14:10:20 +0300 Subject: [PATCH 2/2] fix --- .../core-nestjs/src/services/users.service.ts | 6 +- package-lock.json | 82 +++++-------------- 2 files changed, 25 insertions(+), 63 deletions(-) diff --git a/libs/rucken/core-nestjs/src/services/users.service.ts b/libs/rucken/core-nestjs/src/services/users.service.ts index 8f99a779..27b982f8 100644 --- a/libs/rucken/core-nestjs/src/services/users.service.ts +++ b/libs/rucken/core-nestjs/src/services/users.service.ts @@ -5,7 +5,7 @@ import { User } from '../entities/user.entity'; @Injectable() export class UsersService { - constructor(@InjectRepository(User) private readonly repository: Repository) {} + constructor(@InjectRepository(User) private readonly repository: Repository) { } async assertUsernameAndEmail(options: { id?: number; email: string; username: string }) { if (options.email) { @@ -141,7 +141,7 @@ export class UsersService { user: item }; } catch (error) { - throw new NotFoundException(`User with email "${options.email}" not founded`); + throw new NotFoundException(`User with email "${options.email}" not found`); } } @@ -157,7 +157,7 @@ export class UsersService { user: item }; } catch (error) { - throw new NotFoundException(`User with username "${options.username}" not founded`); + throw new NotFoundException(`User with username "${options.username}" not found`); } } } diff --git a/package-lock.json b/package-lock.json index f90dcbea..ce2b73e4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4571,8 +4571,7 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -4593,14 +4592,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -4615,20 +4612,17 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -4745,8 +4739,7 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -4758,7 +4751,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -4773,7 +4765,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -4781,14 +4772,12 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -4807,7 +4796,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -4888,8 +4876,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -4901,7 +4888,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -4987,8 +4973,7 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -5024,7 +5009,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -5044,7 +5028,6 @@ "version": "3.0.1", "bundled": true, "dev": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -5088,14 +5071,12 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true } } }, @@ -15041,8 +15022,7 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true, - "optional": true + "bundled": true }, "aproba": { "version": "1.2.0", @@ -15060,13 +15040,11 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true, - "optional": true + "bundled": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -15079,18 +15057,15 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "concat-map": { "version": "0.0.1", - "bundled": true, - "optional": true + "bundled": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "core-util-is": { "version": "1.0.2", @@ -15193,8 +15168,7 @@ }, "inherits": { "version": "2.0.3", - "bundled": true, - "optional": true + "bundled": true }, "ini": { "version": "1.3.5", @@ -15204,7 +15178,6 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -15217,20 +15190,17 @@ "minimatch": { "version": "3.0.4", "bundled": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true, - "optional": true + "bundled": true }, "minipass": { "version": "2.3.5", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -15247,7 +15217,6 @@ "mkdirp": { "version": "0.5.1", "bundled": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -15320,8 +15289,7 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true, - "optional": true + "bundled": true }, "object-assign": { "version": "4.1.1", @@ -15331,7 +15299,6 @@ "once": { "version": "1.4.0", "bundled": true, - "optional": true, "requires": { "wrappy": "1" } @@ -15407,8 +15374,7 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true, - "optional": true + "bundled": true }, "safer-buffer": { "version": "2.1.2", @@ -15438,7 +15404,6 @@ "string-width": { "version": "1.0.2", "bundled": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -15456,7 +15421,6 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -15495,13 +15459,11 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true, - "optional": true + "bundled": true }, "yallist": { "version": "3.0.3", - "bundled": true, - "optional": true + "bundled": true } } },