diff --git a/src/routes/auth/auth.controller.ts b/src/routes/auth/auth.controller.ts index 2db6dc8..d5d5909 100644 --- a/src/routes/auth/auth.controller.ts +++ b/src/routes/auth/auth.controller.ts @@ -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') diff --git a/src/routes/auth/auth.service.ts b/src/routes/auth/auth.service.ts index 73b14e2..f74aa37 100644 --- a/src/routes/auth/auth.service.ts +++ b/src/routes/auth/auth.service.ts @@ -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() diff --git a/src/routes/auth/dto/login.dto.ts b/src/routes/auth/dto/login.dto.ts new file mode 100644 index 0000000..f292798 --- /dev/null +++ b/src/routes/auth/dto/login.dto.ts @@ -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; +} \ No newline at end of file diff --git a/src/routes/auth/dto/profile_response.dto.ts b/src/routes/auth/dto/profile_response.dto.ts new file mode 100644 index 0000000..4ae9d65 --- /dev/null +++ b/src/routes/auth/dto/profile_response.dto.ts @@ -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; +} diff --git a/src/routes/auth/dto/refresh_token.dto.ts b/src/routes/auth/dto/refresh_token.dto.ts new file mode 100644 index 0000000..c328692 --- /dev/null +++ b/src/routes/auth/dto/refresh_token.dto.ts @@ -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; +} \ No newline at end of file diff --git a/src/routes/auth/dto/register.dto.ts b/src/routes/auth/dto/register.dto.ts new file mode 100644 index 0000000..0d38d91 --- /dev/null +++ b/src/routes/auth/dto/register.dto.ts @@ -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; +}