fix(raw-materials): remove invalid sku field from product select and resolve localized name
This commit is contained in:
1 parent
a0abfbf306
commit
a5584d0d46
1 file changed
+31
-2
@@ -20,7 +20,13 @@ export const rawMaterialsRoute = new Elysia({ prefix: "/raw-materials" })
|
|||||||
productVariant: {
|
productVariant: {
|
||||||
include: {
|
include: {
|
||||||
product: {
|
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" });
|
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 }) => {
|
.post("/bulk", async ({ body, status }) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in new issue
Block a user