The following example from <https://www.prisma.io/...
# orm-help
y
The following example from https://www.prisma.io/express does not work due to my
id
field being an integer. I get the following error:
PrismaClientValidationError: Argument id: Got invalid value '1' on prisma.updateOnePost. Provided String, expected Int.
Copy code
app.put('/publish/:id', async (req, res) => {
  const { id } = req.params
  const post = await prisma.post.update({
    where: { id },
    data: { published: true },
  })
  res.json(post)
})
Is there anyway to run this without calling
parseInt(id)
?
p
Is there anything stopping you from just using the Number constructor?
d
I use pipe in NestJS. But that’s basicallly parseInt as well.
r
@Yaakov 👋 Prisma validates the types before calling the query so converting to an integer is mandatory.
y
@propagandalf What would be the benefit of the Number constructor over parseInt?
@Ryan Is there a way to document the type of the param expected, so we don't have to convert to integer in each route?
p
There wouldn't really be much of a benefit, its just another form of achieving the same. Without diving too far into it, in fact I wouldn't recommend number over parseint, when you are specifically looking for integers. The "main" thing here is, that your url parameters are stringified, and you need to explicitly make sure those are integers for the database (in this case prisma) to work properly.
💯 1