fix: return existing cost on empty PATCH body instead of 500
Build & Push Docker Image / build (push) Successful in 2m14s
Build & Push Docker Image / build (push) Successful in 2m14s
This commit is contained in:
@@ -91,6 +91,11 @@ router.patch("/costs/:id", requireAuth, requireFeature("costs"), async (req, res
|
||||
if (currency !== undefined) updateData.currency = currency;
|
||||
if (notes !== undefined) updateData.notes = notes;
|
||||
|
||||
if (Object.keys(updateData).length === 0) {
|
||||
res.json(existing);
|
||||
return;
|
||||
}
|
||||
|
||||
const [updated] = await db.update(toolCostsTable).set(updateData).where(eq(toolCostsTable.id, id)).returning();
|
||||
await writeAuditLog(req, "tool_cost", id, "update", { toolId: existing.toolId, ...updateData });
|
||||
res.json(updated);
|
||||
|
||||
Reference in New Issue
Block a user