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

import type { GoalProgress, GoalProgressBase } from "./Goal"
import type { Habit } from "./Habit"
import type { EntityData } from "./_Entity"
import { Entity } from "./_Entity"
interface HabitProgressBase extends EntityData {
habitId: Habit["id"]
}
export interface HabitProgressData extends HabitProgressBase {
goalProgress: GoalProgress
date: Date
}
export interface HabitProgressJSON extends HabitProgressBase {
goalProgress: GoalProgressBase
date: string
}
export class HabitProgress extends Entity implements HabitProgressData {
public habitId: HabitProgressData["habitId"]
public goalProgress: HabitProgressData["goalProgress"]
public date: HabitProgressData["date"]
public constructor(options: HabitProgressData) {
const { id, habitId, goalProgress, date } = options
super({ id })
this.habitId = habitId
this.goalProgress = goalProgress
this.date = date
}
public override toJSON(): HabitProgressJSON {
return {
id: this.id,
habitId: this.habitId,
goalProgress: this.goalProgress,
date: this.date.toISOString(),
}
}
}