This repository has been archived on 2024-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
p61-project/infrastructure/supabase/repositories/HabitProgressCreate.ts

30 lines
999 B
TypeScript
Raw Permalink Normal View History

2024-04-11 23:03:45 +02:00
import type { HabitProgressCreateRepository } from "@/domain/repositories/HabitProgressCreate"
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 HabitProgressCreateSupabaseRepository
extends SupabaseRepository
implements HabitProgressCreateRepository
{
public execute: HabitProgressCreateRepository["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
.insert(
habitProgressSupabaseDTO.fromDomainDataToSupabaseInsert(
habitProgressData,
),
)
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
}
}