slight refactor of delete-by-id implementation
This commit is contained in:
+4
-5
@@ -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 };
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user