From db970353541ae7802cf589aa84bcc941dc878de9 Mon Sep 17 00:00:00 2001 From: ack Date: Wed, 18 Oct 2023 12:33:03 +0700 Subject: [PATCH 1/2] update doc, and swagger options --- src/common/doc/decorators/doc.decorator.ts | 8 ++++++++ src/common/doc/interfaces/doc.interface.ts | 1 + src/modules/user/docs/user.auth.doc.ts | 2 +- src/swagger.ts | 10 +++++++--- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/common/doc/decorators/doc.decorator.ts b/src/common/doc/decorators/doc.decorator.ts index 67790fa3a..768849dbc 100644 --- a/src/common/doc/decorators/doc.decorator.ts +++ b/src/common/doc/decorators/doc.decorator.ts @@ -411,6 +411,14 @@ export function DocAuth(options?: IDocAuthOptions) { }); } + if (options?.google) { + docs.push(ApiBearerAuth('google')); + oneOfUnauthorized.push({ + messagePath: 'auth.error.googleSSO', + statusCode: ENUM_AUTH_STATUS_CODE_ERROR.AUTH_GOOGLE_SSO_ERROR, + }); + } + if (options?.apiKey) { docs.push(ApiSecurity('apiKey')); oneOfUnauthorized.push( diff --git a/src/common/doc/interfaces/doc.interface.ts b/src/common/doc/interfaces/doc.interface.ts index 52ae36887..78a0b15bf 100644 --- a/src/common/doc/interfaces/doc.interface.ts +++ b/src/common/doc/interfaces/doc.interface.ts @@ -24,6 +24,7 @@ export interface IDocAuthOptions { jwtAccessToken?: boolean; jwtRefreshToken?: boolean; apiKey?: boolean; + google?: boolean; } export interface IDocRequestOptions { diff --git a/src/modules/user/docs/user.auth.doc.ts b/src/modules/user/docs/user.auth.doc.ts index 5fb5fca0d..b0af8e90f 100644 --- a/src/modules/user/docs/user.auth.doc.ts +++ b/src/modules/user/docs/user.auth.doc.ts @@ -37,7 +37,7 @@ export function UserAuthLoginGoogleDoc(): MethodDecorator { Doc({ operation: 'modules.auth.user', }), - DocAuth({ apiKey: true, jwtRefreshToken: true }), + DocAuth({ google: true }), DocResponse('user.loginGoogle') ); } diff --git a/src/swagger.ts b/src/swagger.ts index 660b22962..7738b4f38 100644 --- a/src/swagger.ts +++ b/src/swagger.ts @@ -40,6 +40,10 @@ export default async function (app: NestApplication) { { type: 'http', scheme: 'bearer', bearerFormat: 'JWT' }, 'refreshToken' ) + .addBearerAuth( + { type: 'http', scheme: 'bearer', bearerFormat: 'JWT' }, + 'google' + ) .addApiKey( { type: 'apiKey', in: 'header', name: 'x-api-key' }, 'apiKey' @@ -62,14 +66,14 @@ export default async function (app: NestApplication) { SwaggerModule.setup(docPrefix, app, document, { jsonDocumentUrl: `${docPrefix}/json`, yamlDocumentUrl: `${docPrefix}/yaml`, - explorer: false, + explorer: true, customSiteTitle: docName, customCss: theme.getBuffer('dark'), swaggerOptions: { - docExpansion: 'none', + docExpansion: 'list', persistAuthorization: true, displayOperationId: true, - operationsSorter: 'alpha', + operationsSorter: 'method', tagsSorter: 'alpha', tryItOutEnabled: true, filter: true, From 9e242520a74bd3ffe82e1df2014817cb553731df Mon Sep 17 00:00:00 2001 From: ack Date: Wed, 18 Oct 2023 22:30:41 +0700 Subject: [PATCH 2/2] swagger update, swagger interface option update, add all api key protected to all api --- docs/database/databae_migration.md | 4 ++ nest-cli.json | 4 +- package.json | 1 - src/app/controllers/app.controller.ts | 29 +------- src/app/docs/app.doc.ts | 22 +------ src/common/api-key/docs/api-key.admin.doc.ts | 18 ++--- src/common/api-key/docs/api-key.user.doc.ts | 16 ++--- src/common/doc/decorators/doc.decorator.ts | 3 +- src/common/doc/interfaces/doc.interface.ts | 1 + src/common/message/docs/message.public.doc.ts | 2 +- src/common/setting/docs/setting.admin.doc.ts | 2 +- src/common/setting/docs/setting.public.doc.ts | 4 +- .../controllers/health.public.controller.ts | 6 ++ src/health/docs/health.doc.ts | 2 +- src/modules/role/constants/role.constant.ts | 3 + .../role/controllers/role.admin.controller.ts | 9 +++ src/modules/role/docs/role.admin.doc.ts | 21 ++++-- src/modules/role/dtos/role.request.dto.ts | 2 - .../guards/payload/role.payload.type.guard.ts | 5 +- src/modules/role/services/role.service.ts | 2 +- .../user/controllers/user.admin.controller.ts | 11 ++++ .../user/controllers/user.auth.controller.ts | 10 +++ .../controllers/user.public.controller.ts | 2 + .../user/controllers/user.user.controller.ts | 2 + src/modules/user/docs/user.admin.doc.ts | 66 +++++++++++-------- src/modules/user/docs/user.auth.doc.ts | 24 ++++--- src/modules/user/docs/user.public.doc.ts | 6 +- src/modules/user/docs/user.user.doc.ts | 3 +- src/swagger.ts | 12 +--- yarn.lock | 5 -- 30 files changed, 157 insertions(+), 140 deletions(-) diff --git a/docs/database/databae_migration.md b/docs/database/databae_migration.md index 008cae0ef..5540890be 100644 --- a/docs/database/databae_migration.md +++ b/docs/database/databae_migration.md @@ -17,6 +17,10 @@ For remove all data do yarn rollback ``` +# API Key Test +api key: `2ihKDneb9jQGgidAOqfO` +api key secret: `ZLCtDd2rh3TAyVhfAeo3JOPvWfAsTp0Oq6rHl69D` + # User Test 1. Super Admin diff --git a/nest-cli.json b/nest-cli.json index e7ad6495e..316a3bcaa 100644 --- a/nest-cli.json +++ b/nest-cli.json @@ -2,7 +2,9 @@ "collection": "@nestjs/schematics", "sourceRoot": "src", "compilerOptions": { - "plugins": ["@nestjs/swagger"], + "plugins": [ + "@nestjs/swagger" + ], "assets": [ { "include": "languages/**/*", diff --git a/package.json b/package.json index 0daeef0dc..586794d11 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,6 @@ "rimraf": "^5.0.5", "rotating-file-stream": "^3.1.1", "rxjs": "^7.8.1", - "swagger-themes": "^1.2.30", "ua-parser-js": "^1.0.36", "winston": "^3.11.0", "winston-daily-rotate-file": "^4.7.1", diff --git a/src/app/controllers/app.controller.ts b/src/app/controllers/app.controller.ts index 4c449fccc..eaaca1124 100644 --- a/src/app/controllers/app.controller.ts +++ b/src/app/controllers/app.controller.ts @@ -1,9 +1,8 @@ import { Controller, Get, VERSION_NEUTRAL } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { ApiTags } from '@nestjs/swagger'; -import { AppHelloApiKeyDoc, AppHelloDoc } from 'src/app/docs/app.doc'; +import { AppHelloDoc } from 'src/app/docs/app.doc'; import { AppHelloSerialization } from 'src/app/serializations/app.hello.serialization'; -import { ApiKeyPublicProtected } from 'src/common/api-key/decorators/api-key.decorator'; import { HelperDateService } from 'src/common/helper/services/helper.date.service'; import { RequestUserAgent } from 'src/common/request/decorators/request.decorator'; import { Response } from 'src/common/response/decorators/response.decorator'; @@ -47,30 +46,4 @@ export class AppController { }, }; } - - @AppHelloApiKeyDoc() - @Response('app.hello', { serialization: AppHelloSerialization }) - @ApiKeyPublicProtected() - @Get('/hello/api-key') - async helloApiKey( - @RequestUserAgent() userAgent: IResult - ): Promise { - const newDate = this.helperDateService.create(); - - return { - _metadata: { - customProperty: { - messageProperties: { - serviceName: this.serviceName, - }, - }, - }, - data: { - userAgent, - date: newDate, - format: this.helperDateService.format(newDate), - timestamp: this.helperDateService.timestamp(newDate), - }, - }; - } } diff --git a/src/app/docs/app.doc.ts b/src/app/docs/app.doc.ts index 5ff60d32f..885c29881 100644 --- a/src/app/docs/app.doc.ts +++ b/src/app/docs/app.doc.ts @@ -1,32 +1,14 @@ import { applyDecorators } from '@nestjs/common'; import { AppHelloSerialization } from 'src/app/serializations/app.hello.serialization'; -import { - Doc, - DocAuth, - DocGuard, - DocResponse, -} from 'src/common/doc/decorators/doc.decorator'; +import { Doc, DocResponse } from 'src/common/doc/decorators/doc.decorator'; export function AppHelloDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'hello', + operation: 'hello test api', }), DocResponse('app.hello', { serialization: AppHelloSerialization, }) ); } - -export function AppHelloApiKeyDoc(): MethodDecorator { - return applyDecorators( - Doc({ - operation: 'hello', - }), - DocAuth({ apiKey: true }), - DocGuard({ timestamp: true, userAgent: true }), - DocResponse('app.helloApiKey', { - serialization: AppHelloSerialization, - }) - ); -} diff --git a/src/common/api-key/docs/api-key.admin.doc.ts b/src/common/api-key/docs/api-key.admin.doc.ts index 1da1629e7..cbaa3bbf8 100644 --- a/src/common/api-key/docs/api-key.admin.doc.ts +++ b/src/common/api-key/docs/api-key.admin.doc.ts @@ -27,7 +27,7 @@ import { ResponseIdSerialization } from 'src/common/response/serializations/resp export function ApiKeyAdminListDoc(): MethodDecorator { return applyDecorators( - Doc({ operation: 'common.admin.apiKey' }), + Doc({ summary: 'get list of api keys' }), DocRequest({ queries: ApiKeyDocQueryIsActive, }), @@ -43,7 +43,7 @@ export function ApiKeyAdminListDoc(): MethodDecorator { export function ApiKeyAdminGetDoc(): MethodDecorator { return applyDecorators( - Doc({ operation: 'common.admin.apiKey' }), + Doc({ summary: 'get detail an api key' }), DocRequest({ params: ApiKeyDocParamsId, }), @@ -67,7 +67,7 @@ export function ApiKeyAdminGetDoc(): MethodDecorator { export function ApiKeyAdminCreateDoc(): MethodDecorator { return applyDecorators( - Doc({ operation: 'common.admin.apiKey' }), + Doc({ summary: 'create an api key' }), DocAuth({ jwtAccessToken: true, }), @@ -85,7 +85,7 @@ export function ApiKeyAdminCreateDoc(): MethodDecorator { export function ApiKeyAdminActiveDoc(): MethodDecorator { return applyDecorators( - Doc({ operation: 'common.admin.apiKey' }), + Doc({ summary: 'make api key be active' }), DocRequest({ params: ApiKeyDocParamsId, }), @@ -120,7 +120,7 @@ export function ApiKeyAdminActiveDoc(): MethodDecorator { export function ApiKeyAdminInactiveDoc(): MethodDecorator { return applyDecorators( - Doc({ operation: 'common.admin.apiKey' }), + Doc({ summary: 'make api key be inactive' }), DocRequest({ params: ApiKeyDocParamsId, }), @@ -155,7 +155,7 @@ export function ApiKeyAdminInactiveDoc(): MethodDecorator { export function ApiKeyAdminResetDoc(): MethodDecorator { return applyDecorators( - Doc({ operation: 'common.admin.apiKey' }), + Doc({ summary: 'reset secret an api key' }), DocRequest({ params: ApiKeyDocParamsId, }), @@ -192,7 +192,7 @@ export function ApiKeyAdminResetDoc(): MethodDecorator { export function ApiKeyAdminUpdateDoc(): MethodDecorator { return applyDecorators( - Doc({ operation: 'common.admin.apiKey' }), + Doc({ summary: 'update data an api key' }), DocRequest({ params: ApiKeyDocParamsId, bodyType: ENUM_DOC_REQUEST_BODY_TYPE.JSON, @@ -231,7 +231,7 @@ export function ApiKeyAdminUpdateDoc(): MethodDecorator { export function ApiKeyAdminUpdateDateDoc(): MethodDecorator { return applyDecorators( - Doc({ operation: 'common.admin.apiKey' }), + Doc({ summary: 'update date of api key' }), DocRequest({ params: ApiKeyDocParamsId, bodyType: ENUM_DOC_REQUEST_BODY_TYPE.JSON, @@ -270,7 +270,7 @@ export function ApiKeyAdminUpdateDateDoc(): MethodDecorator { export function ApiKeyAdminDeleteDoc(): MethodDecorator { return applyDecorators( - Doc({ operation: 'common.admin.apiKey' }), + Doc({ summary: 'delete an api key' }), DocRequest({ params: ApiKeyDocParamsId, }), diff --git a/src/common/api-key/docs/api-key.user.doc.ts b/src/common/api-key/docs/api-key.user.doc.ts index bf69d0974..18c0191c2 100644 --- a/src/common/api-key/docs/api-key.user.doc.ts +++ b/src/common/api-key/docs/api-key.user.doc.ts @@ -19,7 +19,7 @@ import { ResponseIdSerialization } from 'src/common/response/serializations/resp export function ApiKeyUserListDoc(): MethodDecorator { return applyDecorators( - Doc({ operation: 'common.user.apiKey' }), + Doc({ summary: 'get list of api keys' }), DocRequest({ queries: ApiKeyDocQueryIsActive, }), @@ -35,7 +35,7 @@ export function ApiKeyUserListDoc(): MethodDecorator { export function ApiKeyUserGetDoc(): MethodDecorator { return applyDecorators( - Doc({ operation: 'common.user.apiKey' }), + Doc({ summary: 'get detail an api key' }), DocRequest({ params: ApiKeyDocParamsId, }), @@ -51,7 +51,7 @@ export function ApiKeyUserGetDoc(): MethodDecorator { export function ApiKeyUserCreateDoc(): MethodDecorator { return applyDecorators( - Doc({ operation: 'common.user.apiKey' }), + Doc({ summary: 'create an api key' }), DocAuth({ jwtAccessToken: true, }), @@ -65,7 +65,7 @@ export function ApiKeyUserCreateDoc(): MethodDecorator { export function ApiKeyUserActiveDoc(): MethodDecorator { return applyDecorators( - Doc({ operation: 'common.user.apiKey' }), + Doc({ summary: 'make api key be active' }), DocRequest({ params: ApiKeyDocParamsId, }), @@ -79,7 +79,7 @@ export function ApiKeyUserActiveDoc(): MethodDecorator { export function ApiKeyUserInactiveDoc(): MethodDecorator { return applyDecorators( - Doc({ operation: 'common.user.apiKey' }), + Doc({ summary: 'make api key be inactive' }), DocRequest({ params: ApiKeyDocParamsId, }), @@ -93,7 +93,7 @@ export function ApiKeyUserInactiveDoc(): MethodDecorator { export function ApiKeyUserResetDoc(): MethodDecorator { return applyDecorators( - Doc({ operation: 'common.user.apiKey' }), + Doc({ summary: 'reset secret an api key' }), DocRequest({ params: ApiKeyDocParamsId, }), @@ -109,7 +109,7 @@ export function ApiKeyUserResetDoc(): MethodDecorator { export function ApiKeyUserUpdateDoc(): MethodDecorator { return applyDecorators( - Doc({ operation: 'common.user.apiKey' }), + Doc({ summary: 'update data an api key' }), DocRequest({ params: ApiKeyDocParamsId, }), @@ -125,7 +125,7 @@ export function ApiKeyUserUpdateDoc(): MethodDecorator { export function ApiKeyUserDeleteDoc(): MethodDecorator { return applyDecorators( - Doc({ operation: 'common.user.apiKey' }), + Doc({ summary: 'delete an api key' }), DocRequest({ params: ApiKeyDocParamsId, }), diff --git a/src/common/doc/decorators/doc.decorator.ts b/src/common/doc/decorators/doc.decorator.ts index 768849dbc..ab602f544 100644 --- a/src/common/doc/decorators/doc.decorator.ts +++ b/src/common/doc/decorators/doc.decorator.ts @@ -220,9 +220,10 @@ export function Doc(options?: IDocOptions): MethodDecorator { return applyDecorators( ApiOperation({ - summary: options?.operation, + summary: options?.summary, deprecated: options?.deprecated, description: options?.description, + operationId: options?.operation, }), ApiHeaders([ { diff --git a/src/common/doc/interfaces/doc.interface.ts b/src/common/doc/interfaces/doc.interface.ts index 78a0b15bf..cadc284ee 100644 --- a/src/common/doc/interfaces/doc.interface.ts +++ b/src/common/doc/interfaces/doc.interface.ts @@ -5,6 +5,7 @@ import { ENUM_DOC_REQUEST_BODY_TYPE } from 'src/common/doc/constants/doc.enum.co import { ENUM_FILE_EXCEL_MIME } from 'src/common/file/constants/file.enum.constant'; export interface IDocOptions { + summary?: string; operation?: string; deprecated?: boolean; description?: string; diff --git a/src/common/message/docs/message.public.doc.ts b/src/common/message/docs/message.public.doc.ts index bcf1e4949..0e9aebf91 100644 --- a/src/common/message/docs/message.public.doc.ts +++ b/src/common/message/docs/message.public.doc.ts @@ -4,7 +4,7 @@ import { MessageLanguageSerialization } from 'src/common/message/serializations/ export function MessagePublicLanguageDoc(): MethodDecorator { return applyDecorators( - Doc({ operation: 'common.public.message' }), + Doc({ summary: 'get all language of app' }), DocResponse('apiKey.languages', { serialization: MessageLanguageSerialization, }) diff --git a/src/common/setting/docs/setting.admin.doc.ts b/src/common/setting/docs/setting.admin.doc.ts index 80b1d9e05..def7ca0ec 100644 --- a/src/common/setting/docs/setting.admin.doc.ts +++ b/src/common/setting/docs/setting.admin.doc.ts @@ -14,7 +14,7 @@ import { ENUM_SETTING_STATUS_CODE_ERROR } from 'src/common/setting/constants/set export function SettingAdminUpdateDoc(): MethodDecorator { return applyDecorators( - Doc({ operation: 'common.admin.setting' }), + Doc({ summary: 'update a setting' }), DocRequest({ params: SettingDocParamsId, }), diff --git a/src/common/setting/docs/setting.public.doc.ts b/src/common/setting/docs/setting.public.doc.ts index 108debda9..128206ffb 100644 --- a/src/common/setting/docs/setting.public.doc.ts +++ b/src/common/setting/docs/setting.public.doc.ts @@ -15,7 +15,7 @@ import { SettingListSerialization } from 'src/common/setting/serializations/sett export function SettingPublicListDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'common.public.setting', + summary: 'get list of settings', }), DocResponsePaging('setting.list', { serialization: SettingListSerialization, @@ -25,7 +25,7 @@ export function SettingPublicListDoc(): MethodDecorator { export function SettingPublicGetDoc(): MethodDecorator { return applyDecorators( - Doc({ operation: 'common.public.setting' }), + Doc({ summary: 'get detail a setting' }), DocRequest({ params: SettingDocParamsId, }), diff --git a/src/health/controllers/health.public.controller.ts b/src/health/controllers/health.public.controller.ts index c965dadd5..c235611a2 100644 --- a/src/health/controllers/health.public.controller.ts +++ b/src/health/controllers/health.public.controller.ts @@ -8,6 +8,7 @@ import { MongooseHealthIndicator, } from '@nestjs/terminus'; import { Connection } from 'mongoose'; +import { ApiKeyPublicProtected } from 'src/common/api-key/decorators/api-key.decorator'; import { DatabaseConnection } from 'src/common/database/decorators/database.decorator'; import { Response } from 'src/common/response/decorators/response.decorator'; import { IResponse } from 'src/common/response/interfaces/response.interface'; @@ -33,6 +34,7 @@ export class HealthPublicController { @HealthCheckDoc() @Response('health.check', { serialization: HealthSerialization }) @HealthCheck() + @ApiKeyPublicProtected() @Get('/aws') async checkAws(): Promise { const data = await this.health.check([ @@ -47,6 +49,7 @@ export class HealthPublicController { @HealthCheckDoc() @Response('health.check', { serialization: HealthSerialization }) @HealthCheck() + @ApiKeyPublicProtected() @Get('/database') async checkDatabase(): Promise { const data = await this.health.check([ @@ -64,6 +67,7 @@ export class HealthPublicController { @HealthCheckDoc() @Response('health.check', { serialization: HealthSerialization }) @HealthCheck() + @ApiKeyPublicProtected() @Get('/memory-heap') async checkMemoryHeap(): Promise { const data = await this.health.check([ @@ -82,6 +86,7 @@ export class HealthPublicController { @HealthCheckDoc() @Response('health.check', { serialization: HealthSerialization }) @HealthCheck() + @ApiKeyPublicProtected() @Get('/memory-rss') async checkMemoryRss(): Promise { const data = await this.health.check([ @@ -100,6 +105,7 @@ export class HealthPublicController { @HealthCheckDoc() @Response('health.check', { serialization: HealthSerialization }) @HealthCheck() + @ApiKeyPublicProtected() @Get('/storage') async checkStorage(): Promise { const data = await this.health.check([ diff --git a/src/health/docs/health.doc.ts b/src/health/docs/health.doc.ts index aa56c0a8c..cdfb62976 100644 --- a/src/health/docs/health.doc.ts +++ b/src/health/docs/health.doc.ts @@ -9,7 +9,7 @@ import { HealthSerialization } from 'src/health/serializations/health.serializat export function HealthCheckDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'health', + summary: 'health check api', }), DocAuth({ jwtAccessToken: true, diff --git a/src/modules/role/constants/role.constant.ts b/src/modules/role/constants/role.constant.ts index f1567f2bd..715b0e303 100644 --- a/src/modules/role/constants/role.constant.ts +++ b/src/modules/role/constants/role.constant.ts @@ -1,2 +1,5 @@ export const ROLE_IS_ACTIVE_META_KEY = 'RoleIsActiveMetaKey'; export const ROLE_TYPE_META_KEY = 'RoleTypeMetaKey'; + +export const ROLE_LAWYER_NAME = 'lawyer'; +export const ROLE_CLIENT_NAME = 'client'; diff --git a/src/modules/role/controllers/role.admin.controller.ts b/src/modules/role/controllers/role.admin.controller.ts index 2ba859cb3..75ce8f5b6 100644 --- a/src/modules/role/controllers/role.admin.controller.ts +++ b/src/modules/role/controllers/role.admin.controller.ts @@ -9,6 +9,7 @@ import { Put, } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; +import { ApiKeyPublicProtected } from 'src/common/api-key/decorators/api-key.decorator'; import { AuthJwtAdminAccessProtected } from 'src/common/auth/decorators/auth.jwt.decorator'; import { PaginationQuery, @@ -95,6 +96,7 @@ export class RoleAdminController { action: [ENUM_POLICY_ACTION.READ], }) @AuthJwtAdminAccessProtected() + @ApiKeyPublicProtected() @Get('/list') async list( @PaginationQuery( @@ -146,6 +148,7 @@ export class RoleAdminController { action: [ENUM_POLICY_ACTION.READ], }) @AuthJwtAdminAccessProtected() + @ApiKeyPublicProtected() @RequestParamGuard(RoleRequestDto) @Get('get/:role') async get(@GetRole(true) role: RoleEntity): Promise { @@ -161,6 +164,7 @@ export class RoleAdminController { action: [ENUM_POLICY_ACTION.READ, ENUM_POLICY_ACTION.CREATE], }) @AuthJwtAdminAccessProtected() + @ApiKeyPublicProtected() @Post('/create') async create( @Body() @@ -196,6 +200,7 @@ export class RoleAdminController { action: [ENUM_POLICY_ACTION.READ, ENUM_POLICY_ACTION.UPDATE], }) @AuthJwtAdminAccessProtected() + @ApiKeyPublicProtected() @RequestParamGuard(RoleRequestDto) @Put('/update/:role') async update( @@ -220,6 +225,7 @@ export class RoleAdminController { action: [ENUM_POLICY_ACTION.READ, ENUM_POLICY_ACTION.UPDATE], }) @AuthJwtAdminAccessProtected() + @ApiKeyPublicProtected() @RequestParamGuard(RoleRequestDto) @Put('/update/:role/permission') async updatePermission( @@ -245,6 +251,7 @@ export class RoleAdminController { action: [ENUM_POLICY_ACTION.READ, ENUM_POLICY_ACTION.DELETE], }) @AuthJwtAdminAccessProtected() + @ApiKeyPublicProtected() @RequestParamGuard(RoleRequestDto) @Delete('/delete/:role') async delete(@GetRole() role: RoleDoc): Promise { @@ -267,6 +274,7 @@ export class RoleAdminController { @Response('role.inactive') @RoleAdminUpdateInactiveGuard() @AuthJwtAdminAccessProtected() + @ApiKeyPublicProtected() @RequestParamGuard(RoleRequestDto) @Patch('/update/:role/inactive') async inactive(@GetRole() role: RoleDoc): Promise { @@ -279,6 +287,7 @@ export class RoleAdminController { @Response('role.active') @RoleAdminUpdateActiveGuard() @AuthJwtAdminAccessProtected() + @ApiKeyPublicProtected() @RequestParamGuard(RoleRequestDto) @Patch('/update/:role/active') async active(@GetRole() role: RoleDoc): Promise { diff --git a/src/modules/role/docs/role.admin.doc.ts b/src/modules/role/docs/role.admin.doc.ts index 5daa1a221..5be12a264 100644 --- a/src/modules/role/docs/role.admin.doc.ts +++ b/src/modules/role/docs/role.admin.doc.ts @@ -22,12 +22,13 @@ import { RoleListSerialization } from 'src/modules/role/serializations/role.list export function RoleAdminListDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.admin.role', + summary: 'get all of roles', }), DocRequest({ queries: [...RoleDocQueryIsActive, ...RoleDocQueryType], }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), DocGuard({ role: true, policy: true }), @@ -40,12 +41,13 @@ export function RoleAdminListDoc(): MethodDecorator { export function RoleAdminGetDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.admin.role', + summary: 'get detail a role', }), DocRequest({ params: RoleDocParamsId, }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), DocGuard({ role: true, policy: true }), @@ -58,9 +60,10 @@ export function RoleAdminGetDoc(): MethodDecorator { export function RoleAdminCreateDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.admin.role', + summary: 'create a role', }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), DocRequest({ @@ -78,12 +81,13 @@ export function RoleAdminCreateDoc(): MethodDecorator { export function RoleAdminActiveDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.admin.role', + summary: 'make role be active', }), DocRequest({ params: RoleDocParamsId, }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), DocGuard({ role: true, policy: true }), @@ -94,12 +98,13 @@ export function RoleAdminActiveDoc(): MethodDecorator { export function RoleAdminInactiveDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.admin.role', + summary: 'make role be inactive', }), DocRequest({ params: RoleDocParamsId, }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), DocGuard({ role: true, policy: true }), @@ -110,7 +115,7 @@ export function RoleAdminInactiveDoc(): MethodDecorator { export function RoleAdminUpdateDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.admin.role', + summary: 'update data a role', }), DocRequest({ params: RoleDocParamsId, @@ -118,6 +123,7 @@ export function RoleAdminUpdateDoc(): MethodDecorator { body: RoleUpdateDto, }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), DocGuard({ role: true, policy: true }), @@ -130,12 +136,13 @@ export function RoleAdminUpdateDoc(): MethodDecorator { export function RoleAdminDeleteDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.admin.role', + summary: 'delete a role', }), DocRequest({ params: RoleDocParamsId, }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), DocGuard({ role: true, policy: true }), diff --git a/src/modules/role/dtos/role.request.dto.ts b/src/modules/role/dtos/role.request.dto.ts index e318dc718..4e9d899d5 100644 --- a/src/modules/role/dtos/role.request.dto.ts +++ b/src/modules/role/dtos/role.request.dto.ts @@ -1,9 +1,7 @@ -import { Type } from 'class-transformer'; import { IsNotEmpty, IsUUID } from 'class-validator'; export class RoleRequestDto { @IsNotEmpty() @IsUUID('4') - @Type(() => String) role: string; } diff --git a/src/modules/role/guards/payload/role.payload.type.guard.ts b/src/modules/role/guards/payload/role.payload.type.guard.ts index af41cc6e3..b9aec6383 100644 --- a/src/modules/role/guards/payload/role.payload.type.guard.ts +++ b/src/modules/role/guards/payload/role.payload.type.guard.ts @@ -6,6 +6,7 @@ import { } from '@nestjs/common'; import { Reflector } from '@nestjs/core'; import { HelperArrayService } from 'src/common/helper/services/helper.array.service'; +import { IRequestApp } from 'src/common/request/interfaces/request.interface'; import { ROLE_TYPE_META_KEY } from 'src/modules/role/constants/role.constant'; import { ENUM_ROLE_TYPE } from 'src/modules/role/constants/role.enum.constant'; import { ENUM_ROLE_STATUS_CODE_ERROR } from 'src/modules/role/constants/role.status-code.constant'; @@ -22,8 +23,8 @@ export class RolePayloadTypeGuard implements CanActivate { ENUM_ROLE_TYPE[] >(ROLE_TYPE_META_KEY, [context.getHandler(), context.getClass()]); - const { user } = context.switchToHttp().getRequest(); - const { type } = user; + const { user } = context.switchToHttp().getRequest(); + const { type } = user.user; if (!requiredFor || type === ENUM_ROLE_TYPE.SUPER_ADMIN) { return true; diff --git a/src/modules/role/services/role.service.ts b/src/modules/role/services/role.service.ts index a5b52a014..14a66436b 100644 --- a/src/modules/role/services/role.service.ts +++ b/src/modules/role/services/role.service.ts @@ -127,7 +127,7 @@ export class RoleService implements IRoleService { repository: RoleDoc, options?: IDatabaseSaveOptions ): Promise { - return this.roleRepository.softDelete(repository, options); + return this.roleRepository.delete(repository, options); } async deleteMany( diff --git a/src/modules/user/controllers/user.admin.controller.ts b/src/modules/user/controllers/user.admin.controller.ts index b0416cfef..470ec21a2 100644 --- a/src/modules/user/controllers/user.admin.controller.ts +++ b/src/modules/user/controllers/user.admin.controller.ts @@ -95,6 +95,7 @@ import { } from 'src/modules/user/docs/user.admin.doc'; import { ENUM_USER_SIGN_UP_FROM } from 'src/modules/user/constants/user.enum.constant'; import { FileUploadSingle } from 'src/common/file/decorators/file.decorator'; +import { ApiKeyPublicProtected } from 'src/common/api-key/decorators/api-key.decorator'; @ApiTags('modules.admin.user') @Controller({ @@ -118,6 +119,7 @@ export class UserAdminController { action: [ENUM_POLICY_ACTION.READ], }) @AuthJwtAdminAccessProtected() + @ApiKeyPublicProtected() @Get('/list') async list( @PaginationQuery( @@ -177,6 +179,7 @@ export class UserAdminController { action: [ENUM_POLICY_ACTION.READ], }) @AuthJwtAdminAccessProtected() + @ApiKeyPublicProtected() @RequestParamGuard(UserRequestDto) @Get('/get/:user') async get(@GetUser() user: UserDoc): Promise { @@ -194,6 +197,7 @@ export class UserAdminController { action: [ENUM_POLICY_ACTION.READ, ENUM_POLICY_ACTION.CREATE], }) @AuthJwtAdminAccessProtected() + @ApiKeyPublicProtected() @Post('/create') async create( @Body() @@ -259,6 +263,7 @@ export class UserAdminController { action: [ENUM_POLICY_ACTION.READ, ENUM_POLICY_ACTION.UPDATE], }) @AuthJwtAdminAccessProtected() + @ApiKeyPublicProtected() @RequestParamGuard(UserRequestDto) @Put('/update/:user') async update( @@ -281,6 +286,7 @@ export class UserAdminController { action: [ENUM_POLICY_ACTION.READ, ENUM_POLICY_ACTION.UPDATE], }) @AuthJwtAdminAccessProtected() + @ApiKeyPublicProtected() @RequestParamGuard(UserRequestDto) @Patch('/update/:user/inactive') async inactive(@GetUser() user: UserDoc): Promise { @@ -297,6 +303,7 @@ export class UserAdminController { action: [ENUM_POLICY_ACTION.READ, ENUM_POLICY_ACTION.UPDATE], }) @AuthJwtAdminAccessProtected() + @ApiKeyPublicProtected() @RequestParamGuard(UserRequestDto) @Patch('/update/:user/active') async active(@GetUser() user: UserDoc): Promise { @@ -313,6 +320,7 @@ export class UserAdminController { action: [ENUM_POLICY_ACTION.READ, ENUM_POLICY_ACTION.UPDATE], }) @AuthJwtAdminAccessProtected() + @ApiKeyPublicProtected() @RequestParamGuard(UserRequestDto) @Patch('/update/:user/blocked') async blocked(@GetUser() user: UserDoc): Promise { @@ -329,6 +337,7 @@ export class UserAdminController { action: [ENUM_POLICY_ACTION.READ, ENUM_POLICY_ACTION.DELETE], }) @AuthJwtAdminAccessProtected() + @ApiKeyPublicProtected() @RequestParamGuard(UserRequestDto) @Delete('/delete/:user') async delete(@GetUser() user: UserDoc): Promise { @@ -349,6 +358,7 @@ export class UserAdminController { ], }) @AuthJwtAdminAccessProtected() + @ApiKeyPublicProtected() @Post('/import') async import( @UploadedFile( @@ -382,6 +392,7 @@ export class UserAdminController { action: [ENUM_POLICY_ACTION.READ, ENUM_POLICY_ACTION.EXPORT], }) @AuthJwtAdminAccessProtected() + @ApiKeyPublicProtected() @HttpCode(HttpStatus.OK) @Post('/export') async export(): Promise { diff --git a/src/modules/user/controllers/user.auth.controller.ts b/src/modules/user/controllers/user.auth.controller.ts index b20a3ca69..a10c06c8f 100644 --- a/src/modules/user/controllers/user.auth.controller.ts +++ b/src/modules/user/controllers/user.auth.controller.ts @@ -72,6 +72,7 @@ import { ClientSession, Connection } from 'mongoose'; import { DatabaseConnection } from 'src/common/database/decorators/database.decorator'; import { ENUM_ERROR_STATUS_CODE_ERROR } from 'src/common/error/constants/error.status-code.constant'; import { FileUploadSingle } from 'src/common/file/decorators/file.decorator'; +import { ApiKeyPublicProtected } from 'src/common/api-key/decorators/api-key.decorator'; @ApiTags('modules.auth.user') @Controller({ @@ -91,6 +92,7 @@ export class UserAuthController { @Response('user.login', { serialization: UserLoginSerialization, }) + @ApiKeyPublicProtected() @HttpCode(HttpStatus.OK) @Post('/login') async login(@Body() { email, password }: UserLoginDto): Promise { @@ -220,6 +222,7 @@ export class UserAuthController { @UserAuthLoginGoogleDoc() @Response('user.loginGoogle') @AuthGoogleOAuth2Protected() + @ApiKeyPublicProtected() @Get('/login/google') async loginGoogle( @AuthJwtPayload() @@ -317,6 +320,7 @@ export class UserAuthController { @UserAuthProtected() @UserProtected() @AuthJwtRefreshProtected() + @ApiKeyPublicProtected() @HttpCode(HttpStatus.OK) @Post('/refresh') async refresh( @@ -386,6 +390,7 @@ export class UserAuthController { @Response('user.changePassword') @UserProtected() @AuthJwtAccessProtected() + @ApiKeyPublicProtected() @Patch('/change-password') async changePassword( @Body() body: UserChangePasswordDto, @@ -460,6 +465,7 @@ export class UserAuthController { @UserAuthInfoDoc() @Response('user.info', { serialization: AuthAccessPayloadSerialization }) @AuthJwtAccessProtected() + @ApiKeyPublicProtected() @Get('/info') async info( @AuthJwtPayload() @@ -474,6 +480,7 @@ export class UserAuthController { }) @UserProtected() @AuthJwtAccessProtected() + @ApiKeyPublicProtected() @Get('/profile') async profile(@GetUser() user: UserDoc): Promise { const userWithRole: IUserDoc = @@ -485,6 +492,7 @@ export class UserAuthController { @Response('user.updateProfile') @UserProtected() @AuthJwtAccessProtected() + @ApiKeyPublicProtected() @Patch('/profile/update') async updateProfile( @GetUser() user: UserDoc, @@ -499,6 +507,7 @@ export class UserAuthController { @Response('user.claimUsername') @UserProtected() @AuthJwtAccessProtected() + @ApiKeyPublicProtected() @Patch('/profile/claim-username') async claimUsername( @GetUser() user: UserDoc, @@ -524,6 +533,7 @@ export class UserAuthController { @UserProtected() @AuthJwtAccessProtected() @FileUploadSingle() + @ApiKeyPublicProtected() @HttpCode(HttpStatus.OK) @Post('/profile/upload') async upload( diff --git a/src/modules/user/controllers/user.public.controller.ts b/src/modules/user/controllers/user.public.controller.ts index 2442dc370..5286d5f06 100644 --- a/src/modules/user/controllers/user.public.controller.ts +++ b/src/modules/user/controllers/user.public.controller.ts @@ -1,5 +1,6 @@ import { Body, ConflictException, Controller, Post } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; +import { ApiKeyPublicProtected } from 'src/common/api-key/decorators/api-key.decorator'; import { AuthService } from 'src/common/auth/services/auth.service'; import { Response } from 'src/common/response/decorators/response.decorator'; import { RoleService } from 'src/modules/role/services/role.service'; @@ -23,6 +24,7 @@ export class UserPublicController { @UserPublicSignUpDoc() @Response('user.signUp') + @ApiKeyPublicProtected() @Post('/sign-up') async signUp( @Body() diff --git a/src/modules/user/controllers/user.user.controller.ts b/src/modules/user/controllers/user.user.controller.ts index 2b2d6a2dd..3eed892c3 100644 --- a/src/modules/user/controllers/user.user.controller.ts +++ b/src/modules/user/controllers/user.user.controller.ts @@ -1,5 +1,6 @@ import { Controller, Delete } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; +import { ApiKeyPublicProtected } from 'src/common/api-key/decorators/api-key.decorator'; import { AuthJwtUserAccessProtected } from 'src/common/auth/decorators/auth.jwt.decorator'; import { Response } from 'src/common/response/decorators/response.decorator'; import { @@ -22,6 +23,7 @@ export class UserUserController { @Response('user.deleteSelf') @UserProtected() @AuthJwtUserAccessProtected() + @ApiKeyPublicProtected() @Delete('/delete') async deleteSelf(@GetUser() user: UserDoc): Promise { await this.userService.inactivePermanent(user); diff --git a/src/modules/user/docs/user.admin.doc.ts b/src/modules/user/docs/user.admin.doc.ts index e502a5806..52b62f988 100644 --- a/src/modules/user/docs/user.admin.doc.ts +++ b/src/modules/user/docs/user.admin.doc.ts @@ -27,7 +27,7 @@ import { UserListSerialization } from 'src/modules/user/serializations/user.list export function UserAdminListDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.admin.user', + summary: 'get all of users', }), DocRequest({ queries: [ @@ -38,6 +38,7 @@ export function UserAdminListDoc(): MethodDecorator { ], }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), DocGuard({ role: true, policy: true }), @@ -50,12 +51,13 @@ export function UserAdminListDoc(): MethodDecorator { export function UserAdminGetDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.admin.user', + summary: 'get detail an user', }), DocRequest({ params: UserDocParamsId, }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), DocGuard({ role: true, policy: true }), @@ -65,78 +67,82 @@ export function UserAdminGetDoc(): MethodDecorator { ); } -export function UserAdminCreateDoc(): MethodDecorator { +export function UserAdminActiveDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.admin.user', + summary: 'make user be active', + }), + DocRequest({ + params: UserDocParamsId, }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), - DocRequest({ - bodyType: ENUM_DOC_REQUEST_BODY_TYPE.JSON, - body: UserCreateDto, - }), DocGuard({ role: true, policy: true }), - DocResponse('user.create', { - httpStatus: HttpStatus.CREATED, - serialization: ResponseIdSerialization, - }) + DocResponse('user.active') ); } -export function UserAdminActiveDoc(): MethodDecorator { +export function UserAdminInactiveDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.admin.user', + summary: 'make user be inactive', }), DocRequest({ params: UserDocParamsId, }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), DocGuard({ role: true, policy: true }), - DocResponse('user.active') + DocResponse('user.inactive') ); } -export function UserAdminInactiveDoc(): MethodDecorator { +export function UserAdminBlockedDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.admin.user', + summary: 'block a user', }), DocRequest({ params: UserDocParamsId, }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), DocGuard({ role: true, policy: true }), - DocResponse('user.inactive') + DocResponse('user.blocked') ); } -export function UserAdminBlockedDoc(): MethodDecorator { +export function UserAdminCreateDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.admin.user', - }), - DocRequest({ - params: UserDocParamsId, + summary: 'create a user', }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), + DocRequest({ + bodyType: ENUM_DOC_REQUEST_BODY_TYPE.JSON, + body: UserCreateDto, + }), DocGuard({ role: true, policy: true }), - DocResponse('user.blocked') + DocResponse('user.create', { + httpStatus: HttpStatus.CREATED, + serialization: ResponseIdSerialization, + }) ); } export function UserAdminUpdateDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.admin.user', + summary: 'update data a user', }), DocRequest({ params: UserDocParamsId, @@ -144,6 +150,7 @@ export function UserAdminUpdateDoc(): MethodDecorator { body: UserUpdateNameDto, }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), DocGuard({ role: true, policy: true }), @@ -156,12 +163,13 @@ export function UserAdminUpdateDoc(): MethodDecorator { export function UserAdminDeleteDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.admin.user', + summary: 'delete a user', }), DocRequest({ params: UserDocParamsId, }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), DocGuard({ role: true, policy: true }), @@ -172,9 +180,10 @@ export function UserAdminDeleteDoc(): MethodDecorator { export function UserAdminImportDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.admin.user', + summary: 'import users with excel', }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), DocRequestFile({ @@ -190,9 +199,10 @@ export function UserAdminImportDoc(): MethodDecorator { export function UserAdminExportDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.admin.user', + summary: 'export user into excel', }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), DocGuard({ role: true, policy: true }), diff --git a/src/modules/user/docs/user.auth.doc.ts b/src/modules/user/docs/user.auth.doc.ts index b0af8e90f..4275d0597 100644 --- a/src/modules/user/docs/user.auth.doc.ts +++ b/src/modules/user/docs/user.auth.doc.ts @@ -20,7 +20,7 @@ import { UserRefreshSerialization } from 'src/modules/user/serializations/user.r export function UserAuthLoginDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.public.user', + operation: 'login with email and password', }), DocRequest({ bodyType: ENUM_DOC_REQUEST_BODY_TYPE.JSON, @@ -35,7 +35,7 @@ export function UserAuthLoginDoc(): MethodDecorator { export function UserAuthLoginGoogleDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.auth.user', + summary: 'login with access token google', }), DocAuth({ google: true }), DocResponse('user.loginGoogle') @@ -45,7 +45,7 @@ export function UserAuthLoginGoogleDoc(): MethodDecorator { export function UserAuthRefreshDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.auth.user', + summary: 'refresh a token', }), DocAuth({ jwtRefreshToken: true, @@ -59,9 +59,10 @@ export function UserAuthRefreshDoc(): MethodDecorator { export function UserAuthProfileDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.auth.user', + summary: 'get profile', }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), DocResponse('user.profile', { @@ -73,9 +74,10 @@ export function UserAuthProfileDoc(): MethodDecorator { export function UserAuthUploadProfileDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.auth.user', + summary: 'update profile photo', }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), DocRequestFile({ @@ -88,9 +90,10 @@ export function UserAuthUploadProfileDoc(): MethodDecorator { export function UserAuthUpdateProfileDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.auth.user', + summary: 'update profile', }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), DocRequest({ @@ -104,9 +107,10 @@ export function UserAuthUpdateProfileDoc(): MethodDecorator { export function UserAuthInfoDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.auth.user', + operation: 'get info of access token', }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), DocResponse('user.info', { @@ -118,9 +122,10 @@ export function UserAuthInfoDoc(): MethodDecorator { export function UserAuthChangePasswordDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.auth.user', + summary: 'change password', }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), DocRequest({ @@ -134,9 +139,10 @@ export function UserAuthChangePasswordDoc(): MethodDecorator { export function UserAuthClaimUsernameDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.auth.user', + operation: 'claim username', }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), DocRequest({ diff --git a/src/modules/user/docs/user.public.doc.ts b/src/modules/user/docs/user.public.doc.ts index 5af18f0f6..1748be2dd 100644 --- a/src/modules/user/docs/user.public.doc.ts +++ b/src/modules/user/docs/user.public.doc.ts @@ -2,6 +2,7 @@ import { applyDecorators, HttpStatus } from '@nestjs/common'; import { ENUM_DOC_REQUEST_BODY_TYPE } from 'src/common/doc/constants/doc.enum.constant'; import { Doc, + DocAuth, DocRequest, DocResponse, } from 'src/common/doc/decorators/doc.decorator'; @@ -10,12 +11,15 @@ import { UserSignUpDto } from 'src/modules/user/dtos/user.sign-up.dto'; export function UserPublicSignUpDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.public.user', + operation: 'sign up a user', }), DocRequest({ bodyType: ENUM_DOC_REQUEST_BODY_TYPE.JSON, body: UserSignUpDto, }), + DocAuth({ + apiKey: true, + }), DocResponse('user.signUp', { httpStatus: HttpStatus.CREATED, }) diff --git a/src/modules/user/docs/user.user.doc.ts b/src/modules/user/docs/user.user.doc.ts index 2f964a609..11269feda 100644 --- a/src/modules/user/docs/user.user.doc.ts +++ b/src/modules/user/docs/user.user.doc.ts @@ -9,9 +9,10 @@ import { export function UserUserDeleteSelfDoc(): MethodDecorator { return applyDecorators( Doc({ - operation: 'modules.user.user', + operation: 'user delete their account', }), DocAuth({ + apiKey: true, jwtAccessToken: true, }), DocGuard({ role: true }), diff --git a/src/swagger.ts b/src/swagger.ts index 7738b4f38..a6250c0c2 100644 --- a/src/swagger.ts +++ b/src/swagger.ts @@ -10,7 +10,6 @@ import { import { AwsS3Serialization } from 'src/common/aws/serializations/aws.s3.serialization'; import { ResponseDefaultSerialization } from 'src/common/response/serializations/response.default.serialization'; import { ResponsePagingSerialization } from 'src/common/response/serializations/response.paging.serialization'; -import { SwaggerTheme } from 'swagger-themes'; import { writeFileSync } from 'fs'; export default async function (app: NestApplication) { @@ -28,10 +27,7 @@ export default async function (app: NestApplication) { .setTitle(docName) .setDescription(docDesc) .setVersion(docVersion) - .addTag("API's") .addServer('/') - .addServer('/staging') - .addServer('/prod') .addBearerAuth( { type: 'http', scheme: 'bearer', bearerFormat: 'JWT' }, 'accessToken' @@ -62,15 +58,13 @@ export default async function (app: NestApplication) { }); writeFileSync('./data/swagger.json', JSON.stringify(document)); - const theme = new SwaggerTheme('v3'); SwaggerModule.setup(docPrefix, app, document, { jsonDocumentUrl: `${docPrefix}/json`, yamlDocumentUrl: `${docPrefix}/yaml`, explorer: true, customSiteTitle: docName, - customCss: theme.getBuffer('dark'), swaggerOptions: { - docExpansion: 'list', + docExpansion: 'none', persistAuthorization: true, displayOperationId: true, operationsSorter: 'method', @@ -78,10 +72,6 @@ export default async function (app: NestApplication) { tryItOutEnabled: true, filter: true, deepLinking: true, - syntaxHighlight: { - activate: true, - theme: 'tomorrow-night', - }, }, }); diff --git a/yarn.lock b/yarn.lock index b1de701f0..c4143564e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8139,11 +8139,6 @@ supports-preserve-symlinks-flag@^1.0.0: resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09" integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w== -swagger-themes@^1.2.30: - version "1.2.30" - resolved "https://registry.yarnpkg.com/swagger-themes/-/swagger-themes-1.2.30.tgz#4c9cffc8e38ee40309998fc954c562f976daae94" - integrity sha512-OOk1gMfu50knSui4ncnOGtQEw8snOkMCLiOWVLqO0IT1SNYJC83MBWtRwMWSYmaC+m51XdNBlZ030T4t6viNvg== - swagger-ui-dist@5.9.0: version "5.9.0" resolved "https://registry.yarnpkg.com/swagger-ui-dist/-/swagger-ui-dist-5.9.0.tgz#d52b6cf52fd0a8e6930866c402aaa793fe4e3f76"