Skip to content
RED SAGSkills
medium10 pts · first answer countsprismatransactionssql

Moving credits between accounts

This code moves credits between two users. If the server crashes between the two lines, credits disappear. What is the right fix?

await prisma.account.update({
  where: { id: fromId },
  data: { credits: { decrement: amount } },
})
await prisma.account.update({
  where: { id: toId },
  data: { credits: { increment: amount } },
})
Choose one answer