From d72bb07930bc7b9a95954044be5c8da9398121b8 Mon Sep 17 00:00:00 2001 From: pedrodecf Date: Sun, 4 Feb 2024 15:09:19 -0300 Subject: [PATCH] Change user creation useCase to accept authentication with Google --- src/controller/user/registerUser.ts | 8 ++++++-- src/use-cases/user/createUserUseCase.ts | 10 ++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/controller/user/registerUser.ts b/src/controller/user/registerUser.ts index 106154c..c622188 100644 --- a/src/controller/user/registerUser.ts +++ b/src/controller/user/registerUser.ts @@ -10,12 +10,14 @@ export async function registerUser( ) { const registerBodySchema = z.object({ name: z.string(), - surname: z.string(), + surname: z.string().optional(), email: z.string().email(), password: z.string().min(6), + avatar_url: z.string().optional(), + is_google: z.boolean().optional() }) - const { name, surname, email, password } = registerBodySchema.parse( + const { name, surname, email, password, avatar_url, is_google } = registerBodySchema.parse( request.body, ) @@ -27,6 +29,8 @@ export async function registerUser( surname, email, password, + avatar_url, + is_google, }) } catch (error) { if (error instanceof UserAlreadyExistsError) { diff --git a/src/use-cases/user/createUserUseCase.ts b/src/use-cases/user/createUserUseCase.ts index 5a5aa8b..8bde357 100644 --- a/src/use-cases/user/createUserUseCase.ts +++ b/src/use-cases/user/createUserUseCase.ts @@ -5,9 +5,11 @@ import { User } from '@prisma/client' interface CreateUserUseCaseRequest { name: string - surname: string + surname?: string email: string password: string + avatar_url?: string + is_google?: boolean } interface CreateUserUseCaseResponse { @@ -22,6 +24,8 @@ export class CreateUserUseCase { surname, email, password, + avatar_url, + is_google }: CreateUserUseCaseRequest): Promise { const userWithSameEmail = await this.usersRepository.findByEmail(email) @@ -35,7 +39,9 @@ export class CreateUserUseCase { name, surname, email, - password_hash + password_hash, + avatar_url, + is_google }) return {