mirror of
https://github.com/theoludwig/p61-project.git
synced 2024-07-17 07:00:12 +02:00
38 lines
845 B
TypeScript
38 lines
845 B
TypeScript
import type { GoalFrequency } from "./Goal"
|
|
import type { Habit } from "./Habit"
|
|
import { HabitHistory } from "./HabitHistory"
|
|
|
|
export interface HabitsTrackerData {
|
|
habitsHistory: {
|
|
[key in GoalFrequency]: HabitHistory[]
|
|
}
|
|
}
|
|
|
|
export class HabitsTracker implements HabitsTrackerData {
|
|
public habitsHistory: HabitsTrackerData["habitsHistory"]
|
|
|
|
public constructor(options: HabitsTrackerData) {
|
|
const { habitsHistory } = options
|
|
this.habitsHistory = habitsHistory
|
|
}
|
|
|
|
public static default(): HabitsTracker {
|
|
return new HabitsTracker({
|
|
habitsHistory: {
|
|
daily: [],
|
|
weekly: [],
|
|
monthly: [],
|
|
},
|
|
})
|
|
}
|
|
|
|
public addHabit(habit: Habit): void {
|
|
this.habitsHistory[habit.goal.frequency].push(
|
|
new HabitHistory({
|
|
habit,
|
|
progressHistory: [],
|
|
}),
|
|
)
|
|
}
|
|
}
|