1
1
mirror of https://github.com/theoludwig/p61-project.git synced 2024-07-17 07:00:12 +02:00
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-04-05 00:08:40 +02:00
interface HabitProgressBase extends EntityData {
2024-03-15 22:48:28 +01:00
habitId: Habit["id"]
2024-03-22 10:23:28 +01:00
}
2024-04-05 00:08:40 +02:00
export interface HabitProgressData extends HabitProgressBase {
2024-03-15 22:48:28 +01:00
goalProgress: GoalProgress
date: Date
}
2024-04-05 00:08:40 +02:00
export interface HabitProgressJSON extends HabitProgressBase {
2024-03-22 10:23:28 +01:00
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
}