feat(raw-materials): add inline price editing with keyboard shortcuts and partial update support
This commit is contained in:
1 parent
a5584d0d46
commit
b030c08f68
2 files changed
+128
-10
No files matched your search
@@ -137,20 +137,30 @@ export const rawMaterialsRoute = new Elysia({ prefix: "/raw-materials" })
|
||||
if (isNaN(id)) return status(400, { message: "Invalid ID" });
|
||||
|
||||
try {
|
||||
const updateData: any = {};
|
||||
if (body.name !== undefined) updateData.name = String(body.name).trim();
|
||||
if (body.unit !== undefined) updateData.unit = String(body.unit).trim();
|
||||
if (body.pricePerUnit !== undefined) {
|
||||
updateData.pricePerUnit =
|
||||
typeof body.pricePerUnit === "string"
|
||||
? parseFloat(body.pricePerUnit) || 0
|
||||
: Number(body.pricePerUnit) || 0;
|
||||
}
|
||||
|
||||
const rawMaterial = await prisma.rawMaterial.update({
|
||||
where: { id },
|
||||
data: body,
|
||||
data: updateData,
|
||||
});
|
||||
return rawMaterial;
|
||||
} catch (err) {
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return status(500, { message: "Failed to update raw material" });
|
||||
return status(500, { message: "Failed to update raw material", error: err.message });
|
||||
}
|
||||
}, {
|
||||
body: t.Object({
|
||||
name: t.String(),
|
||||
unit: t.String(),
|
||||
pricePerUnit: t.Number(),
|
||||
name: t.Optional(t.String()),
|
||||
unit: t.Optional(t.String()),
|
||||
pricePerUnit: t.Optional(t.Union([t.Number(), t.String()])),
|
||||
}),
|
||||
detail: { tags: ["raw-materials"] }
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user