1
1
mirror of https://github.com/theoludwig/p61-project.git synced 2024-07-17 07:00:12 +02:00
p61-project/infrastructure/supabase/repositories/GetHabitProgressHistory.ts

25 lines
892 B
TypeScript

import type { GetHabitProgressHistoryRepository } from "@/domain/repositories/GetHabitProgressHistory"
import { SupabaseRepository } from "@/infrastructure/supabase/repositories/_SupabaseRepository"
import { habitProgressHistorySupabaseDTO } from "../data-transfer-objects/HabitProgressDTO"
export class GetHabitProgressHistorySupabaseRepository
extends SupabaseRepository
implements GetHabitProgressHistoryRepository
{
public execute: GetHabitProgressHistoryRepository["execute"] = async (
options,
) => {
const { habit } = options
const { data } = await this.supabaseClient
.from("habits_progresses")
.select("*")
.eq("habit_id", habit.id)
.throwOnError()
const habitProgressHistory = data as NonNullable<typeof data>
return habitProgressHistorySupabaseDTO.fromSupabaseToDomain(
habitProgressHistory,
habit.goal,
)
}
}