Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
fix(settings): save a template's own header section as an update (#2040)
Brad Barbin399daeee36cc
diff --git a/.claude/rules/document-template-customizer.md b/.claude/rules/document-template-customizer.mdindex 504b2d6e5e..739f1cc28c 100644--- a/.claude/rules/document-template-customizer.md+++ b/.claude/rules/document-template-customizer.md@@ -52,8 +52,12 @@ are regenerated; that's expected, not a bug.`resolveTemplate(type, stored)` (read-time normalizer: falls back to the defaultand **appends missing built-in blocks hidden** so old rows survive new blocks),`BUILT_IN_SECTIONS`, `collectSectionIds`.-- **merge.ts** — `{{token}}` merge-field catalog; `interpolateContent` fills- header/footer/richText/keyValue at render.+- **merge.ts** — `{token}` merge-field catalog; `interpolateContent` fills+ header/footer/richText/shared/terms at render (keyValue/field use+ `interpolateString`). A paragraph whose merge fields ALL resolve empty is+ dropped (and a list left empty with it), so "Approved by {order.approvedBy}"+ prints nothing on an unapproved PO; a Rich Text or Shared block whose+ content drops out entirely is not rendered, heading included.## Editor UIdiff --git a/apps/erp/app/modules/purchasing/purchasing.server.ts b/apps/erp/app/modules/purchasing/purchasing.server.tsindex ac9ea077eb..a5a2ba04bd 100644--- a/apps/erp/app/modules/purchasing/purchasing.server.ts+++ b/apps/erp/app/modules/purchasing/purchasing.server.ts@@ -4117,6 +4117,61 @@ export const getPurchaseOrder = defineServiceFn({}});+/**+ * Get who approved a purchase order and when.+ *+ * @remarks+ * Reads the order's latest approval request that was not cancelled. When it+ * is Approved, answers the approver (`approvedBy` is the name, `approvedById`+ * the user id) and `approvedDate`, the business day of the decision in the+ * company's timezone. All three are null when the order was never approved,+ * is waiting on a decision, or its latest request was rejected.+ *+ * @param purchaseOrderId - The purchase order's id (`po_…`), not its number.+ * @mcp read+ */+export const getPurchaseOrderApproval = defineServiceFn({+ input: z.object({ purchaseOrderId: z.string().min(1) }),+ permission: { view: "purchasing" },+ async run(ctx, { purchaseOrderId }) {+ // approvalRequest has no RLS policies: prove the caller can see the order.+ const order = await ctx.asCaller.supabase+ .from("purchaseOrder")+ .select("id")+ .eq("id", purchaseOrderId)+ .eq("companyId", ctx.company.id)+ .maybeSingle();+ if (order.error) {+ return ctx.error(+ "internal",+ "Failed to load purchase order",+ order.error+ );+ }+ if (!order.data) {+ return ctx.error("notFound", "Purchase order not found");+ }++ const approval = await service.getPurchaseOrderApproval(+ ctx.asSystem.supabase,+ {+ companyId: ctx.company.id,+ purchaseOrderId,+ timezone: await getCompanyTimeZone(+ ctx.asSystem.supabase,+ ctx.company.id+ )+ }+ );+ return {+ purchaseOrderId,+ approvedBy: approval?.approvedBy ?? null,+ approvedById: approval?.approvedById ?? null,+ approvedDate: approval?.approvedDate ?? null+ };+ }+});+/*** Get purchase orders*diff --git a/apps/erp/app/modules/purchasing/purchasing.service.ts b/apps/erp/app/modules/purchasing/purchasing.service.tsindex 3f6ceaf6df..b4efd0bfca 100644--- a/apps/erp/app/modules/purchasing/purchasing.service.ts+++ b/apps/erp/app/modules/purchasing/purchasing.service.ts@@ -604,8 +604,9 @@ export async function getPurchaseOrderLocations(}/**- * Who approved a purchase order and on which day in the company's timezone,- * for the PDF's `order.approved*` merge fields. Null when it was not approved.+ * Who approved a purchase order and on which day in the company's timezone:+ * the PDF's `order.approved*` merge fields, the order's properties panel and+ * `purchasing.getPurchaseOrderApproval`. Null when it was not approved.*/export async function getPurchaseOrderApproval(serviceRole: SupabaseClient<Database>,@@ -614,7 +615,7 @@ export async function getPurchaseOrderApproval(purchaseOrderId,timezone}: { companyId: string; purchaseOrderId: string; timezone: string }-): Promise<PurchaseOrderApproval | null> {+): Promise<(PurchaseOrderApproval & { approvedById: string | null }) | null> {const approval = await getDocumentApproval(serviceRole,"purchaseOrder",@@ -624,6 +625,7 @@ export async function getPurchaseOrderApproval(if (!approval) return null;return {approvedBy: approval.approvedBy,+ approvedById: approval.approvedById,approvedDate: datetime.businessDay(approval.approvedAt, timezone).toString()};}diff --git a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderProperties.tsx b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderProperties.tsxindex 8e5761aabe..e263445cba 100644--- a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderProperties.tsx+++ b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderProperties.tsx@@ -19,6 +19,7 @@ import {toast,VStack} from "@carbon/react";+import { formatDate } from "@carbon/utils";import { Trans, useLingui } from "@lingui/react/macro";import { useCallback } from "react";import {@@ -67,6 +68,10 @@ const PurchaseOrderProperties = () => {const routeData = useRouteData<{purchaseOrder: PurchaseOrder;supplierQuote: SupplierQuote;+ approval: {+ approvedById: string | null;+ approvedDate: string;+ } | null;}>(path.to.purchaseOrder(orderId));const fetcher = useAction<typeof action>({@@ -490,6 +495,18 @@ const PurchaseOrderProperties = () => {/></VStack>+ {routeData?.approval && (+ <VStack spacing={2}>+ <span className="text-xs font-medium text-muted-foreground">+ <Trans>Approved By</Trans>+ </span>+ <EmployeeAvatar employeeId={routeData.approval.approvedById} />+ <span className="text-xs text-muted-foreground">+ {formatDate(routeData.approval.approvedDate)}+ </span>+ </VStack>+ )}+<CustomFormInlineFieldscustomFields={(routeData?.purchaseOrder?.customFields ?? {}) as Record<string, Json>diff --git a/apps/erp/app/modules/settings/settings.server.ts b/apps/erp/app/modules/settings/settings.server.tsindex 8e0164b4e4..6322f52a56 100644--- a/apps/erp/app/modules/settings/settings.server.ts+++ b/apps/erp/app/modules/settings/settings.server.ts@@ -1411,9 +1411,10 @@ export const viewPrintJobContent = defineServiceFn({* Writes the company's template for one document type: its blocks, theme,* settings and the header and footer sections it uses. The logo and header* layout (`headerConfig`) is edited with the template but lives on the- * company-wide header section, so it is saved onto that section first, with- * the section's name and content kept, and applies wherever the header is- * used. A built-in header section is forked into the company's own copy.+ * company-wide header section, so it is saved onto that section in the same+ * transaction as the template, with the section's name and content kept, and+ * applies wherever the header is used. A built-in header section is forked+ * into the company's own copy.** @mcp*/@@ -1429,49 +1430,45 @@ export const saveDocumentTemplate = defineServiceFn({}),permission: { update: "settings" },async run(ctx, template) {- const client = ctx.asCaller.supabase;const { headerConfig, headerSectionId } = template;+ let header: Parameters<typeof service.upsertDocumentTemplate>[2];if (headerConfig && headerSectionId) {- const resolved = await service.resolveSections(client, ctx.company.id, [- headerSectionId- ]);- const header = resolved[headerSectionId];- const section = await service.upsertDocumentSection(client, {+ const resolved = await service.resolveSections(+ ctx.asCaller.supabase,+ ctx.company.id,+ [headerSectionId]+ );+ const section = resolved[headerSectionId];+ header = {id: headerSectionId,- companyId: ctx.company.id,- name: header?.name ?? "Default Header",- placement: "header",- content: (header?.content ?? {+ name: section?.name ?? "Default Header",+ content: (section?.content ?? {type: "doc",content: []}) as JSONContent,- config: headerConfig as Record<string, unknown>,- createdBy: ctx.auditUserId,- updatedBy: ctx.auditUserId- });- if (section.error) {- return ctx.error("internal", "Failed to save header", section.error);- }+ config: headerConfig as Record<string, unknown>+ };}- const upsert = await service.upsertDocumentTemplate(client, {- companyId: ctx.company.id,- documentType: template.documentType,- blocks: template.blocks as DocumentBlock[],- theme: template.theme as DocumentTheme,- settings: template.settings as DocumentSettings,- headerSectionId: headerSectionId || null,- footerSectionId: template.footerSectionId || null,- createdBy: ctx.auditUserId,- updatedBy: ctx.auditUserId- });- if (upsert.error) {- return ctx.error(- "internal",- "Failed to save document layout",- upsert.error+ // The header layout and the template land together or not at all.+ try {+ await service.upsertDocumentTemplate(+ ctx.asSystem.pg,+ {+ companyId: ctx.company.id,+ documentType: template.documentType,+ blocks: template.blocks as DocumentBlock[],+ theme: template.theme as DocumentTheme,+ settings: template.settings as DocumentSettings,+ headerSectionId: headerSectionId || null,+ footerSectionId: template.footerSectionId || null,+ userId: ctx.auditUserId+ },+ header);+ } catch (err) {+ return ctx.error("internal", "Failed to save document layout", err);}return { documentType: template.documentType };}diff --git a/apps/erp/app/modules/settings/settings.service.ts b/apps/erp/app/modules/settings/settings.service.tsindex b7271ecfc8..6a60277ba2 100644--- a/apps/erp/app/modules/settings/settings.service.ts+++ b/apps/erp/app/modules/settings/settings.service.ts@@ -863,9 +863,15 @@ export async function getDocumentTemplateConfig(return toDocumentTemplate(stored.data, documentType);}-/** The template row only: `settings.documentTemplate.save` also saves the header layout onto its section. */+/**+ * The template row and, when given, its header section's layout, in one+ * transaction: `settings.documentTemplate.save` is the operation. The header+ * row is inserted when the company has none under that id (a built-in header+ * is forked into the company's copy); an existing row takes only the new+ * `config`.+ */export async function upsertDocumentTemplate(- client: SupabaseClient<Database>,+ db: Kysely<KyselyDatabase>,documentTemplate: {companyId: string;documentType: DocumentTemplateType;@@ -874,19 +880,66 @@ export async function upsertDocumentTemplate(settings: DocumentSettings;headerSectionId: string | null;footerSectionId: string | null;- createdBy: string;- updatedBy: string;+ userId: string;+ },+ header?: {+ id: string;+ name: string;+ content: JSONContent;+ config: Record<string, unknown>;}) {- return client.from("documentTemplate").upsert(- {- ...documentTemplate,+ const { companyId, userId } = documentTemplate;+ const now = datetime.timestamp();+ const jsonb = (value: unknown) => sql<Json>`${JSON.stringify(value)}::jsonb`;++ await withTransaction(db, async (trx) => {+ if (header) {+ await trx+ .insertInto("documentSection")+ .values({+ id: header.id,+ companyId,+ name: header.name,+ placement: "header",+ content: jsonb(header.content),+ config: jsonb(header.config),+ createdBy: userId+ })+ .onConflict((oc) =>+ oc.columns(["id", "companyId"]).doUpdateSet({+ config: jsonb(header.config),+ updatedBy: userId,+ updatedAt: now+ })+ )+ .execute();+ }++ const template = {+ blocks: jsonb(documentTemplate.blocks),+ theme: jsonb(documentTemplate.theme),+ settings: jsonb(documentTemplate.settings),+ headerSectionId: documentTemplate.headerSectionId,+ footerSectionId: documentTemplate.footerSectionId,// Always persist the current schema version of the JSON we're writing.formatVersion: CURRENT_TEMPLATE_FORMAT_VERSION,- updatedAt: new Date().toISOString()- },- { onConflict: "companyId,documentType" }- );+ updatedBy: userId,+ updatedAt: now+ };+ await trx+ .insertInto("documentTemplate")+ .values({+ ...template,+ companyId,+ documentType: documentTemplate.documentType,+ createdBy: userId+ })+ .onConflict((oc) =>+ oc.columns(["companyId", "documentType"]).doUpdateSet(template)+ )+ .execute();+ });}export async function getDocumentSections(diff --git a/apps/erp/app/routes/api+/mcp+/lib/tool-manifest.digest.json b/apps/erp/app/routes/api+/mcp+/lib/tool-manifest.digest.jsonindex 022e66aea6..57a2688589 100644--- a/apps/erp/app/routes/api+/mcp+/lib/tool-manifest.digest.json+++ b/apps/erp/app/routes/api+/mcp+/lib/tool-manifest.digest.json@@ -1,5 +1,5 @@{- "totalTools": 1617,+ "totalTools": 1618,"modules": 14,"tools": [{"name":"accounting_closePeriod","classification":"WRITE","schema":"7e5905ac5974","response":"7e5905ac5974","permission":"accounting:update","paginates":false},@@ -948,6 +948,7 @@{"name":"purchasing_getLeaseSchedule","classification":"READ","schema":"dc3a69d0ccf7","response":"8c06f01ac6f1","permission":"purchasing:view","paginates":false},{"name":"purchasing_getLinkedSupplierQuotes","classification":"READ","schema":"a03ea9b74e8a","response":"cb143b1fe761","permission":"purchasing:view","paginates":false},{"name":"purchasing_getPurchaseOrder","classification":"READ","schema":"47850e9f092b","response":"259ccf5593fd","permission":"purchasing:view","paginates":false},+ {"name":"purchasing_getPurchaseOrderApproval","classification":"READ","schema":"1dc426e5562a","response":"fdc5ca69959c","permission":"purchasing:view","paginates":false},{"name":"purchasing_getPurchaseOrderDelivery","classification":"READ","schema":"47850e9f092b","response":"1b814db8a608","permission":"purchasing:view","paginates":false},{"name":"purchasing_getPurchaseOrderLine","classification":"READ","schema":"555dd21fcbd0","response":"d1fd90a42c26","permission":"purchasing:view","paginates":false},{"name":"purchasing_getPurchaseOrderLines","classification":"READ","schema":"47850e9f092b","response":"085f671f872c","permission":"purchasing:view","paginates":false},diff --git a/apps/erp/app/routes/x+/purchase-order+/$orderId.tsx b/apps/erp/app/routes/x+/purchase-order+/$orderId.tsxindex 781ff25295..481fd45e62 100644--- a/apps/erp/app/routes/x+/purchase-order+/$orderId.tsx+++ b/apps/erp/app/routes/x+/purchase-order+/$orderId.tsx@@ -7,6 +7,7 @@ import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { getCarbonServiceRole } from "@carbon/auth/client.server";import { flash } from "@carbon/auth/session.server";+import { getCompanyTimeZone } from "@carbon/database";import {canApproveRequest,canCancelRequest,@@ -26,6 +27,7 @@ import { purchaseOrderApprovalValidator } from "~/modules/purchasing/purchasing.import {getDefaultAttachmentsForPO,getPurchaseOrder,+ getPurchaseOrderApproval,getPurchaseOrderDelivery,getPurchaseOrderLines,getSupplier,@@ -145,7 +147,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {}const serviceRole = getCarbonServiceRole();- const [supplier, interaction, approvalRequest, companySettings] =+ const [supplier, interaction, approvalRequest, companySettings, approval] =await Promise.all([purchaseOrder.data?.supplierId? getSupplier(client, purchaseOrder.data.supplierId)@@ -159,7 +161,15 @@ export async function loader({ request, params }: LoaderFunctionArgs) {orderId): Promise.resolve({ data: null, error: null }),- getCompanySettings(serviceRole, companyId)+ getCompanySettings(serviceRole, companyId),+ // Who approved it, for the properties panel.+ getCompanyTimeZone(serviceRole, companyId).then((timezone) =>+ getPurchaseOrderApproval(serviceRole, {+ companyId,+ purchaseOrderId: orderId,+ timezone+ })+ )]);const defaultCc = supplier?.data?.defaultCc?.length@@ -271,6 +281,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {interaction: interaction?.data,supplier: supplier?.data ?? null,approvalRequest: approvalRequest.data,+ approval,canApprove,canReopen,canDelete,diff --git a/packages/documents/src/pdf/blocks/RichTextBlock.tsx b/packages/documents/src/pdf/blocks/RichTextBlock.tsxindex a391792908..aa66cba27d 100644--- a/packages/documents/src/pdf/blocks/RichTextBlock.tsx+++ b/packages/documents/src/pdf/blocks/RichTextBlock.tsx@@ -6,6 +6,7 @@ import { Text, View } from "@react-pdf/renderer";import type { RichTextBlock as RichTextBlockType } from "../../template";import { interpolateContent } from "../../template";import { Note } from "../components";+import { hasContent } from "./resolveTerms";import { useTw } from "./tw";/**@@ -20,17 +21,15 @@ export function RichTextBlock({vars: Record<string, string>;}) {const tw = useTw();- const hasContent =- block.content &&- typeof block.content === "object" &&- Array.isArray(block.content.content) &&- block.content.content.length > 0;+ const authored = hasContent(block.content);+ if (!authored && !block.title) return null;- if (!hasContent && !block.title) return null;-- const content = hasContent+ const content = authored? interpolateContent(block.content, vars): block.content;+ // Every line was a merge field that came out empty: print nothing, heading+ // included, rather than a heading over an empty box.+ if (authored && !hasContent(content)) return null;return (<View style={tw("border border-gray-200 mb-4")}>@@ -40,7 +39,7 @@ export function RichTextBlock({{block.title}</Text>) : null}- {hasContent ? (+ {authored ? (<View style={tw("text-[9px] text-gray-800")}><Note content={content} /></View>diff --git a/packages/documents/src/pdf/blocks/SharedBlock.tsx b/packages/documents/src/pdf/blocks/SharedBlock.tsxindex efaad3eebc..9ef612efcb 100644--- a/packages/documents/src/pdf/blocks/SharedBlock.tsx+++ b/packages/documents/src/pdf/blocks/SharedBlock.tsx@@ -9,6 +9,7 @@ import type {} from "../../template";import { interpolateContent } from "../../template";import { Note } from "../components";+import { hasContent } from "./resolveTerms";import { useTw } from "./tw";/** Extension block — doc-agnostic. Takes resolved sections + merge `vars`. */@@ -25,13 +26,9 @@ export function SharedBlock({const section = sections[block.sectionId];if (!section) return null;- const hasContent =- section.content &&- typeof section.content === "object" &&- Array.isArray(section.content.content) &&- section.content.content.length > 0;-- if (!hasContent) return null;+ if (!hasContent(section.content)) return null;+ const content = interpolateContent(section.content, vars);+ if (!hasContent(content)) return null;return (<View style={tw("border border-gray-200 mb-4")}>@@ -40,7 +37,7 @@ export function SharedBlock({{section.name}</Text><View style={tw("text-[9px] text-gray-800")}>- <Note content={interpolateContent(section.content, vars)} />+ <Note content={content} /></View></View></View>diff --git a/packages/documents/src/template/merge.ts b/packages/documents/src/template/merge.tsindex 26d9d7c9e6..c5087f5e08 100644--- a/packages/documents/src/template/merge.ts+++ b/packages/documents/src/template/merge.ts@@ -28,25 +28,53 @@ export function interpolateString(return text.replace(TOKEN_RE, (_match, token: string) => vars[token] ?? "");}+/**+ * True when a node holds text directly (a paragraph or heading), its text has+ * at least one merge field, and every merge field in it resolves empty.+ */+function isEmptiedByMergeFields(+ node: JSONContent,+ vars: Record<string, string>+): boolean {+ const children = node.content ?? [];+ if (!children.some((child) => typeof child.text === "string")) return false;+ let fields = 0;+ for (const child of children) {+ for (const [, token] of (child.text ?? "").matchAll(TOKEN_RE)) {+ fields++;+ if (token && vars[token]?.trim()) return false;+ }+ }+ return fields > 0;+}+/*** Deep-clone a tiptap document, replacing `{token}` inside every text node.+ * A paragraph whose merge fields all resolve empty is left out, so+ * "Approved by {order.approvedBy}" prints nothing on an unapproved order+ * rather than "Approved by". A list or other container left with nothing in+ * it is left out too; the document itself is always returned.* Pure — never mutates the input (block state stays as the user authored it).*/export function interpolateContent(content: JSONContent,vars: Record<string, string>): JSONContent {- const walk = (node: JSONContent): JSONContent => {+ const walk = (node: JSONContent): JSONContent | null => {const next: JSONContent = { ...node };if (typeof next.text === "string") {next.text = interpolateString(next.text, vars);}- if (Array.isArray(next.content)) {- next.content = next.content.map(walk);+ if (Array.isArray(node.content)) {+ if (isEmptiedByMergeFields(node, vars)) return null;+ next.content = node.content+ .map(walk)+ .filter((child): child is JSONContent => child !== null);+ if (node.content.length > 0 && next.content.length === 0) return null;}return next;};- return walk(content);+ return walk(content) ?? { ...content, content: [] };}/** Wrap a token for insertion into authored content. */diff --git a/packages/documents/src/template/template.test.ts b/packages/documents/src/template/template.test.tsindex f315314bbb..a72cbcc0e0 100644--- a/packages/documents/src/template/template.test.ts+++ b/packages/documents/src/template/template.test.ts@@ -9,6 +9,7 @@ import {documentThemeColors,resolveTemplate} from "./defaults";+import { interpolateContent } from "./merge";import { blockSchema, documentTemplateSchema } from "./schema";describe("documentThemeColors", () => {@@ -147,3 +148,53 @@ describe("schema validation", () => {).toEqual(DEFAULT_SALES_INVOICE_TEMPLATE);});});++describe("interpolateContent", () => {+ const paragraph = (text: string) => ({+ type: "paragraph",+ content: [{ type: "text", text }]+ });+ const doc = (...content: object[]) => ({ type: "doc", content });+ const approvalLine = paragraph(+ "Approved by {order.approvedBy} on {order.approvedDate}"+ );++ it("fills merge fields", () => {+ expect(+ interpolateContent(doc(approvalLine), {+ "order.approvedBy": "Jordan Lee",+ "order.approvedDate": "Jun 2, 2026"+ })+ ).toEqual(doc(paragraph("Approved by Jordan Lee on Jun 2, 2026")));+ });++ it("leaves out a paragraph whose merge fields are all empty", () => {+ expect(+ interpolateContent(doc(approvalLine, paragraph("Thank you")), {+ "order.approvedBy": "",+ "order.approvedDate": ""+ })+ ).toEqual(doc(paragraph("Thank you")));+ });++ it("keeps a paragraph when one of its merge fields has a value", () => {+ expect(+ interpolateContent(doc(approvalLine), { "order.approvedBy": "Jordan" })+ ).toEqual(doc(paragraph("Approved by Jordan on ")));+ });++ it("keeps paragraphs without merge fields, empty ones included", () => {+ const spacer = { type: "paragraph" };+ expect(interpolateContent(doc(paragraph("Thank you"), spacer), {})).toEqual(+ doc(paragraph("Thank you"), spacer)+ );+ });++ it("leaves out a list whose items all came out empty", () => {+ const list = {+ type: "bulletList",+ content: [{ type: "listItem", content: [approvalLine] }]+ };+ expect(interpolateContent(doc(list), {})).toEqual(doc());+ });+});diff --git a/packages/ee/src/approvals/service.ts b/packages/ee/src/approvals/service.tsindex ccaa79f384..589d721db8 100644--- a/packages/ee/src/approvals/service.ts+++ b/packages/ee/src/approvals/service.ts@@ -747,11 +747,15 @@ export async function getDocumentApproval(documentType: (typeof approvalDocumentType)[number],documentId: string,companyId: string-): Promise<{ approvedBy: string | null; approvedAt: string } | null> {+): Promise<{+ approvedBy: string | null;+ approvedById: string | null;+ approvedAt: string;+} | null> {const latest = await serviceRole.from("approvalRequest").select(- "status, decisionAt, decider:user!approvalRequest_decisionBy_fkey(fullName)"+ "status, decisionAt, decisionBy, decider:user!approvalRequest_decisionBy_fkey(fullName)").eq("documentType", documentType).eq("documentId", documentId)@@ -776,6 +780,7 @@ export async function getDocumentApproval(return {approvedBy: latest.data.decider?.fullName ?? null,+ approvedById: latest.data.decisionBy,approvedAt: latest.data.decisionAt};}