fix(workspace): obtener orgName via JOIN en getById, eliminar fetch separado con race condition
Some checks failed
/ Deploy to Cloudflare Pages (push) Has been cancelled

This commit is contained in:
2026-07-07 15:26:52 -03:00
parent 6fee592e40
commit df5fb55696
3 changed files with 11 additions and 16 deletions

View File

@@ -23,6 +23,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
return {
id: row.id as string,
name: row.name as string,
@@ -40,6 +42,7 @@ function fromRow(row: Record<string, unknown>): Process {
ownerId: (row.owner_id as string) ?? '',
updatedBy: (row.updated_by as string) ?? '',
orgId: (row.org_id as string | null) ?? null,
orgName: org?.name ?? null,
}
}
@@ -96,13 +99,14 @@ export const supabaseProcessRepo = {
},
async getById(id: string): Promise<Process | undefined> {
// JOIN con organizations para obtener orgName en una sola query (evita fetch separado y race conditions)
const { data, error } = await supabase
.from('processes')
.select('*')
.select('*, org:organizations!org_id(name)')
.eq('id', id)
.single()
if (error) return undefined
return fromRow(data)
return fromRow(data as Record<string, unknown>)
},
// JOIN con users para resolver owner/updater en una sola query (evita N+1).