Files
lab/src/lib/appwrite/prosthetic-queries.ts
T
kovakmedya f34630de62 fix: serialize Appwrite rows before sending to client components
Next 16's server-to-client serializer rejects values whose prototype is
not plain Object. node-appwrite returns row objects carrying internal
helpers (toString etc.), so every <ClientComponent prop={row}> crashed with
'Only plain objects, and a few built-ins, can be passed to Client
Components from Server Components.'

Added a tiny toPlain helper that JSON-roundtrips any value and applied it
at the boundary of every query that returns rows consumed by 'use client'
files:
  - connection-queries (enrich)
  - job-queries (inbound, outbound, approved labs)
  - job-file-queries (listJobFiles)
  - job-history-queries (listJobHistory)
  - prosthetic-queries (listProsthetics, listActiveProsthetics)
  - finance-queries (listFinanceEntries)
  - notification-helpers (listNotifications)
  - dashboard-queries (getDashboardData)
  - jobs/[jobId] page (direct getRow for the job prop on JobActionsPanel)

Internal Maps inside queries stay live — only the data crossing the
server/client boundary is normalised.
2026-05-21 20:57:59 +03:00

37 lines
1.1 KiB
TypeScript

import "server-only";
import { Query } from "node-appwrite";
import { DATABASE_ID, TABLES, type Prosthetic } from "./schema";
import { createAdminClient } from "./server";
import { toPlain } from "./serialize";
export async function listProsthetics(tenantId: string): Promise<Prosthetic[]> {
const { tablesDB } = createAdminClient();
const result = await tablesDB.listRows({
databaseId: DATABASE_ID,
tableId: TABLES.prosthetics,
queries: [
Query.equal("tenantId", tenantId),
Query.orderAsc("name"),
Query.limit(200),
],
});
return toPlain(result.rows as unknown as Prosthetic[]);
}
export async function listActiveProsthetics(tenantId: string): Promise<Prosthetic[]> {
const { tablesDB } = createAdminClient();
const result = await tablesDB.listRows({
databaseId: DATABASE_ID,
tableId: TABLES.prosthetics,
queries: [
Query.equal("tenantId", tenantId),
Query.notEqual("archived", true),
Query.orderAsc("name"),
Query.limit(200),
],
});
return toPlain(result.rows as unknown as Prosthetic[]);
}