Skip to content

Commit

Permalink
fix restore event missing CityRefreshEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Jan 25, 2025
1 parent 9de5c6d commit 2945ef8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/entity/CityEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ abstract class Event {
constructor(
public readonly type: CityEventType,
public readonly _payload: Record<string, any>,
public readonly createdAt: Date = new Date(),
public readonly createdAt: Date,
) {}

get payload(): Record<string, any> {
Expand All @@ -16,14 +16,14 @@ abstract class Event {
}

export class CityInitializedEvent extends Event {
constructor(payload: Record<string, any>) {
super(CityEventType.CityInitializedEvent, payload);
constructor(payload: Record<string, any>, createdAt: Date = new Date()) {
super(CityEventType.CityInitializedEvent, payload, createdAt);
}
}

export class RefreshEvent extends Event {
constructor(payload: Record<string, any>) {
super(CityEventType.RefreshEvent, payload);
constructor(payload: Record<string, any>, createdAt: Date = new Date()) {
super(CityEventType.RefreshEvent, payload, createdAt);
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/repository/KvCityRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
CityEvent,
CityEventType,
CityInitializedEvent,
RefreshEvent,
} from "@entity/CityEvent";
import { addBreadcrumb } from "@sentry/cloudflare";

Expand Down Expand Up @@ -77,7 +78,12 @@ export class KvCityRepository {
private rebuildEvent(event: EventSchema): CityEvent {
switch (event.type) {
case CityEventType.CityInitializedEvent:
return new CityInitializedEvent(event.payload);
return new CityInitializedEvent(
event.payload,
new Date(event.createdAt),
);
case CityEventType.RefreshEvent:
return new RefreshEvent(event.payload, new Date(event.createdAt));
default:
throw new Error(`Unknown event type: ${event.type}`);
}
Expand Down

0 comments on commit 2945ef8

Please sign in to comment.