Commit pendiente de Etapas 3+4. Son cambios validados (migraciones corriendo, build verde, 521 tests). Hay que commitearlos antes de empezar la siguiente etapa.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { supabase } from '@/lib/supabase'
|
||||
import { db } from '@/persistence/db'
|
||||
import type { Process } from '@/domain/types'
|
||||
|
||||
function toRow(process: Process, userId: string) {
|
||||
@@ -66,13 +65,8 @@ export const supabaseProcessRepo = {
|
||||
},
|
||||
|
||||
async delete(id: string): Promise<void> {
|
||||
// CASCADE en Supabase elimina: activities, gateways, activity_resource_assignments
|
||||
// CASCADE en Supabase elimina: activities, gateways, activity_resource_assignments, simulations
|
||||
const { error } = await supabase.from('processes').delete().eq('id', id)
|
||||
if (error) throw error
|
||||
|
||||
// TODO Sprint 4 Etapa 4: eliminar cuando simulaciones migren a Supabase
|
||||
await db.transaction('rw', [db.simulations], async () => {
|
||||
await db.simulations.where('processId').equals(id).delete()
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
49
src/persistence/supabase/simulation-repo.ts
Normal file
49
src/persistence/supabase/simulation-repo.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { supabase } from '@/lib/supabase'
|
||||
import type { Simulation, SimulationResult } from '@/domain/types'
|
||||
|
||||
function fromRow(row: Record<string, unknown>): Simulation {
|
||||
return {
|
||||
id: row.id as string,
|
||||
processId: row.process_id as string,
|
||||
executedAt: Number(row.executed_at),
|
||||
result: row.result as SimulationResult,
|
||||
resultAutomated: row.result_automated != null
|
||||
? (row.result_automated as SimulationResult)
|
||||
: undefined,
|
||||
}
|
||||
}
|
||||
|
||||
export const supabaseSimulationRepo = {
|
||||
async save(simulation: Simulation): Promise<void> {
|
||||
const { error } = await supabase.from('simulations').insert({
|
||||
id: simulation.id,
|
||||
process_id: simulation.processId,
|
||||
executed_at: simulation.executedAt,
|
||||
result: simulation.result,
|
||||
result_automated: simulation.resultAutomated ?? null,
|
||||
})
|
||||
if (error) throw error
|
||||
},
|
||||
|
||||
async getLatestByProcess(processId: string): Promise<Simulation | undefined> {
|
||||
const { data, error } = await supabase
|
||||
.from('simulations')
|
||||
.select('*')
|
||||
.eq('process_id', processId)
|
||||
.order('executed_at', { ascending: false })
|
||||
.limit(1)
|
||||
.single()
|
||||
if (error) return undefined
|
||||
return fromRow(data as Record<string, unknown>)
|
||||
},
|
||||
|
||||
async getByProcess(processId: string): Promise<Simulation[]> {
|
||||
const { data, error } = await supabase
|
||||
.from('simulations')
|
||||
.select('*')
|
||||
.eq('process_id', processId)
|
||||
.order('executed_at', { ascending: false })
|
||||
if (error) throw error
|
||||
return (data ?? []).map(fromRow)
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user