From 7effaa7c4010196d364fe57e81382cf8c2131fb9 Mon Sep 17 00:00:00 2001 From: Gsk54 Date: Wed, 21 Dec 2022 16:15:57 +0100 Subject: [PATCH] add phone --- .../20221219143521_phone/migration.sql | 5 +++++ .../20221219145046_phone/migration.sql | 8 ++++++++ prisma/schema.prisma | 7 ++++--- .../users/adapters/primaries/user.presenter.ts | 3 +++ src/modules/users/adapters/primaries/user.proto | 1 + .../users/domain/dtos/create-user.request.ts | 17 +++++++++-------- .../users/domain/dtos/update-user.request.ts | 4 ++++ src/modules/users/domain/entities/user.ts | 9 ++++++--- .../tests/unit/create-user.usecase.spec.ts | 4 ++-- .../tests/unit/delete-user.usecase.spec.ts | 5 ++++- .../tests/unit/find-all-users.usecase.spec.ts | 3 +++ .../unit/find-user-by-uuid.usecase.spec.ts | 1 + 12 files changed, 50 insertions(+), 17 deletions(-) create mode 100644 prisma/migrations/20221219143521_phone/migration.sql create mode 100644 prisma/migrations/20221219145046_phone/migration.sql diff --git a/prisma/migrations/20221219143521_phone/migration.sql b/prisma/migrations/20221219143521_phone/migration.sql new file mode 100644 index 0000000..0582557 --- /dev/null +++ b/prisma/migrations/20221219143521_phone/migration.sql @@ -0,0 +1,5 @@ +-- AlterTable +ALTER TABLE "user" ADD COLUMN "phone" TEXT, +ALTER COLUMN "firstName" DROP NOT NULL, +ALTER COLUMN "lastName" DROP NOT NULL, +ALTER COLUMN "email" DROP NOT NULL; diff --git a/prisma/migrations/20221219145046_phone/migration.sql b/prisma/migrations/20221219145046_phone/migration.sql new file mode 100644 index 0000000..da9fc77 --- /dev/null +++ b/prisma/migrations/20221219145046_phone/migration.sql @@ -0,0 +1,8 @@ +/* + Warnings: + + - A unique constraint covering the columns `[phone]` on the table `user` will be added. If there are existing duplicate values, this will fail. + +*/ +-- CreateIndex +CREATE UNIQUE INDEX "user_phone_key" ON "user"("phone"); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 5c56f48..e756077 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -12,9 +12,10 @@ datasource db { model User { uuid String @id @default(uuid()) @db.Uuid - firstName String - lastName String - email String @unique + firstName String? + lastName String? + email String? @unique + phone String? @unique createdAt DateTime @default(now()) updatedAt DateTime @updatedAt diff --git a/src/modules/users/adapters/primaries/user.presenter.ts b/src/modules/users/adapters/primaries/user.presenter.ts index 25f63a8..6ff9a25 100644 --- a/src/modules/users/adapters/primaries/user.presenter.ts +++ b/src/modules/users/adapters/primaries/user.presenter.ts @@ -12,4 +12,7 @@ export class UserPresenter { @AutoMap() email: string; + + @AutoMap() + phone: string; } diff --git a/src/modules/users/adapters/primaries/user.proto b/src/modules/users/adapters/primaries/user.proto index cf8979c..a579285 100644 --- a/src/modules/users/adapters/primaries/user.proto +++ b/src/modules/users/adapters/primaries/user.proto @@ -19,6 +19,7 @@ message User { string firstName = 2; string lastName = 3; string email = 4; + string phone = 5; } message UserFilter { diff --git a/src/modules/users/domain/dtos/create-user.request.ts b/src/modules/users/domain/dtos/create-user.request.ts index f836448..f060bee 100644 --- a/src/modules/users/domain/dtos/create-user.request.ts +++ b/src/modules/users/domain/dtos/create-user.request.ts @@ -1,23 +1,24 @@ import { AutoMap } from '@automapper/classes'; -import { IsNotEmpty, IsString } from 'class-validator'; +import { IsString } from 'class-validator'; export class CreateUserRequest { @IsString() @AutoMap() - uuid: string; + uuid?: string; @IsString() - @IsNotEmpty() @AutoMap() - firstName: string; + firstName?: string; @IsString() - @IsNotEmpty() @AutoMap() - lastName: string; + lastName?: string; @IsString() - @IsNotEmpty() @AutoMap() - email: string; + email?: string; + + @IsString() + @AutoMap() + phone?: string; } diff --git a/src/modules/users/domain/dtos/update-user.request.ts b/src/modules/users/domain/dtos/update-user.request.ts index 96c57ef..0eca819 100644 --- a/src/modules/users/domain/dtos/update-user.request.ts +++ b/src/modules/users/domain/dtos/update-user.request.ts @@ -17,4 +17,8 @@ export class UpdateUserRequest { @IsString() @AutoMap() email?: string; + + @IsString() + @AutoMap() + phone?: string; } diff --git a/src/modules/users/domain/entities/user.ts b/src/modules/users/domain/entities/user.ts index beb4814..77f7720 100644 --- a/src/modules/users/domain/entities/user.ts +++ b/src/modules/users/domain/entities/user.ts @@ -5,11 +5,14 @@ export class User { uuid: string; @AutoMap() - firstName: string; + firstName?: string; @AutoMap() - lastName: string; + lastName?: string; @AutoMap() - email: string; + email?: string; + + @AutoMap() + phone?: string; } diff --git a/src/modules/users/tests/unit/create-user.usecase.spec.ts b/src/modules/users/tests/unit/create-user.usecase.spec.ts index ec1b9ea..2d3a8f5 100644 --- a/src/modules/users/tests/unit/create-user.usecase.spec.ts +++ b/src/modules/users/tests/unit/create-user.usecase.spec.ts @@ -9,10 +9,10 @@ import { CreateUserUseCase } from '../../domain/usecases/create-user.usecase'; import { UserProfile } from '../../mappers/user.profile'; const newUserRequest: CreateUserRequest = { - uuid: 'bb281075-1b98-4456-89d6-c643d3044a91', firstName: 'John', lastName: 'Doe', email: 'john.doe@email.com', + phone: '0601020304', }; const newUserCommand: CreateUserCommand = new CreateUserCommand(newUserRequest); @@ -47,7 +47,7 @@ describe('CreateUserUseCase', () => { }); describe('execute', () => { - it('should create an User and returns new entity object', async () => { + it('should create and return a new user', async () => { const newUser: User = await createUserUseCase.execute(newUserCommand); expect(newUser.lastName).toBe(newUserRequest.lastName); diff --git a/src/modules/users/tests/unit/delete-user.usecase.spec.ts b/src/modules/users/tests/unit/delete-user.usecase.spec.ts index a1cd771..40e5c19 100644 --- a/src/modules/users/tests/unit/delete-user.usecase.spec.ts +++ b/src/modules/users/tests/unit/delete-user.usecase.spec.ts @@ -9,18 +9,21 @@ const mockUsers = [ firstName: 'John', lastName: 'Doe', email: 'john.doe@email.com', + phone: '0601020304', }, { uuid: 'bb281075-1b98-4456-89d6-c643d3044a92', firstName: 'Jane', lastName: 'Doe', email: 'jane.doe@email.com', + phone: '0602030405', }, { uuid: 'bb281075-1b98-4456-89d6-c643d3044a93', firstName: 'Jimmy', lastName: 'Doe', email: 'jimmy.doe@email.com', + phone: '0603040506', }, ]; @@ -57,7 +60,7 @@ describe('DeleteUserUseCase', () => { }); describe('execute', () => { - it('should delete an User', async () => { + it('should delete a user', async () => { const savedUuid = mockUsers[0].uuid; const deleteUserCommand = new DeleteUserCommand(savedUuid); await deleteUserUseCase.execute(deleteUserCommand); diff --git a/src/modules/users/tests/unit/find-all-users.usecase.spec.ts b/src/modules/users/tests/unit/find-all-users.usecase.spec.ts index 16a9c22..326f09f 100644 --- a/src/modules/users/tests/unit/find-all-users.usecase.spec.ts +++ b/src/modules/users/tests/unit/find-all-users.usecase.spec.ts @@ -9,18 +9,21 @@ const mockUsers = [ firstName: 'John', lastName: 'Doe', email: 'john.doe@email.com', + phone: '0601020304', }, { uuid: 'bb281075-1b98-4456-89d6-c643d3044a92', firstName: 'Jane', lastName: 'Doe', email: 'jane.doe@email.com', + phone: '0602030405', }, { uuid: 'bb281075-1b98-4456-89d6-c643d3044a93', firstName: 'Jimmy', lastName: 'Doe', email: 'jimmy.doe@email.com', + phone: '0603040506', }, ]; diff --git a/src/modules/users/tests/unit/find-user-by-uuid.usecase.spec.ts b/src/modules/users/tests/unit/find-user-by-uuid.usecase.spec.ts index b847d7f..81673c5 100644 --- a/src/modules/users/tests/unit/find-user-by-uuid.usecase.spec.ts +++ b/src/modules/users/tests/unit/find-user-by-uuid.usecase.spec.ts @@ -8,6 +8,7 @@ const mockUser = { firstName: 'John', lastName: 'Doe', email: 'john.doe@email.com', + phone: '0601020304', }; const mockUserRepository = {