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
Raw Normal View History

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
{
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
}
}