Skip to content

Commit 69d43dc

Browse files
committed
refactor: use default clock
The clock must be replaceable for tests.
1 parent 0470323 commit 69d43dc

7 files changed

Lines changed: 23 additions & 39 deletions

src/main/application/burn_up_query_handler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import {
44
type BurnUpQuery,
55
BurnUpQueryResult,
66
} from "../../shared/domain/burn_up_query";
7-
import type { Clock } from "../../shared/domain/temporal";
7+
import { Clock } from "../../shared/domain/temporal";
88
import { BurnUpProjection } from "../domain/burn_up_projection";
99
import type { EventStore } from "../infrastructure/event_store";
1010

1111
export class BurnUpQueryHandler {
1212
static create({
1313
eventStore,
14-
clock,
14+
clock = Clock.systemDefaultZone(),
1515
}: {
1616
eventStore: EventStore;
17-
clock: Clock;
17+
clock?: Clock;
1818
}) {
1919
return new BurnUpQueryHandler(eventStore, clock);
2020
}

src/main/application/estimate_query_handler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import type {
44
EstimateQuery,
55
EstimateQueryResult,
66
} from "../../shared/domain/estimate_query";
7-
import type { Clock } from "../../shared/domain/temporal";
7+
import { Clock } from "../../shared/domain/temporal";
88
import { EstimateProjection } from "../domain/estimate_projection";
99
import type { EventStore } from "../infrastructure/event_store";
1010

1111
export class EstimateQueryHandler {
1212
static create({
1313
eventStore,
14-
clock,
14+
clock = Clock.systemDefaultZone(),
1515
}: {
1616
eventStore: EventStore;
17-
clock: Clock;
17+
clock?: Clock;
1818
}) {
1919
return new EstimateQueryHandler(eventStore, clock);
2020
}

src/main/application/recent_activities_query_handler.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
// Copyright (c) 2026 Falko Schumann. All rights reserved. MIT license.
22

3-
import type { Clock } from "../../shared/domain/temporal";
4-
import type {
5-
RecentActivitiesQuery,
6-
RecentActivitiesQueryResult,
7-
} from "../../shared/domain/recent_activities_query";
3+
import { Clock } from "../../shared/domain/temporal";
4+
import type { RecentActivitiesQuery, RecentActivitiesQueryResult } from "../../shared/domain/recent_activities_query";
85
import type { EventStore } from "../infrastructure/event_store";
96
import { RecentActivitiesProjection } from "../domain/recent_activities_projection";
107

118
export class RecentActivitiesQueryHandler {
129
static create({
1310
eventStore,
14-
clock,
11+
clock = Clock.systemDefaultZone(),
1512
}: {
1613
eventStore: EventStore;
17-
clock: Clock;
14+
clock?: Clock;
1815
}) {
1916
return new RecentActivitiesQueryHandler(eventStore, clock);
2017
}

src/main/application/report_query_handler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import type {
44
ReportQuery,
55
ReportQueryResult,
66
} from "../../shared/domain/report_query";
7-
import type { Clock } from "../../shared/domain/temporal";
7+
import { Clock } from "../../shared/domain/temporal";
88
import { ReportProjection } from "../domain/report_projection";
99
import type { EventStore } from "../infrastructure/event_store";
1010

1111
export class ReportQueryHandler {
1212
static create({
1313
eventStore,
14-
clock,
14+
clock = Clock.systemDefaultZone(),
1515
}: {
1616
eventStore: EventStore;
17-
clock: Clock;
17+
clock?: Clock;
1818
}) {
1919
return new ReportQueryHandler(eventStore, clock);
2020
}

src/main/application/statistics_query_handler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import type {
44
StatisticsQuery,
55
StatisticsQueryResult,
66
} from "../../shared/domain/statistics_query";
7-
import type { Clock } from "../../shared/domain/temporal";
7+
import { Clock } from "../../shared/domain/temporal";
88
import { StatisticsProjection } from "../domain/statistics_projection";
99
import type { EventStore } from "../infrastructure/event_store";
1010

1111
export class StatisticsQueryHandler {
1212
static create({
1313
eventStore,
14-
clock,
14+
clock = Clock.systemDefaultZone(),
1515
}: {
1616
eventStore: EventStore;
17-
clock: Clock;
17+
clock?: Clock;
1818
}) {
1919
return new StatisticsQueryHandler(eventStore, clock);
2020
}

src/main/application/timesheet_query_handler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { Temporal } from "@js-temporal/polyfill";
44

5-
import type { Clock } from "../../shared/domain/temporal";
5+
import { Clock } from "../../shared/domain/temporal";
66
import type {
77
TimesheetQuery,
88
TimesheetQueryResult,
@@ -18,13 +18,13 @@ export class TimesheetQueryHandler {
1818
eventStore,
1919
holidayRepository,
2020
vacationRepository,
21-
clock,
21+
clock = Clock.systemDefaultZone(),
2222
}: {
2323
capacity?: Temporal.DurationLike | string;
2424
eventStore: EventStore;
2525
holidayRepository: HolidayRepository;
2626
vacationRepository: VacationRepository;
27-
clock: Clock;
27+
clock?: Clock;
2828
}) {
2929
return new TimesheetQueryHandler(
3030
capacity,

src/main/index.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { StopTimerCommandHandler } from "./application/stop_timer_command_handle
1414
import { LogActivityCommandHandler } from "./application/log_activity_command_handler";
1515
import { ExportTimesheetCommandHandler } from "./application/export_timesheet_command_handler";
1616
import { RecentActivitiesQueryHandler } from "./application/recent_activities_query_handler";
17-
import { Clock } from "../shared/domain/temporal";
1817
import { ReportQueryHandler } from "./application/report_query_handler";
1918
import { StatisticsQueryHandler } from "./application/statistics_query_handler";
2019
import { EstimateQueryHandler } from "./application/estimate_query_handler";
@@ -70,7 +69,6 @@ const eventStore = EventStore.create();
7069
const holidayRepository = HolidayRepository.create();
7170
const vacationRepository = VacationRepository.create();
7271
const timesheetExporter = TimesheetExporter.create();
73-
const clock = Clock.systemDefaultZone();
7472

7573
const timerState = TimerState.create();
7674
const startTimerCommandHandler = StartTimerCommandHandler.create({
@@ -85,26 +83,15 @@ const logActivityCommandHandler = LogActivityCommandHandler.create({
8583
});
8684
const recentActivitiesQueryHandler = RecentActivitiesQueryHandler.create({
8785
eventStore,
88-
clock,
89-
});
90-
const reportQueryHandler = ReportQueryHandler.create({ eventStore, clock });
91-
const statisticsQueryHandler = StatisticsQueryHandler.create({
92-
eventStore,
93-
clock,
94-
});
95-
const estimateQueryHandler = EstimateQueryHandler.create({
96-
eventStore,
97-
clock,
98-
});
99-
const burnUpQueryHandler = BurnUpQueryHandler.create({
100-
eventStore,
101-
clock,
10286
});
87+
const reportQueryHandler = ReportQueryHandler.create({ eventStore });
88+
const statisticsQueryHandler = StatisticsQueryHandler.create({ eventStore });
89+
const estimateQueryHandler = EstimateQueryHandler.create({ eventStore });
90+
const burnUpQueryHandler = BurnUpQueryHandler.create({ eventStore });
10391
const timesheetQueryHandler = TimesheetQueryHandler.create({
10492
eventStore,
10593
holidayRepository,
10694
vacationRepository,
107-
clock,
10895
});
10996
const exportTimesheetCommandHandler = ExportTimesheetCommandHandler.create({
11097
timesheetExporter,

0 commit comments

Comments
 (0)