-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgift-card.event-handler.materialized-view.ts
33 lines (32 loc) · 1.48 KB
/
gift-card.event-handler.materialized-view.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { GiftCardEvent } from '../api/gift-card.events';
import { MaterializedView, View } from '@fraktalio/fmodel-ts';
import { GiftCardSummary } from './gift-card.event-handler';
import { Injectable } from '@nestjs/common';
import { GiftCardViewStateRepository } from './gift-card.view-state-repository';
/**
* *** APPLICATION LAYER ***
* ___
* A materialized view implementation - query side component tha handles event and produces and store denormalized state which is adequate for the querying purposes.
* ___
* Materialized view is using/delegating a pure `eventHandler` of type `View`<`S`, `E`> to handle events and produce/store denormalized view state.
* In order to handle the event, materialized view needs to fetch the current view state via `GiftCardViewStateRepository.fetchState` function, and then delegate the event to the `eventHandler/view` which can produce new state as a result.
* Produced state is then stored via `GiftCardViewStateRepository.save` function.
* ___
* @param s - state type that is being evolved - `GiftCardSummary | null`
* @param e - event type that is being handled - `GiftCardEvent`
*/
@Injectable()
export class GiftCardMaterializedView extends MaterializedView<
GiftCardSummary | null,
GiftCardEvent
> {
constructor(
protected readonly eventHandler: View<
GiftCardSummary | null,
GiftCardEvent
>,
protected readonly viewStateRepository: GiftCardViewStateRepository,
) {
super(eventHandler, viewStateRepository);
}
}