This commit is contained in:
David Arranz 2024-05-20 11:01:40 +02:00
parent c040a247e7
commit 1f6de61a4b
2 changed files with 13 additions and 31 deletions

View File

@ -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,

View File

@ -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<IUserRepository>,
): Promise<boolean> => {
return await adapter
.startTransaction()
.complete(async (t) =>
repository({ transaction: t }).existsUserWithName(name),
);
};
export const findUserByID = async (
id: UniqueID,
adapter: IAdapter,