From a5584d0d467a29d1febb9e4632c0fb0c860c5f2a Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 18 Oct 2026 11:44:51 +0700 Subject: [PATCH] fix(raw-materials): remove invalid sku field from product select and resolve localized name --- apps/backend/src/routes/raw-materials.ts | 33 ++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/apps/backend/src/routes/raw-materials.ts b/apps/backend/src/routes/raw-materials.ts index 1a3063e..14f2682 100644 --- a/apps/backend/src/routes/raw-materials.ts +++ b/apps/backend/src/routes/raw-materials.ts @@ -20,7 +20,13 @@ export const rawMaterialsRoute = new Elysia({ prefix: "/raw-materials" }) productVariant: { include: { product: { - select: { id: true, name: true, sku: true } + select: { + id: true, + name: true, + translations: { + select: { langCode: true, name: true } + } + } } } } @@ -30,7 +36,30 @@ export const rawMaterialsRoute = new Elysia({ prefix: "/raw-materials" }) }); if (!rawMaterial) return status(404, { message: "Raw material not found" }); - return rawMaterial; + + const result = { + ...rawMaterial, + bomItems: rawMaterial.bomItems.map((item) => { + const prod = item.productVariant?.product; + if (!prod) return item; + const thName = prod.translations?.find((t) => t.langCode === "th")?.name; + const fallbackName = prod.translations?.[0]?.name; + const resolvedName = prod.name || thName || fallbackName || `Product #${prod.id}`; + return { + ...item, + productVariant: { + ...item.productVariant, + product: { + ...prod, + name: resolvedName, + } + } + }; + }) + }; + + return result; + }) .post("/bulk", async ({ body, status }) => { try {