-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): introduce ADD_PHOTOGRAPH_TO_DIGITAL_TEXT_PAGE (#541)
* implement DigitalText.addPhotographToPage * add handler for PHOTOGRAPH_ADDED_TO_DIGITAL_TEXT_PAGE * add happy path test ADD_PHOTOGRAPH_TO_DIGITAL_TEXT_PAGE * add invalid test cases * add type validation test ADD_PHOTOGRAPH_TO_DIGITAL_TEXT_PAGE * fix tests for ADD_PHOTOGRAPH_TO_DIGITAL_TEXT_PAGE
- Loading branch information
1 parent
6629efc
commit c66dfa0
Showing
19 changed files
with
808 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
59 changes: 59 additions & 0 deletions
59
...dd-photograph-to-digital-text-page/add-photograph-to-digital-text-page.command-handler.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { AggregateType } from '@coscrad/api-interfaces'; | ||
import { CommandHandler } from '@coscrad/commands'; | ||
import { Valid } from '../../../../../domain/domainModelValidators/Valid'; | ||
import { DeluxeInMemoryStore } from '../../../../../domain/types/DeluxeInMemoryStore'; | ||
import { InMemorySnapshot } from '../../../../../domain/types/ResourceType'; | ||
import { InternalError, isInternalError } from '../../../../../lib/errors/InternalError'; | ||
import { isNotFound } from '../../../../../lib/types/not-found'; | ||
import { ResultOrError } from '../../../../../types/ResultOrError'; | ||
import { BaseUpdateCommandHandler } from '../../../shared/command-handlers/base-update-command-handler'; | ||
import { BaseEvent, IEventPayload } from '../../../shared/events/base-event.entity'; | ||
import { EventRecordMetadata } from '../../../shared/events/types/EventRecordMetadata'; | ||
import { DigitalText } from '../../entities'; | ||
import { AddPhotographToDigitalTextPage } from './add-photograph-to-digital-text-page.command'; | ||
import { PhotographAddedToDigitalTextPage } from './photograph-added-to-digital-text-page.event'; | ||
|
||
@CommandHandler(AddPhotographToDigitalTextPage) | ||
export class AddPhotographToDigitalTextPageCommandHandler extends BaseUpdateCommandHandler<DigitalText> { | ||
protected async fetchRequiredExternalState({ | ||
photographId, | ||
}: AddPhotographToDigitalTextPage): Promise<InMemorySnapshot> { | ||
const photographSearchResult = await this.repositoryProvider | ||
.forResource(AggregateType.photograph) | ||
.fetchById(photographId); | ||
|
||
if (isInternalError(photographSearchResult)) { | ||
throw new InternalError( | ||
`Failed to ADD_PHOTOGRAPH_TO_DIGITAL_TEXT due to invalid existing state`, | ||
[photographSearchResult] | ||
); | ||
} | ||
|
||
return new DeluxeInMemoryStore({ | ||
[AggregateType.photograph]: isNotFound(photographSearchResult) | ||
? [] | ||
: [photographSearchResult], | ||
}).fetchFullSnapshotInLegacyFormat(); | ||
} | ||
|
||
protected actOnInstance( | ||
digitalText: DigitalText, | ||
{ pageIdentifier, photographId }: AddPhotographToDigitalTextPage | ||
): ResultOrError<DigitalText> { | ||
return digitalText.addPhotographToPage(pageIdentifier, photographId); | ||
} | ||
|
||
protected validateExternalState( | ||
_state: InMemorySnapshot, | ||
_instance: DigitalText | ||
): InternalError | Valid { | ||
return Valid; | ||
} | ||
|
||
protected buildEvent( | ||
payload: AddPhotographToDigitalTextPage, | ||
eventMeta: EventRecordMetadata | ||
): BaseEvent<IEventPayload> { | ||
return new PhotographAddedToDigitalTextPage(payload, eventMeta); | ||
} | ||
} |
Oops, something went wrong.