2024-04-11 23:03:45 +02:00
|
|
|
import type { HabitProgressUpdateRepository } from "@/domain/repositories/HabitProgressUpdate"
|
2024-05-02 23:48:47 +02:00
|
|
|
import { SupabaseRepository } from "@/infrastructure/supabase/repositories/_SupabaseRepository"
|
|
|
|
import { habitProgressSupabaseDTO } from "../data-transfer-objects/HabitProgressDTO"
|
2024-04-11 23:03:45 +02:00
|
|
|
|
|
|
|
export class HabitProgressUpdateSupabaseRepository
|
|
|
|
extends SupabaseRepository
|
|
|
|
implements HabitProgressUpdateRepository
|
|
|
|
{
|
|
|
|
public execute: HabitProgressUpdateRepository["execute"] = async (
|
|
|
|
options,
|
|
|
|
) => {
|
|
|
|
const { habitProgressData } = options
|
2024-05-02 23:48:47 +02:00
|
|
|
const { data } = await this.supabaseClient
|
2024-04-11 23:03:45 +02:00
|
|
|
.from("habits_progresses")
|
2024-05-02 23:48:47 +02:00
|
|
|
.update(
|
|
|
|
habitProgressSupabaseDTO.fromDomainDataToSupabaseUpdate(
|
|
|
|
habitProgressData,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.eq("id", habitProgressData.id)
|
2024-04-11 23:03:45 +02:00
|
|
|
.select("*")
|
2024-05-02 23:48:47 +02:00
|
|
|
.single()
|
|
|
|
.throwOnError()
|
|
|
|
const insertedProgress = data as NonNullable<typeof data>
|
|
|
|
return habitProgressSupabaseDTO.fromSupabaseToDomain(
|
|
|
|
insertedProgress,
|
|
|
|
habitProgressData.goalProgress.goal,
|
|
|
|
)
|
2024-04-11 23:03:45 +02:00
|
|
|
}
|
|
|
|
}
|