This commit is contained in:
@@ -38,6 +38,31 @@ function fromRow(row: Record<string, unknown>): Process {
|
||||
createdAt: new Date(row.created_at as string).getTime(),
|
||||
updatedAt: new Date(row.updated_at as string).getTime(),
|
||||
ownerId: (row.owner_id as string) ?? '',
|
||||
updatedBy: (row.updated_by as string) ?? '',
|
||||
}
|
||||
}
|
||||
|
||||
// Solo para display — no es parte del dominio puro. La resolución UUID → nombre
|
||||
// es responsabilidad del repositorio, no del dominio (que solo conoce ownerId/updatedBy).
|
||||
export interface ProcessWithUserNames extends Process {
|
||||
ownerName: string
|
||||
ownerAvatarUrl?: string
|
||||
updaterName: string
|
||||
}
|
||||
|
||||
interface UserRef {
|
||||
name: string | null
|
||||
avatar_url?: string | null
|
||||
}
|
||||
|
||||
function fromRowWithUsers(row: Record<string, unknown>): ProcessWithUserNames {
|
||||
const owner = row.owner as UserRef | null
|
||||
const updater = row.updater as UserRef | null
|
||||
return {
|
||||
...fromRow(row),
|
||||
ownerName: owner?.name ?? 'Desconocido',
|
||||
ownerAvatarUrl: owner?.avatar_url ?? undefined,
|
||||
updaterName: updater?.name ?? 'Desconocido',
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,13 +82,16 @@ export const supabaseProcessRepo = {
|
||||
return fromRow(data)
|
||||
},
|
||||
|
||||
async getAll(): Promise<Process[]> {
|
||||
// JOIN con users para resolver owner/updater en una sola query (evita N+1).
|
||||
// Si las FK owner_id/updated_by no están declaradas como relaciones en PostgREST,
|
||||
// este select falla — en ese caso usar el fallback de dos queries + mapeo en memoria.
|
||||
async getAll(): Promise<ProcessWithUserNames[]> {
|
||||
const { data, error } = await supabase
|
||||
.from('processes')
|
||||
.select('*')
|
||||
.select('*, owner:users!owner_id(name, avatar_url), updater:users!updated_by(name)')
|
||||
.order('updated_at', { ascending: false })
|
||||
if (error) throw error
|
||||
return (data ?? []).map(fromRow)
|
||||
return (data ?? []).map((row) => fromRowWithUsers(row as Record<string, unknown>))
|
||||
},
|
||||
|
||||
async delete(id: string): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user