mirror of
https://github.com/ershisan99/flashcards-api.git
synced 2025-12-25 05:09:25 +00:00
add scalar api reference
This commit is contained in:
@@ -19,6 +19,7 @@ import { CommandBus } from '@nestjs/cqrs'
|
||||
import { FileFieldsInterceptor } from '@nestjs/platform-express'
|
||||
import {
|
||||
ApiBadRequestResponse,
|
||||
ApiBearerAuth,
|
||||
ApiBody,
|
||||
ApiConsumes,
|
||||
ApiNoContentResponse,
|
||||
@@ -63,6 +64,7 @@ export class AuthController {
|
||||
@ApiUnauthorizedResponse({ description: 'Not logged in' })
|
||||
@ApiBadRequestResponse({ description: 'User not found' })
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Get('me')
|
||||
async getUserData(@Request() req): Promise<UserEntity> {
|
||||
const userId = req.user.id
|
||||
@@ -77,6 +79,7 @@ export class AuthController {
|
||||
@UseInterceptors(FileFieldsInterceptor([{ name: 'avatar', maxCount: 1 }]))
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Patch('me')
|
||||
@ApiBearerAuth()
|
||||
async updateUserData(
|
||||
@Request() req,
|
||||
@UploadedFiles()
|
||||
@@ -115,7 +118,7 @@ export class AuthController {
|
||||
secure: true,
|
||||
})
|
||||
|
||||
return { accessToken: req.user.data.accessToken }
|
||||
return { accessToken: req.user.data.accessToken, refreshToken: req.user.data.refreshToken }
|
||||
}
|
||||
|
||||
@ApiOperation({ description: 'Create a new user account', summary: 'Create a new user account' })
|
||||
@@ -155,6 +158,7 @@ export class AuthController {
|
||||
@HttpCode(HttpStatus.NO_CONTENT)
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('logout')
|
||||
@ApiBearerAuth()
|
||||
async logout(
|
||||
@Cookies('accessToken') accessToken: string,
|
||||
@Res({ passthrough: true }) res: ExpressResponse
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { IsUUID } from 'class-validator'
|
||||
|
||||
import { ApiSchema } from '../../../infrastructure/common/helpers/api-schema'
|
||||
|
||||
@ApiSchema({ name: 'EmailVerificationRequest' })
|
||||
export class EmailVerificationDto {
|
||||
@IsUUID('4')
|
||||
code: string
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { IsBoolean, IsEmail, IsOptional, Length } from 'class-validator'
|
||||
|
||||
import { ApiSchema } from '../../../infrastructure/common/helpers/api-schema'
|
||||
|
||||
@ApiSchema({ name: 'LoginRequest' })
|
||||
export class LoginDto {
|
||||
@Length(3, 30)
|
||||
password: string
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { ApiProperty } from '@nestjs/swagger'
|
||||
import { IsEmail, IsOptional, IsString } from 'class-validator'
|
||||
|
||||
import { ApiSchema } from '../../../infrastructure/common/helpers/api-schema'
|
||||
|
||||
@ApiSchema({ name: 'RecoverPasswordRequest' })
|
||||
export class RecoverPasswordDto {
|
||||
/** User's email address */
|
||||
@IsEmail()
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
import { ApiProperty } from '@nestjs/swagger'
|
||||
import { IsBoolean, IsEmail, IsOptional, IsString, Length } from 'class-validator'
|
||||
|
||||
export class RegistrationDto {
|
||||
@Length(3, 30)
|
||||
@IsOptional()
|
||||
name?: string
|
||||
import { ApiSchema } from '../../../infrastructure/common/helpers/api-schema'
|
||||
|
||||
@ApiSchema({ name: 'RegistrationRequest' })
|
||||
export class RegistrationDto {
|
||||
@Length(3, 30)
|
||||
password: string
|
||||
|
||||
@IsEmail()
|
||||
email: string
|
||||
|
||||
@Length(3, 30)
|
||||
@IsOptional()
|
||||
name?: string
|
||||
|
||||
@ApiProperty({
|
||||
description: `HTML template to be sent in the email;\n ##name## will be replaced with the user's name; \n ##token## will be replaced with the password recovery token`,
|
||||
example: `<b>Hello, ##name##!</b><br/>Please confirm your email by clicking on the link below:<br/><a href="http://localhost:3000/confirm-email/##token##">Confirm email</a>. If it doesn't work, copy and paste the following link in your browser:<br/>http://localhost:3000/confirm-email/##token##`,
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { ApiProperty } from '@nestjs/swagger'
|
||||
import { IsOptional, IsString, IsUUID } from 'class-validator'
|
||||
|
||||
import { ApiSchema } from '../../../infrastructure/common/helpers/api-schema'
|
||||
|
||||
@ApiSchema({ name: 'ResendVerificationEmailRequest' })
|
||||
export class ResendVerificationEmailDto {
|
||||
@IsUUID()
|
||||
userId: string
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { Length } from 'class-validator'
|
||||
|
||||
import { ApiSchema } from '../../../infrastructure/common/helpers/api-schema'
|
||||
|
||||
@ApiSchema({ name: 'ResetPasswordRequest' })
|
||||
export class ResetPasswordDto {
|
||||
@Length(3, 30)
|
||||
password: string
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { IsNumber, IsString, Max, Min } from 'class-validator'
|
||||
|
||||
import { ApiSchema } from '../../../infrastructure/common/helpers/api-schema'
|
||||
|
||||
@ApiSchema({ name: 'SaveGradeRequest' })
|
||||
export class SaveGradeDto {
|
||||
@IsString()
|
||||
cardId: string
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { PartialType, PickType } from '@nestjs/swagger'
|
||||
import { IsOptional } from 'class-validator'
|
||||
|
||||
import { ApiSchema } from '../../../infrastructure/common/helpers/api-schema'
|
||||
import { User } from '../entities/auth.entity'
|
||||
|
||||
@ApiSchema({ name: 'UpdateUserRequest' })
|
||||
export class UpdateUserDataDto extends PartialType(PickType(User, ['name', 'avatar'] as const)) {
|
||||
@IsOptional()
|
||||
avatar?: string
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { ApiProperty, OmitType } from '@nestjs/swagger'
|
||||
|
||||
import { ApiSchema } from '../../../infrastructure/common/helpers/api-schema'
|
||||
|
||||
export class User {
|
||||
id: string
|
||||
email: string
|
||||
@@ -14,6 +16,8 @@ export class User {
|
||||
|
||||
export class LoginResponse {
|
||||
accessToken: string
|
||||
refreshToken: string
|
||||
}
|
||||
|
||||
@ApiSchema({ name: 'User' })
|
||||
export class UserEntity extends OmitType(User, ['password']) {}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Inject, Injectable } from '@nestjs/common'
|
||||
import { PassportStrategy } from '@nestjs/passport'
|
||||
import { Request } from 'express'
|
||||
import { Strategy } from 'passport-jwt'
|
||||
import { ExtractJwt, Strategy } from 'passport-jwt'
|
||||
|
||||
import { AppSettings } from '../../../settings/app-settings'
|
||||
import { UsersService } from '../../users/services/users.service'
|
||||
@@ -24,7 +24,10 @@ export class JwtRefreshStrategy extends PassportStrategy(Strategy, 'jwt-refresh'
|
||||
private userService: UsersService
|
||||
) {
|
||||
super({
|
||||
jwtFromRequest: cookieExtractor,
|
||||
jwtFromRequest: ExtractJwt.fromExtractors([
|
||||
cookieExtractor,
|
||||
ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||
]),
|
||||
ignoreExpiration: true,
|
||||
secretOrKey: appSettings.auth.REFRESH_JWT_SECRET_KEY,
|
||||
})
|
||||
|
||||
@@ -5,13 +5,11 @@ import { ExtractJwt, Strategy } from 'passport-jwt'
|
||||
|
||||
import { AppSettings } from '../../../settings/app-settings'
|
||||
import { UsersService } from '../../users/services/users.service'
|
||||
import { AuthService } from '../auth.service'
|
||||
|
||||
@Injectable()
|
||||
export class JwtStrategy extends PassportStrategy(Strategy) {
|
||||
constructor(
|
||||
@Inject(AppSettings.name) private readonly appSettings: AppSettings,
|
||||
private authService: AuthService,
|
||||
private userService: UsersService
|
||||
) {
|
||||
super({
|
||||
|
||||
Reference in New Issue
Block a user