Skip to content

Commit

Permalink
OV-3: * changing name to fullName
Browse files Browse the repository at this point in the history
  • Loading branch information
JPjok3r committed Aug 21, 2024
1 parent eca26b8 commit 6fe3503
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 27 deletions.
28 changes: 14 additions & 14 deletions backend/src/bundles/users/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class UserEntity implements Entity {

private 'email': string;

private 'name': string;
private 'fullName': string;

private 'passwordHash': string;

Expand All @@ -14,60 +14,60 @@ class UserEntity implements Entity {
private constructor({
id,
email,
name,
fullName,
passwordHash,
passwordSalt,
}: {
id: number | null;
email: string;
name: string;
fullName: string;
passwordHash: string;
passwordSalt: string;
}) {
this.id = id;
this.email = email;
this.name = name;
this.fullName = fullName;
this.passwordHash = passwordHash;
this.passwordSalt = passwordSalt;
}

public static initialize({
id,
email,
name,
fullName,
passwordHash,
passwordSalt,
}: {
id: number;
email: string;
name: string;
fullName: string;
passwordHash: string;
passwordSalt: string;
}): UserEntity {
return new UserEntity({
id,
email,
name,
fullName,
passwordHash,
passwordSalt,
});
}

public static initializeNew({
email,
name,
fullName,
passwordHash,
passwordSalt,
}: {
email: string;
name: string;
fullName: string;
passwordHash: string;
passwordSalt: string;
}): UserEntity {
return new UserEntity({
id: null,
email,
name,
fullName,
passwordHash,
passwordSalt,
});
Expand All @@ -76,24 +76,24 @@ class UserEntity implements Entity {
public toObject(): {
id: number;
email: string;
name: string;
fullName: string;
} {
return {
id: this.id as number,
email: this.email,
name: this.name,
fullName: this.fullName,
};
}

public toNewObject(): {
email: string;
name: string;
fullName: string;
passwordHash: string;
passwordSalt: string;
} {
return {
email: this.email,
name: this.name,
fullName: this.fullName,
passwordHash: this.passwordHash,
passwordSalt: this.passwordSalt,
};
Expand Down
2 changes: 1 addition & 1 deletion backend/src/bundles/users/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
class UserModel extends AbstractModel {
public 'email': string;

public 'name': string;
public 'fullName': string;

public 'passwordHash': string;

Expand Down
4 changes: 2 additions & 2 deletions backend/src/bundles/users/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class UserRepository implements Repository {
}

public async create(entity: UserEntity): Promise<UserEntity> {
const { email, name, passwordSalt, passwordHash } =
const { email, fullName, passwordSalt, passwordHash } =
entity.toNewObject();

const item = await this.userModel
.query()
.insert({
email,
name,
fullName,
passwordSalt,
passwordHash,
})
Expand Down
2 changes: 1 addition & 1 deletion backend/src/bundles/users/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class UserService implements Service {
const user = await this.userRepository.create(
UserEntity.initializeNew({
email: payload.email,
name: payload.name,
fullName: payload.fullName,
passwordSalt: salt,
passwordHash: hash,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const TABLE_NAME = 'users';

async function up(knex: Knex): Promise<void> {
await knex.schema.table(TABLE_NAME, (table) => {
table.string('name').notNullable();
table.string('full_name').notNullable();
});
}

async function down(knex: Knex): Promise<void> {
await knex.schema.table(TABLE_NAME, (table) => {
table.dropColumn('name');
table.dropColumn('full_name');
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type UserSignUpRequestDto } from '~/bundles/users/users.js';

const DEFAULT_SIGN_UP_PAYLOAD: UserSignUpRequestDto = {
name: '',
fullName: '',
email: '',
password: '',
confirmPassword: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const UserValidationRule = {
EMAIL_MAXIMUM_LENGTH: 320,
PASSWORD_MINIMUM_LENGTH: 6,
PASSWORD_MAXIMUM_LENGTH: 12,
NAME_MINIMUM_WORD_LENGTH: 2,
FULL_NAME_MINIMUM_WORD_LENGTH: 2,
} as const;

export { UserValidationRule };
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type UserSignUpRequestDto = {
name: string;
fullName: string;
email: string;
password: string;
confirmPassword: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type UserSignUpResponseDto = {
id: number;
name: string;
fullName: string;
email: string;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { z } from 'zod';
import { UserValidationMessage, UserValidationRule } from '../enums/enums.js';

type UserSignUpRequestValidationDto = {
name: z.ZodEffects<z.ZodString, string, string>;
fullName: z.ZodEffects<z.ZodString, string, string>;
email: z.ZodString;
password: z.ZodString;
confirmPassword: z.ZodString;
};

const userSignUp = z
.object<UserSignUpRequestValidationDto>({
name: z.string({ required_error: UserValidationMessage.FIELD_REQUIRE })
fullName: z.string({ required_error: UserValidationMessage.FIELD_REQUIRE })
.trim()
.refine((value) => value.split(/\s+/).length >= 2, {
.refine((value) => value.split(/\s+/).length >= UserValidationRule.FULL_NAME_MINIMUM_WORD_LENGTH, {
message: UserValidationMessage.NAME_MIN_TWO_WORDS,
}),
email: z
Expand Down

0 comments on commit 6fe3503

Please sign in to comment.