slight refactor of delete-by-id implementation

This commit is contained in:
Avraham Sakal
2025-07-28 22:15:40 -04:00
parent 5c8620ef5e
commit 55d35e150c
+4 -5
View File
@@ -25,12 +25,11 @@ export const facts = router({
},
)
.mutation(async ({ input: { factId } }) => {
const deletedFact = db.data.facts.find((fact) => fact.id === factId);
if (!deletedFact) throw new Error("Fact not found");
db.data.facts.splice(
db.data.facts.findIndex((fact) => fact.id === factId),
1,
const deletedFactId = db.data.facts.findIndex(
(fact) => fact.id === factId,
);
if (deletedFactId === -1) throw new Error("Fact not found");
db.data.facts.splice(deletedFactId, 1);
db.write();
return { ok: true };
}),