forked from Ynov/ptitspas-ynov-back
auth dto moved to auth route
This commit is contained in:
parent
d117e7b925
commit
489edf22e7
@ -1,14 +1,14 @@
|
||||
import { Body, Controller, Get, Post, Req, UnauthorizedException, UseGuards } from '@nestjs/common';
|
||||
import { LoginDto } from '../user/dto/login.dto';
|
||||
import { LoginDto } from './dto/login.dto';
|
||||
import { AuthService } from './auth.service';
|
||||
import { Public } from 'src/common/decorators/public.decorator';
|
||||
import { RegisterDto } from '../user/dto/register.dto';
|
||||
import { RegisterDto } from './dto/register.dto';
|
||||
import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||
import { AuthGuard } from 'src/common/guards/auth.guard';
|
||||
import type { Request } from 'express';
|
||||
import { UserService } from '../user/user.service';
|
||||
import { ProfileResponseDto } from '../user/dto/profile_response.dto';
|
||||
import { RefreshTokenDto } from '../user/dto/refresh_token.dto';
|
||||
import { ProfileResponseDto } from './dto/profile_response.dto';
|
||||
import { RefreshTokenDto } from './dto/refresh_token.dto';
|
||||
|
||||
@ApiTags('Authentification')
|
||||
@Controller('auth')
|
||||
|
||||
@ -6,10 +6,10 @@ import {
|
||||
import { UserService } from '../user/user.service';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import * as bcrypt from 'bcrypt';
|
||||
import { RegisterDto } from '../user/dto/register.dto';
|
||||
import { RegisterDto } from './dto/register.dto';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { RoleType, StatutUtilisateurType, Users } from 'src/entities/users.entity';
|
||||
import { LoginDto } from '../user/dto/login.dto';
|
||||
import { LoginDto } from './dto/login.dto';
|
||||
import { DeepPartial } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
|
||||
17
src/routes/auth/dto/login.dto.ts
Normal file
17
src/routes/auth/dto/login.dto.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { IsEmail, IsString, MaxLength, MinLength } from "class-validator";
|
||||
|
||||
export class LoginDto {
|
||||
@ApiProperty({ example: 'mon.utilisateur@exemple.com', description: "Adresse email de l'utililisateur" })
|
||||
@IsEmail()
|
||||
email: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: "Mon_motdepasse_fort_1234?",
|
||||
description: "Mot de passe de l'utilisateur"
|
||||
})
|
||||
@IsString({ message: 'Le mot de passe doit etre une chaine de caracteres' })
|
||||
//@MinLength(8, { message: 'Le mot de passe doit contenir au moins 8 caracteres' })
|
||||
@MaxLength(50)
|
||||
password: string;
|
||||
}
|
||||
22
src/routes/auth/dto/profile_response.dto.ts
Normal file
22
src/routes/auth/dto/profile_response.dto.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { RoleType, StatutUtilisateurType } from 'src/entities/users.entity';
|
||||
|
||||
export class ProfileResponseDto {
|
||||
@ApiProperty()
|
||||
id: string;
|
||||
|
||||
@ApiProperty()
|
||||
email: string;
|
||||
|
||||
@ApiProperty({ enum: RoleType })
|
||||
role: RoleType;
|
||||
|
||||
@ApiProperty()
|
||||
prenom?: string;
|
||||
|
||||
@ApiProperty()
|
||||
nom?: string;
|
||||
|
||||
@ApiProperty({ enum: StatutUtilisateurType })
|
||||
statut: StatutUtilisateurType;
|
||||
}
|
||||
12
src/routes/auth/dto/refresh_token.dto.ts
Normal file
12
src/routes/auth/dto/refresh_token.dto.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { IsString } from "class-validator";
|
||||
|
||||
export class RefreshTokenDto {
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Token de rafraîchissement',
|
||||
example: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
|
||||
})
|
||||
@IsString()
|
||||
refresh_token: string;
|
||||
}
|
||||
14
src/routes/auth/dto/register.dto.ts
Normal file
14
src/routes/auth/dto/register.dto.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { ApiProperty, OmitType } from '@nestjs/swagger';
|
||||
import { IsEnum, IsOptional } from 'class-validator';
|
||||
import { CreateUserDto } from '../../user/dto/create_user.dto';
|
||||
import { RoleType, StatutUtilisateurType } from 'src/entities/users.entity';
|
||||
|
||||
export class RegisterDto extends OmitType(CreateUserDto, ['changement_mdp_obligatoire'] as const) {
|
||||
@ApiProperty({ enum: [RoleType.ASSISTANTE_MATERNELLE, RoleType.PARENT], default: RoleType.PARENT })
|
||||
@IsEnum(RoleType)
|
||||
role: RoleType = RoleType.PARENT;
|
||||
|
||||
@IsEnum(StatutUtilisateurType)
|
||||
@IsOptional()
|
||||
statut?: StatutUtilisateurType = StatutUtilisateurType.EN_ATTENTE;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user