I was doing some Prisma requests and I noticed that some Promises weren't working.
I know I could use async-await, but this should work.
prisma
.user({ uid })
.then(user => {
if (Object.keys(user).length) throw 'error!'
return prisma.updateUser({
data: { money: user.money - 50 },
where: { id: user.id }
})
})
.then(user => {
prisma
.createLog({
user: { connect: { id: user.id } },
type: 'TICKET_BOUGHT',
date: new Date()
})
.then(() => console.log('Ticket bought'))
})
.catch(error => console.error(error))
If the user doesn't exist, it should throw an error, but instead the second 'then' is run.