27 lines
885 B
TypeScript
27 lines
885 B
TypeScript
import DomainEvent from "../DomainEvent";
|
|
import DomainProjection from "../DomainProjection";
|
|
import { ApplicationUpdateFinished } from "../events/ApplicationUpdateFinished";
|
|
import { ApplicationUpdateStarted } from "../events/ApplicationUpdateStarted";
|
|
|
|
export type UpdateDefinition = {
|
|
id: string;
|
|
newVersion: string;
|
|
};
|
|
|
|
export default class ApplicationUpdates implements DomainProjection {
|
|
private pendingUpdates: UpdateDefinition[] = [];
|
|
handle(event: DomainEvent<any>): void {
|
|
if (event.type === "ApplicationUpdateStarted") {
|
|
this.pendingUpdates.push(event.payload);
|
|
} else if (event.type === "ApplicationUpdateFinished") {
|
|
this.pendingUpdates = this.pendingUpdates.filter((pendingUpdate) => {
|
|
return pendingUpdate.id !== event.payload.id;
|
|
});
|
|
}
|
|
}
|
|
|
|
getPendingUpdates(): UpdateDefinition[] {
|
|
return this.pendingUpdates;
|
|
}
|
|
}
|