Utilisation du plugin swagger pour de la meilleure documentation, et meilleure prise en charge d'erreurs

This commit is contained in:
2024-12-08 18:18:11 +01:00
parent 83d3a573ca
commit 77b33144f6
15 changed files with 249 additions and 107 deletions

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -1,6 +1,6 @@
import { ApiProperty } from '@nestjs/swagger'
export class AuthEntity {
@ApiProperty()
/**
* Jeton d'accès à l'API, valable 12h.
*/
accessToken: string
}