2024-03-16 00:36:44 +01:00
|
|
|
import type { GetHabitProgressHistoryRepository } from "@/domain/repositories/GetHabitProgressHistory"
|
2024-05-02 23:48:47 +02:00
|
|
|
import { SupabaseRepository } from "@/infrastructure/supabase/repositories/_SupabaseRepository"
|
|
|
|
import { habitProgressHistorySupabaseDTO } from "../data-transfer-objects/HabitProgressDTO"
|
2024-03-15 22:48:28 +01:00
|
|
|
|
2024-03-16 00:36:44 +01:00
|
|
|
export class GetHabitProgressHistorySupabaseRepository
|
2024-03-15 22:48:28 +01:00
|
|
|
extends SupabaseRepository
|
2024-03-16 00:36:44 +01:00
|
|
|
implements GetHabitProgressHistoryRepository
|
2024-03-15 22:48:28 +01:00
|
|
|
{
|
2024-03-22 23:41:51 +01:00
|
|
|
public execute: GetHabitProgressHistoryRepository["execute"] = async (
|
|
|
|
options,
|
|
|
|
) => {
|
2024-03-15 22:48:28 +01:00
|
|
|
const { habit } = options
|
2024-05-02 23:48:47 +02:00
|
|
|
const { data } = await this.supabaseClient
|
2024-03-15 22:48:28 +01:00
|
|
|
.from("habits_progresses")
|
|
|
|
.select("*")
|
|
|
|
.eq("habit_id", habit.id)
|
2024-05-02 23:48:47 +02:00
|
|
|
.throwOnError()
|
|
|
|
const habitProgressHistory = data as NonNullable<typeof data>
|
|
|
|
return habitProgressHistorySupabaseDTO.fromSupabaseToDomain(
|
|
|
|
habitProgressHistory,
|
|
|
|
habit.goal,
|
|
|
|
)
|
2024-03-15 22:48:28 +01:00
|
|
|
}
|
|
|
|
}
|