1
1
mirror of https://github.com/theoludwig/p61-project.git synced 2024-07-17 07:00:12 +02:00
p61-project/domain/entities/HabitsTracker.ts

38 lines
845 B
TypeScript
Raw Normal View History

import type { GoalFrequency } from "./Goal"
2024-04-05 00:08:40 +02:00
import type { Habit } from "./Habit"
import { HabitHistory } from "./HabitHistory"
2024-03-16 00:36:44 +01:00
2024-03-22 10:23:28 +01:00
export interface HabitsTrackerData {
habitsHistory: {
[key in GoalFrequency]: HabitHistory[]
}
2024-03-16 00:36:44 +01:00
}
2024-03-22 10:23:28 +01:00
export class HabitsTracker implements HabitsTrackerData {
public habitsHistory: HabitsTrackerData["habitsHistory"]
2024-03-16 00:36:44 +01:00
2024-03-22 10:23:28 +01:00
public constructor(options: HabitsTrackerData) {
2024-03-16 00:36:44 +01:00
const { habitsHistory } = options
this.habitsHistory = habitsHistory
}
public static default(): HabitsTracker {
return new HabitsTracker({
habitsHistory: {
daily: [],
weekly: [],
monthly: [],
},
})
2024-03-16 00:36:44 +01:00
}
2024-04-05 00:08:40 +02:00
public addHabit(habit: Habit): void {
this.habitsHistory[habit.goal.frequency].push(
new HabitHistory({
habit,
progressHistory: [],
}),
)
}
2024-03-16 00:36:44 +01:00
}