Created
December 7, 2025 22:44
-
-
Save trikitrok/078dc61f8bec5ce9af5be563053cec39 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AcmeCompanyApi implements CompanyApi { | |
| private readonly acmeCausesEndpoint: AcmeCausesEndpoint; | |
| private readonly claimOpeningEndpoint: AcmeClaimOpeningEndpoint; | |
| private readonly authTokenRetriever: AcmeAuthTokenRetriever; | |
| constructor(config: AcmeApiConfig = new AcmeApiConfig()) { | |
| this.acmeCausesEndpoint = new AcmeCausesEndpoint(config); | |
| this.claimOpeningEndpoint = new AcmeClaimOpeningEndpoint(config); | |
| this.authTokenRetriever = new AcmeAuthTokenRetriever(config); | |
| } | |
| async open(claim: Claim): Promise<OpeningResult> { | |
| const token = await this.authTokenRetriever.retrieveToken(); | |
| const causes = await this.acmeCausesEndpoint.getAllFor(claim, token); | |
| const cause = this.findCauseInClaim(causes, claim); | |
| const referenceInCompany = await this.claimOpeningEndpoint.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