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/HabitCreate.ts

23 lines
826 B
TypeScript
Raw Normal View History

2024-04-05 00:08:40 +02:00
import type { HabitCreateRepository } from "@/domain/repositories/HabitCreate"
2024-05-02 23:48:47 +02:00
import { SupabaseRepository } from "@/infrastructure/supabase/repositories/_SupabaseRepository"
import { habitSupabaseDTO } from "../data-transfer-objects/HabitDTO"
2024-04-05 00:08:40 +02:00
export class HabitCreateSupabaseRepository
extends SupabaseRepository
implements HabitCreateRepository
{
public execute: HabitCreateRepository["execute"] = async (options) => {
const { habitCreateData } = options
2024-05-02 23:48:47 +02:00
const { data } = await this.supabaseClient
2024-04-05 00:08:40 +02:00
.from("habits")
2024-05-02 23:48:47 +02:00
.insert(
habitSupabaseDTO.fromDomainCreateDataToSupabaseInsert(habitCreateData),
)
2024-04-05 00:08:40 +02:00
.select("*")
2024-05-02 23:48:47 +02:00
.single()
.throwOnError()
const insertedHabit = data as NonNullable<typeof data>
return habitSupabaseDTO.fromSupabaseToDomain(insertedHabit)
2024-04-05 00:08:40 +02:00
}
}