From 177efdb2ab5250e84be32095c62f9469f689a2d6 Mon Sep 17 00:00:00 2001 From: Alexandre Garbe Date: Fri, 5 Jul 2024 13:47:08 +0200 Subject: [PATCH] chore(api): removed purifyts from createAccountProfile and getAccountFromEmail functions --- .../modules/account/database/accounts.ts | 53 ++++++------------- .../modules/account/features/createAccount.ts | 14 +++-- .../features/validateSubscriptionRequest.ts | 8 ++- 3 files changed, 26 insertions(+), 49 deletions(-) diff --git a/packages/reva-api/modules/account/database/accounts.ts b/packages/reva-api/modules/account/database/accounts.ts index 94d8ed21b..ebc684922 100644 --- a/packages/reva-api/modules/account/database/accounts.ts +++ b/packages/reva-api/modules/account/database/accounts.ts @@ -1,7 +1,4 @@ -import { Either, Left, Maybe, Right } from "purify-ts"; - import { prismaClient } from "../../../prisma/client"; -import { logger } from "../../shared/logger"; import { Account } from ".prisma/client"; export const createAccountProfile = async (params: { @@ -11,37 +8,21 @@ export const createAccountProfile = async (params: { organismId?: string; keycloakId: string; certificationAuthorityId?: string; -}): Promise> => { - try { - const account = await prismaClient.account.create({ - data: { - keycloakId: params.keycloakId, - email: params.email, - firstname: params.firstname, - lastname: params.lastname, - organismId: params.organismId, - certificationAuthorityId: params.certificationAuthorityId, - }, - }); - - return Right(account); - } catch (e) { - logger.error(e); - return Left("error while creating account"); - } -}; +}): Promise => + prismaClient.account.create({ + data: { + keycloakId: params.keycloakId, + email: params.email, + firstname: params.firstname, + lastname: params.lastname, + organismId: params.organismId, + certificationAuthorityId: params.certificationAuthorityId, + }, + }); -export const getAccountFromEmail = async (email: string) => { - try { - const account = await prismaClient.account.findUnique({ - where: { - email, - }, - }); - return Right(Maybe.fromNullable(account)); - } catch (e: unknown) { - const errorMessage = `Error while retrieving account from email - ${e}`; - logger.error(errorMessage); - return Left(errorMessage); - } -}; +export const getAccountFromEmail = async (email: string) => + prismaClient.account.findUnique({ + where: { + email, + }, + }); diff --git a/packages/reva-api/modules/account/features/createAccount.ts b/packages/reva-api/modules/account/features/createAccount.ts index 03eeabe1c..2f87928ba 100644 --- a/packages/reva-api/modules/account/features/createAccount.ts +++ b/packages/reva-api/modules/account/features/createAccount.ts @@ -88,12 +88,10 @@ export const createAccount = async (params: { const keycloakId = await IAM.createAccount(params); //create and return the account in database - return ( - await createAccountProfile({ - ...params, - firstname: params.firstname || "", - lastname: params.lastname || "", - keycloakId, - }) - ).unsafeCoerce(); + return await createAccountProfile({ + ...params, + firstname: params.firstname || "", + lastname: params.lastname || "", + keycloakId, + }); }; diff --git a/packages/reva-api/modules/subscription/features/validateSubscriptionRequest.ts b/packages/reva-api/modules/subscription/features/validateSubscriptionRequest.ts index a50a7e8d1..05c93d59b 100644 --- a/packages/reva-api/modules/subscription/features/validateSubscriptionRequest.ts +++ b/packages/reva-api/modules/subscription/features/validateSubscriptionRequest.ts @@ -55,11 +55,9 @@ export const validateSubscriptionRequest = async ({ } //account check - const oldAccount = ( - await getAccountFromEmail(subscriptionRequest.accountEmail) - ) - .unsafeCoerce() - .extractNullable(); + const oldAccount = await getAccountFromEmail( + subscriptionRequest.accountEmail, + ); if (oldAccount) { throw new Error(