Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Created December 7, 2025 22:23
Show Gist options
  • Select an option

  • Save trikitrok/d1a7306ac02ad664e5aa0ca08bb03bfd to your computer and use it in GitHub Desktop.

Select an option

Save trikitrok/d1a7306ac02ad664e5aa0ca08bb03bfd to your computer and use it in GitHub Desktop.
class AcmeCompanyApi implements CompanyApi {
private readonly forGettingCauses: ForGettingCauses;
private readonly forOpeningClaim: ForOpeningClaim;
private readonly authTokenRetriever: AuthTokenRetriever;
constructor(config: AcmeApiConfig = new AcmeApiConfig()) {
this.forGettingCauses = new AcmeCausesEndpoint(config);
this.forOpeningClaim = new AcmeClaimOpeningEndpoint(config);
this.authTokenRetriever = new AcmeAuthTokenRetriever(config);
}
async open(claim: Claim): Promise<OpeningResult> {
const token = await this.authTokenRetriever.retrieveToken();
const causes = await this.forGettingCauses.getAllFor(claim, token);
const cause = this.findCauseInClaim(causes, claim);
const referenceInCompany = await this.forOpeningClaim.open(claim, cause, token);
return OpeningResult.successful(referenceInCompany, claim);
}
private findCauseInClaim(causes: Cause[], claim: Claim): Cause {
let foundCause = causes.find((c) => c.causeCode === claim.causeCode());
if (!foundCause) {
throw new CannotFindMatchingCauseError();
}
return foundCause;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment