My prisma model
model Todo {
id Int @default(autoincrement()) @id
title String
content String
status TodoStatus @default(IN_PROGRESS)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
The api call
app.get("/todos/:id", async (req: Request, res: Response) => {
const id = parseInt(req.params.id); // this line
const todo = await prisma.todo.findFirst({
where: { id },
});
res.json(todo);
});
Do I have to always parseInt the id? because by default req.params is a string type, and obviously my Todo primary key is int. I don't see any online resources parsing the int and then only passing to the Prisma query, it feels a bit odd to always parsing the req.params.id to int all the time in every api call.