mirror of
https://github.com/theoludwig/p61-project.git
synced 2024-07-17 07:00:12 +02:00
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { HabitsTracker } from "@/data/domain/entities/HabitsTracker"
|
|
import { Presenter } from "./_Presenter"
|
|
import type {
|
|
RetrieveHabitsTrackerUseCase,
|
|
RetrieveHabitsTrackerUseCaseOptions,
|
|
} from "@/data/domain/use-cases/RetrieveHabitsTracker"
|
|
|
|
export interface HabitsTrackerPresenterState {
|
|
habitsTracker: HabitsTracker
|
|
}
|
|
|
|
export interface HabitsTrackerPresenterOptions {
|
|
retrieveHabitsTrackerUseCase: RetrieveHabitsTrackerUseCase
|
|
}
|
|
|
|
export class HabitsTrackerPresenter
|
|
extends Presenter<HabitsTrackerPresenterState>
|
|
implements HabitsTrackerPresenterOptions
|
|
{
|
|
public retrieveHabitsTrackerUseCase: RetrieveHabitsTrackerUseCase
|
|
|
|
public constructor(options: HabitsTrackerPresenterOptions) {
|
|
const { retrieveHabitsTrackerUseCase } = options
|
|
const habitsTracker = HabitsTracker.default()
|
|
super({ habitsTracker })
|
|
this.retrieveHabitsTrackerUseCase = retrieveHabitsTrackerUseCase
|
|
}
|
|
|
|
public async retrieveHabitsTracker(
|
|
options: RetrieveHabitsTrackerUseCaseOptions,
|
|
): Promise<void> {
|
|
const habitsTracker =
|
|
await this.retrieveHabitsTrackerUseCase.execute(options)
|
|
this.setState((state) => {
|
|
state.habitsTracker = habitsTracker
|
|
})
|
|
}
|
|
}
|