fix(raw-materials): remove invalid sku field from product select and resolve localized name

This commit is contained in:
Your Name committed 2026-10-18 11:44:51 +07:00
1 parent a0abfbf306
commit a5584d0d46
1 file changed
+31 -2
+31 -2
View File
@@ -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 {