[refactor] updated the API
TODO: implement the countdown.store.ts Signed-off-by: s0wlz (Matthias Puchstein) <matthias@puchstein.lu>
This commit is contained in:
14
src/features/countdown/model/countdown.mapper.ts
Normal file
14
src/features/countdown/model/countdown.mapper.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import type {CountdownSnapshot, CountdownSnapshotDto} from "./countdown.types";
|
||||
import {type Duration, millisToDuration} from "../../../shared/time/duration";
|
||||
|
||||
export function mapSnapshotDtoToSnapshot(snapshotDto: CountdownSnapshotDto): CountdownSnapshot {
|
||||
const duration: Duration = millisToDuration(snapshotDto.duration);
|
||||
return {
|
||||
id: snapshotDto.id,
|
||||
label: snapshotDto.label,
|
||||
duration: duration,
|
||||
state: snapshotDto.state,
|
||||
start_epoch: snapshotDto.start_epoch_ms !== null ? new Date(snapshotDto.start_epoch_ms) : null,
|
||||
target_epoch: snapshotDto.target_epoch_ms !== null ? new Date(snapshotDto.target_epoch_ms) : null,
|
||||
};
|
||||
}
|
||||
@@ -1,7 +1,17 @@
|
||||
import type {Duration} from "../../../shared/time/duration";
|
||||
import type {EmptyPayload} from "../../../shared/payloads/empty";
|
||||
|
||||
export type CountdownState = "Idle" | "Running" | "Paused" | "Finished";
|
||||
|
||||
export type CountdownSnapshotDto = {
|
||||
id: number;
|
||||
label: string;
|
||||
duration: number;
|
||||
state: CountdownState;
|
||||
start_epoch_ms: number | null;
|
||||
target_epoch_ms: number | null;
|
||||
};
|
||||
|
||||
export type CountdownSnapshot = {
|
||||
id: number;
|
||||
label: string;
|
||||
@@ -12,7 +22,22 @@ export type CountdownSnapshot = {
|
||||
}
|
||||
|
||||
export type CountdownCommand =
|
||||
| "countdown_create"
|
||||
| "countdown_delete"
|
||||
| "countdown_list"
|
||||
| "countdown_start"
|
||||
| "countdown_pause"
|
||||
| "countdown_resume"
|
||||
| "countdown_reset";
|
||||
| "countdown_reset"
|
||||
| "countdown_snapshot";
|
||||
|
||||
export type CountdownPayload = EmptyPayload | CountdownIdPayload | CountdownCreatePayload;
|
||||
|
||||
export type CountdownIdPayload = {
|
||||
id: number;
|
||||
};
|
||||
|
||||
export type CountdownCreatePayload = {
|
||||
label: string;
|
||||
duration: number;
|
||||
}
|
||||
Reference in New Issue
Block a user