65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
/* import {
|
|
ApplicationServiceError,
|
|
type IApplicationServiceError,
|
|
} from "@/contexts/common/application/services/ApplicationServiceError";
|
|
import { IAdapter, RepositoryBuilder } from "@/contexts/common/domain";
|
|
import { Result, UniqueID } from "@shared/contexts";
|
|
import { NullOr } from "@shared/utilities";
|
|
import { ICustomerParticipantAddress, ICustomerParticipantAddressRepository } from "../../domain";
|
|
|
|
export const participantAddressFinder = async (
|
|
addressId: UniqueID,
|
|
adapter: IAdapter,
|
|
repository: RepositoryBuilder<ICustomerParticipantAddressRepository>
|
|
) => {
|
|
if (addressId.isNull()) {
|
|
return Result.fail<IApplicationServiceError>(
|
|
ApplicationServiceError.create(
|
|
ApplicationServiceError.INVALID_REQUEST_PARAM,
|
|
`Participant address ID required`
|
|
)
|
|
);
|
|
}
|
|
|
|
const transaction = adapter.startTransaction();
|
|
let address: NullOr<ICustomerParticipantAddress> = null;
|
|
|
|
try {
|
|
await transaction.complete(async (t) => {
|
|
address = await repository({ transaction: t }).getById(addressId);
|
|
});
|
|
|
|
if (address === null) {
|
|
return Result.fail<IApplicationServiceError>(
|
|
ApplicationServiceError.create(ApplicationServiceError.NOT_FOUND_ERROR, "", {
|
|
id: addressId.toString(),
|
|
entity: "participant address",
|
|
})
|
|
);
|
|
}
|
|
|
|
return Result.ok<ICustomerParticipantAddress>(address);
|
|
} catch (error: unknown) {
|
|
const _error = error as Error;
|
|
|
|
if (repository().isRepositoryError(_error)) {
|
|
return Result.fail<IApplicationServiceError>(
|
|
ApplicationServiceError.create(
|
|
ApplicationServiceError.REPOSITORY_ERROR,
|
|
_error.message,
|
|
_error
|
|
)
|
|
);
|
|
}
|
|
|
|
return Result.fail<IApplicationServiceError>(
|
|
ApplicationServiceError.create(
|
|
ApplicationServiceError.UNEXCEPTED_ERROR,
|
|
_error.message,
|
|
_error
|
|
)
|
|
);
|
|
}
|
|
};
|
|
*/
|