Utilisation du plugin swagger pour de la meilleure documentation, et meilleure prise en charge d'erreurs
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import { Body, Controller, Post } from '@nestjs/common'
|
||||
import { AuthService } from './auth.service'
|
||||
import { ApiOkResponse, ApiTags } from '@nestjs/swagger'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { AuthEntity } from './entity/auth.entity'
|
||||
import { LoginDto } from './dto/login.dto'
|
||||
|
||||
@ -9,9 +9,13 @@ import { LoginDto } from './dto/login.dto'
|
||||
export class AuthController {
|
||||
constructor(private readonly authService: AuthService) {}
|
||||
|
||||
/**
|
||||
* Se connecter par nom et mot de passe pour récupérer un jeton de connexion.
|
||||
*
|
||||
* @throws {401} Mot de passe incorrect.
|
||||
*/
|
||||
@Post('login')
|
||||
@ApiOkResponse({ type: AuthEntity })
|
||||
login(@Body() { name, password }: LoginDto) {
|
||||
return this.authService.login(name, password)
|
||||
async login(@Body() { name, password }: LoginDto): Promise<AuthEntity> {
|
||||
return await this.authService.login(name, password)
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,9 @@
|
||||
import { ApiProperty } from '@nestjs/swagger'
|
||||
import { IsNotEmpty, IsString } from 'class-validator'
|
||||
import { IsNotEmpty } from 'class-validator'
|
||||
|
||||
export class LoginDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@ApiProperty()
|
||||
name: string
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@ApiProperty()
|
||||
password: string
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import { ApiProperty } from '@nestjs/swagger'
|
||||
|
||||
export class AuthEntity {
|
||||
@ApiProperty()
|
||||
/**
|
||||
* Jeton d'accès à l'API, valable 12h.
|
||||
*/
|
||||
accessToken: string
|
||||
}
|
||||
|
Reference in New Issue
Block a user