mirror of
https://github.com/theoludwig/p61-project.git
synced 2024-07-17 07:00:12 +02:00
30 lines
999 B
TypeScript
30 lines
999 B
TypeScript
import type { HabitProgressCreateRepository } from "@/domain/repositories/HabitProgressCreate"
|
|
import { SupabaseRepository } from "@/infrastructure/supabase/repositories/_SupabaseRepository"
|
|
import { habitProgressSupabaseDTO } from "../data-transfer-objects/HabitProgressDTO"
|
|
|
|
export class HabitProgressCreateSupabaseRepository
|
|
extends SupabaseRepository
|
|
implements HabitProgressCreateRepository
|
|
{
|
|
public execute: HabitProgressCreateRepository["execute"] = async (
|
|
options,
|
|
) => {
|
|
const { habitProgressData } = options
|
|
const { data } = await this.supabaseClient
|
|
.from("habits_progresses")
|
|
.insert(
|
|
habitProgressSupabaseDTO.fromDomainDataToSupabaseInsert(
|
|
habitProgressData,
|
|
),
|
|
)
|
|
.select("*")
|
|
.single()
|
|
.throwOnError()
|
|
const insertedProgress = data as NonNullable<typeof data>
|
|
return habitProgressSupabaseDTO.fromSupabaseToDomain(
|
|
insertedProgress,
|
|
habitProgressData.goalProgress.goal,
|
|
)
|
|
}
|
|
}
|