2024-03-10 09:49:36 +00:00
|
|
|
import DomainEvent from "../DomainEvent";
|
|
|
|
import DomainProjection from "../DomainProjection";
|
2024-03-10 11:22:38 +00:00
|
|
|
import { ApplicationUpdateFinished } from "../events/ApplicationUpdateFinished";
|
|
|
|
import { ApplicationUpdateStarted } from "../events/ApplicationUpdateStarted";
|
2024-03-10 09:49:36 +00:00
|
|
|
|
2024-02-07 22:48:42 +00:00
|
|
|
export type UpdateDefinition = {
|
|
|
|
id: string;
|
|
|
|
newVersion: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default class ApplicationUpdates implements DomainProjection {
|
2024-03-10 11:22:38 +00:00
|
|
|
private pendingUpdates: UpdateDefinition[] = [];
|
2024-02-07 22:48:42 +00:00
|
|
|
handle(event: DomainEvent<any>): void {
|
|
|
|
if (event.type === "ApplicationUpdateStarted") {
|
|
|
|
this.pendingUpdates.push(event.payload);
|
2024-03-10 11:22:38 +00:00
|
|
|
} else if (event.type === "ApplicationUpdateFinished") {
|
|
|
|
this.pendingUpdates = this.pendingUpdates.filter((pendingUpdate) => {
|
|
|
|
return pendingUpdate.id !== event.payload.id;
|
|
|
|
});
|
2024-02-07 22:48:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getPendingUpdates(): UpdateDefinition[] {
|
|
|
|
return this.pendingUpdates;
|
|
|
|
}
|
|
|
|
}
|