Ajout des fichiers de base pour le projet.

This commit is contained in:
2025-08-12 17:18:10 +00:00
parent 0695d2ca1e
commit 14e69e1f61
20 changed files with 2087 additions and 0 deletions

View File

@ -0,0 +1,45 @@
export class AccountEntity {
constructor(
public readonly id: string,
public readonly email: string,
private password: string,
public readonly roleId: number,
public readonly createdAt: Date,
public readonly updatedAt: Date,
) {
this.validateEmail(email);
this.validatePassword(password);
}
// Logique métier : validation de l'email
private validateEmail(email: string): void {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
throw new Error("Format d'email invalide");
}
}
private validatePassword(password: string): void {
if (password.length < 8) {
throw new Error("Mot de passe trop court");
}
}
// Logique métier : vérification du mot de passe
public verifyPassword(plainPassword: string): boolean {
// Dans un vrai projet, on utiliserait bcrypt
return this.password === plainPassword;
}
// Factory method pour créer un nouveau compte
static create(email: string, password: string): AccountEntity {
const now = new Date();
const id = crypto.randomUUID();
return new AccountEntity(id, email, password, 1, now, now);
}
}
export type CreateAccountDto = {
email: string;
password: string;
};