feat(process-repo): extender fromRow/toRow/getById con areaId y areaName

- fromRow: extrae areaId y areaName (vía JOIN en getById)
- toRow y updateEditable: incluyen area_id en escrituras a Supabase
- getById: JOIN con areas!area_id(name) para obtener nombre en una query
- Fixtures de tests actualizados con areaId: null (campo requerido)
- 4 tests nuevos en tests/persistence/area-repo.test.ts

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-07-07 18:18:14 -03:00
parent f9e886e12d
commit d6e7226842
16 changed files with 118 additions and 17 deletions

View File

@@ -92,6 +92,7 @@ export function ImportPage() {
ownerId: user!.id,
updatedBy: user!.id,
orgId: null,
areaId: null,
}
const activityElements = extractActivityElements(graph)

View File

@@ -13,6 +13,7 @@ function toRow(process: Process, userId: string) {
analysis_horizon_years: process.analysisHorizonYears,
automation_investment: process.automationInvestment,
group_id: process.groupId,
area_id: process.areaId,
tags: process.tags,
// owner_id se preserva del valor existente en el proceso; solo se inicializa con userId en creates
owner_id: process.ownerId || userId,
@@ -25,6 +26,8 @@ function toRow(process: Process, userId: string) {
function fromRow(row: Record<string, unknown>): Process {
// org puede estar presente si el query hizo JOIN con organizations (getById lo incluye)
const org = row.org as { name: string } | null
// area puede estar presente si el query hizo JOIN con areas (getById lo incluye)
const area = row.area as { name: string } | null
return {
id: row.id as string,
name: row.name as string,
@@ -43,6 +46,8 @@ function fromRow(row: Record<string, unknown>): Process {
updatedBy: (row.updated_by as string) ?? '',
orgId: (row.org_id as string | null) ?? null,
orgName: org?.name ?? null,
areaId: (row.area_id as string | null) ?? null,
areaName: area?.name ?? null,
}
}
@@ -91,6 +96,7 @@ export const supabaseProcessRepo = {
automation_investment: process.automationInvestment,
tags: process.tags,
group_id: process.groupId,
area_id: process.areaId,
updated_by: userId,
updated_at: new Date().toISOString(),
})
@@ -102,7 +108,7 @@ export const supabaseProcessRepo = {
// JOIN con organizations para obtener orgName en una sola query (evita fetch separado y race conditions)
const { data, error } = await supabase
.from('processes')
.select('*, org:organizations!org_id(name)')
.select('*, org:organizations!org_id(name), area:areas!area_id(name)')
.eq('id', id)
.single()
if (error) return undefined