diff --git a/src/domain/models/superuser.ts b/src/domain/models/superuser.ts index e8bbb21..bfd7f87 100644 --- a/src/domain/models/superuser.ts +++ b/src/domain/models/superuser.ts @@ -6,6 +6,8 @@ export class SuperUser { public id: SuperUserId public firstName: string public lastName: string + public email: string + public isActive: boolean public avatarUrl: string public roles: Array @@ -14,6 +16,8 @@ export class SuperUser { id: SuperUserId, firstName: string, lastName: string, + email: string, + isActive: boolean, avatarUrl: string, roles: Array, }, @@ -21,6 +25,8 @@ export class SuperUser { this.id = superUserProps.id this.firstName = superUserProps.firstName this.lastName = superUserProps.lastName + this.email = superUserProps.email + this.isActive = superUserProps.isActive this.avatarUrl = superUserProps.avatarUrl this.roles = superUserProps.roles } diff --git a/src/domain/services/createSuperUser.ts b/src/domain/services/createSuperUser.ts index 5ab65a8..67a5694 100644 --- a/src/domain/services/createSuperUser.ts +++ b/src/domain/services/createSuperUser.ts @@ -1,6 +1,7 @@ import { SuperUserRole } from "src/domain/constants"; import { SuperUserId } from "src/domain/valueObjects"; import { + EmailValidator, SuperUserFirstNameValidator, SuperUserLastNameValidator, } from "src/domain/validators"; @@ -10,15 +11,18 @@ import { SuperUser } from "src/domain/models"; export class CreateSuperUser { protected readonly firstNameValidator: SuperUserFirstNameValidator protected readonly lastNameValidator: SuperUserLastNameValidator + protected readonly emailValidator: EmailValidator constructor( createSuperUserProps: { firstNameValidator: SuperUserFirstNameValidator, lastNameValidator: SuperUserLastNameValidator, + emailValidator: EmailValidator, }, ) { this.firstNameValidator = createSuperUserProps.firstNameValidator this.lastNameValidator = createSuperUserProps.lastNameValidator + this.emailValidator = createSuperUserProps.emailValidator } execute( @@ -26,17 +30,21 @@ export class CreateSuperUser { id: SuperUserId, firstName: string, lastName: string, + email: string, avatarUrl: string, roles: Array, } ): SuperUser { this.firstNameValidator.validate(createUserParams.firstName) this.lastNameValidator.validate(createUserParams.lastName) + this.emailValidator.validate(createUserParams.email) return new SuperUser({ id: createUserParams.id, firstName: createUserParams.firstName, lastName: createUserParams.lastName, + email: createUserParams.email, + isActive: true, avatarUrl: createUserParams.avatarUrl, roles: createUserParams.roles, }) diff --git a/src/domain/services/createUser.ts b/src/domain/services/createUser.ts index 4ad5dd1..393ec3e 100644 --- a/src/domain/services/createUser.ts +++ b/src/domain/services/createUser.ts @@ -1,7 +1,7 @@ import { UserId } from "src/domain/valueObjects"; import { - UserNameValidator, EmailValidator, + UserNameValidator, TelegramValidator, } from "src/domain/validators"; import { User } from "src/domain/models"; diff --git a/src/domain/validators/common.ts b/src/domain/validators/common.ts new file mode 100644 index 0000000..f8bbd7f --- /dev/null +++ b/src/domain/validators/common.ts @@ -0,0 +1,14 @@ +import { InvalidEmailError } from "src/domain/errors" + + +const EMAIL_VALIDATION_PATTERN = + /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b/ + + +export class EmailValidator { + validate(value: string): void { + if (!EMAIL_VALIDATION_PATTERN.test(value)) { + throw new InvalidEmailError() + } + } +} diff --git a/src/domain/validators/index.ts b/src/domain/validators/index.ts index 0e8b433..fdd4134 100644 --- a/src/domain/validators/index.ts +++ b/src/domain/validators/index.ts @@ -1,2 +1,3 @@ +export * from "./common"; export * from "./user"; -export * from "./superUser" +export * from "./superUser"; diff --git a/src/domain/validators/user.ts b/src/domain/validators/user.ts index dc53c96..e9b0e46 100644 --- a/src/domain/validators/user.ts +++ b/src/domain/validators/user.ts @@ -1,6 +1,5 @@ import { InvalidUserNameError, - InvalidEmailError, InvalidTelegramError } from "src/domain/errors" @@ -8,9 +7,6 @@ import { const USER_NAME_MIN_LENGTH = 5 const USER_NAME_MAX_LENGTH = 64 -const EMAIL_VALIDATION_PATTERN = - /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b/ - const TELEGRAM_MIN_LENGTH = 5 const TELEGRAM_MAX_LENGTH = 32 const TELEGRAM_VALIDATION_PATTERN = /^[a-zA-Z0-9_]+$/ @@ -30,15 +26,6 @@ export class UserNameValidator { } -export class EmailValidator { - validate(value: string): void { - if (!EMAIL_VALIDATION_PATTERN.test(value)) { - throw new InvalidEmailError() - } - } -} - - export class TelegramValidator { validate(value: string): void { if (