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(api): clearing a work instruction stores {} instead of null
Sidwebworks95771d153eff
diff --git a/apps/erp/app/modules/shared/shared.service.ts b/apps/erp/app/modules/shared/shared.service.tsindex 1860e17f7d..a1d660c224 100644--- a/apps/erp/app/modules/shared/shared.service.ts+++ b/apps/erp/app/modules/shared/shared.service.ts@@ -813,6 +813,14 @@ export async function assign(.select("id");}+/**+ * The stored work instruction for plain text. Empty text is `{}`, as the+ * editor stores it: the column is NOT NULL, so `null` refused every clear.+ */+export function workInstructionFromText(text: string) {+ return text.trim() ? textToTiptap(text) : {};+}+/*** Replaces one operation's work instruction, as the caller. The text becomes* the editor's document (`textToTiptap`); empty text clears it. An id the@@ -827,7 +835,7 @@ export async function setOperationWorkInstruction(const updated = await ctx.asCaller.supabase.from(table as "jobOperation").update({- workInstruction: text.trim() ? textToTiptap(text) : null,+ workInstruction: workInstructionFromText(text),updatedBy: ctx.auditUserId,updatedAt: datetime.timestamp()})diff --git a/apps/erp/app/modules/shared/shared.work-instruction.test.ts b/apps/erp/app/modules/shared/shared.work-instruction.test.tsnew file mode 100644index 0000000000..c90e105bd2--- /dev/null+++ b/apps/erp/app/modules/shared/shared.work-instruction.test.ts@@ -0,0 +1,17 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,+// including ports, remain AGPLv3; serving them over a network requires releasing their source.++import { expect, it } from "vitest";+import { workInstructionFromText } from "./shared.service";++it("clears to {} rather than null, which the NOT NULL column refuses", () => {+ expect(workInstructionFromText("")).toEqual({});+ expect(workInstructionFromText(" \n ")).toEqual({});+});++it("stores text as the editor's document", () => {+ expect(workInstructionFromText("Torque to **12 Nm**")).toMatchObject({+ type: "doc"+ });+});