60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import { IAdapter, RepositoryBuilder } from "@/contexts/common/domain";
|
|
import { Email, Name, UniqueID } from "@shared/contexts";
|
|
import { IUserRepository, User } from "../domain";
|
|
|
|
export const existsUserByID = async (
|
|
id: UniqueID,
|
|
adapter: IAdapter,
|
|
repository: RepositoryBuilder<IUserRepository>,
|
|
): Promise<boolean> => {
|
|
return await adapter
|
|
.startTransaction()
|
|
.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,
|
|
repository: RepositoryBuilder<IUserRepository>,
|
|
): Promise<User | null> => {
|
|
return await adapter
|
|
.startTransaction()
|
|
.complete(async (t) => repository({ transaction: t }).getById(id));
|
|
};
|
|
|
|
export const existsUserByEmail = async (
|
|
email: Email,
|
|
adapter: IAdapter,
|
|
repository: RepositoryBuilder<IUserRepository>,
|
|
): Promise<boolean> => {
|
|
return await adapter
|
|
.startTransaction()
|
|
.complete(async (t) =>
|
|
repository({ transaction: t }).existsUserWithEmail(email),
|
|
);
|
|
};
|
|
|
|
export const findUserByEmail = async (
|
|
email: Email,
|
|
adapter: IAdapter,
|
|
repository: RepositoryBuilder<IUserRepository>,
|
|
): Promise<User | null> => {
|
|
return await adapter
|
|
.startTransaction()
|
|
.complete(async (t) =>
|
|
repository({ transaction: t }).findUserByEmail(email),
|
|
);
|
|
};
|