Created
April 1, 2021 10:18
-
-
Save MohammedALREAI/b88c984a9efefb9e7dc553633d24956b to your computer and use it in GitHub Desktop.
swiger setup and make in the controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { INestApplication } from '@nestjs/common'; | |
import { DocumentBuilder, OpenAPIObject, SwaggerModule } from '@nestjs/swagger'; | |
import { SWAGGER_CONFIG } from './swagger.config'; | |
export function createDocument(app: INestApplication): OpenAPIObject { | |
const builder = new DocumentBuilder() | |
.setTitle(SWAGGER_CONFIG.title) | |
.setDescription(SWAGGER_CONFIG.description) | |
.addBearerAuth({ type: 'http', scheme: 'bearer', bearerFormat: 'JWT' }, 'access-token') | |
.setVersion(SWAGGER_CONFIG.version); | |
for (const tag of SWAGGER_CONFIG.tags) { | |
builder.addTag(tag); | |
} | |
const options = builder.build(); | |
return SwaggerModule.createDocument(app, options); | |
} | |
//controller | |
@ApiTags("Auth") | |
@HttpCode(HttpStatus.ACCEPTED) | |
@ApiOperation({description:"get getUserMainData "}) | |
@ApiResponse({description:"Ok"}) | |
@ApiBadRequestResponse({description:"bad Request with verification "}) | |
@ApiInternalServerErrorResponse({description:"data has been send but there is issiue in server so try later "}) | |
@Get('user-main-data') | |
@UseGuards(AuthGuard('jwt'), AcceptedAuthGuard) | |
@Roles([Role.USER, Role.ADMIN]) | |
getUserData(@GetAuthenticatedUser() user: User) { | |
return this.authService.getUserMainData(user); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment