Tools/domain/projections/ApplicationUpdates.ts

27 lines
885 B
TypeScript
Raw Permalink Normal View History

2024-03-10 09:49:36 +00:00
import DomainEvent from "../DomainEvent";
import DomainProjection from "../DomainProjection";
import { ApplicationUpdateFinished } from "../events/ApplicationUpdateFinished";
import { ApplicationUpdateStarted } from "../events/ApplicationUpdateStarted";
2024-03-10 09:49:36 +00:00
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;
}
}