2024-04-11 12:31:45 +02:00
|
|
|
import type { HabitEditRepository } from "@/domain/repositories/HabitEdit"
|
2024-05-02 23:48:47 +02:00
|
|
|
import { SupabaseRepository } from "@/infrastructure/supabase/repositories/_SupabaseRepository"
|
|
|
|
import { habitSupabaseDTO } from "../data-transfer-objects/HabitDTO"
|
2024-04-11 12:31:45 +02:00
|
|
|
|
|
|
|
export class HabitEditSupabaseRepository
|
|
|
|
extends SupabaseRepository
|
|
|
|
implements HabitEditRepository
|
|
|
|
{
|
|
|
|
public execute: HabitEditRepository["execute"] = async (options) => {
|
|
|
|
const { habitEditData } = options
|
2024-05-02 23:48:47 +02:00
|
|
|
const { data } = await this.supabaseClient
|
2024-04-11 12:31:45 +02:00
|
|
|
.from("habits")
|
2024-05-02 23:48:47 +02:00
|
|
|
.update(
|
|
|
|
habitSupabaseDTO.fromDomainEditDataToSupabaseUpdate(habitEditData),
|
|
|
|
)
|
2024-04-11 13:07:17 +02:00
|
|
|
.eq("id", habitEditData.id)
|
2024-04-11 12:31:45 +02:00
|
|
|
.select("*")
|
2024-05-02 23:48:47 +02:00
|
|
|
.single()
|
|
|
|
.throwOnError()
|
|
|
|
const updatedHabit = data as NonNullable<typeof data>
|
|
|
|
return habitSupabaseDTO.fromSupabaseToDomain(updatedHabit)
|
2024-04-11 12:31:45 +02:00
|
|
|
}
|
|
|
|
}
|