From 1f6de61a4b7cf7abcebac88ae8f8aa778961272d Mon Sep 17 00:00:00 2001 From: David Arranz Date: Mon, 20 May 2024 11:01:40 +0200 Subject: [PATCH] . --- .../sequelize/SequelizeBusinessTransaction.ts | 30 ------------------- .../users/application/userServices.ts | 14 ++++++++- 2 files changed, 13 insertions(+), 31 deletions(-) diff --git a/server/src/contexts/common/infrastructure/sequelize/SequelizeBusinessTransaction.ts b/server/src/contexts/common/infrastructure/sequelize/SequelizeBusinessTransaction.ts index c7ae198..7c476f2 100644 --- a/server/src/contexts/common/infrastructure/sequelize/SequelizeBusinessTransaction.ts +++ b/server/src/contexts/common/infrastructure/sequelize/SequelizeBusinessTransaction.ts @@ -24,36 +24,6 @@ export class SequelizeBusinessTransaction return await this._connection.transaction(work); } catch (error: unknown) { //error instanceof BaseError; - - /* - { - name: "SequelizeValidationError", - errors: [ - { - message: "Customer.entity_type cannot be null", - type: "notNull Violation", - path: "entity_type", - value: null, - origin: "CORE", - instance: { - dataValues: { - id: "85ac4089-6ad7-4058-a16a-adf7fbbfe388", - created_at: "2023-08-02T10:42:49.248Z", - }, - ... - ... - }, - isNewRecord: true, - }, - validatorKey: "is_null", - validatorName: null, - validatorArgs: [ - ], - }, - ], - } - */ - throw InfrastructureError.create( InfrastructureError.UNEXCEPTED_ERROR, (error as Error).message, diff --git a/server/src/contexts/users/application/userServices.ts b/server/src/contexts/users/application/userServices.ts index 12940b3..ad318d5 100644 --- a/server/src/contexts/users/application/userServices.ts +++ b/server/src/contexts/users/application/userServices.ts @@ -1,5 +1,5 @@ import { IAdapter, RepositoryBuilder } from "@/contexts/common/domain"; -import { Email, UniqueID } from "@shared/contexts"; +import { Email, Name, UniqueID } from "@shared/contexts"; import { IUserRepository, User } from "../domain"; export const existsUserByID = async ( @@ -12,6 +12,18 @@ export const existsUserByID = async ( .complete(async (t) => repository({ transaction: t }).existsUserWithId(id)); }; +export const existsUserByName = async ( + name: Name, + adapter: IAdapter, + repository: RepositoryBuilder, +): Promise => { + return await adapter + .startTransaction() + .complete(async (t) => + repository({ transaction: t }).existsUserWithName(name), + ); +}; + export const findUserByID = async ( id: UniqueID, adapter: IAdapter,