This repository has been archived on 2024-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
p61-project/domain/entities/HabitProgress.ts

42 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-03-22 10:23:28 +01:00
import type { GoalProgress, GoalProgressBase } from "./Goal"
2024-03-15 22:48:28 +01:00
import type { Habit } from "./Habit"
2024-03-22 10:23:28 +01:00
import type { EntityData } from "./_Entity"
2024-03-15 22:48:28 +01:00
import { Entity } from "./_Entity"
2024-03-22 10:23:28 +01:00
interface HabitProgressDataBase extends EntityData {
2024-03-15 22:48:28 +01:00
habitId: Habit["id"]
2024-03-22 10:23:28 +01:00
}
export interface HabitProgressData extends HabitProgressDataBase {
2024-03-15 22:48:28 +01:00
goalProgress: GoalProgress
date: Date
}
2024-03-22 10:23:28 +01:00
export interface HabitProgressJSON extends HabitProgressDataBase {
goalProgress: GoalProgressBase
date: string
}
export class HabitProgress extends Entity implements HabitProgressData {
public habitId: HabitProgressData["habitId"]
public goalProgress: HabitProgressData["goalProgress"]
public date: HabitProgressData["date"]
2024-03-15 22:48:28 +01:00
2024-03-22 10:23:28 +01:00
public constructor(options: HabitProgressData) {
2024-03-15 22:48:28 +01:00
const { id, habitId, goalProgress, date } = options
super({ id })
this.habitId = habitId
this.goalProgress = goalProgress
this.date = date
}
2024-03-22 10:23:28 +01:00
public override toJSON(): HabitProgressJSON {
return {
id: this.id,
habitId: this.habitId,
goalProgress: this.goalProgress,
date: this.date.toISOString(),
}
}
2024-03-15 22:48:28 +01:00
}