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 } }) => {
|
.mutation(async ({ input: { factId } }) => {
|
||||||
const deletedFact = db.data.facts.find((fact) => fact.id === factId);
|
const deletedFactId = db.data.facts.findIndex(
|
||||||
if (!deletedFact) throw new Error("Fact not found");
|
(fact) => fact.id === factId,
|
||||||
db.data.facts.splice(
|
|
||||||
db.data.facts.findIndex((fact) => fact.id === factId),
|
|
||||||
1,
|
|
||||||
);
|
);
|
||||||
|
if (deletedFactId === -1) throw new Error("Fact not found");
|
||||||
|
db.data.facts.splice(deletedFactId, 1);
|
||||||
db.write();
|
db.write();
|
||||||
return { ok: true };
|
return { ok: true };
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user