2024-03-16 00:36:44 +01:00
|
|
|
import type { GetHabitsByUserIdRepository } from "@/domain/repositories/GetHabitsByUserId"
|
2024-05-02 23:48:47 +02:00
|
|
|
import { SupabaseRepository } from "@/infrastructure/supabase/repositories/_SupabaseRepository"
|
|
|
|
import { habitsSupabaseDTO } from "../data-transfer-objects/HabitDTO"
|
2024-03-15 22:48:28 +01:00
|
|
|
|
|
|
|
export class GetHabitsByUserIdSupabaseRepository
|
|
|
|
extends SupabaseRepository
|
|
|
|
implements GetHabitsByUserIdRepository
|
|
|
|
{
|
2024-03-22 23:41:51 +01:00
|
|
|
public execute: GetHabitsByUserIdRepository["execute"] = async (options) => {
|
|
|
|
const { userId } = options
|
2024-05-02 23:48:47 +02:00
|
|
|
const { data } = await this.supabaseClient
|
2024-03-22 23:41:51 +01:00
|
|
|
.from("habits")
|
|
|
|
.select("*")
|
|
|
|
.eq("user_id", userId)
|
2024-05-02 23:48:47 +02:00
|
|
|
.throwOnError()
|
|
|
|
const habits = data as NonNullable<typeof data>
|
|
|
|
return habitsSupabaseDTO.fromSupabaseToDomain(habits)
|
2024-03-15 22:48:28 +01:00
|
|
|
}
|
|
|
|
}
|