Extend transaction usage

This commit is contained in:
Jonas Lochmann
2020-10-02 09:58:13 +02:00
parent 62f4e368a6
commit abc2102da5
47 changed files with 1367 additions and 860 deletions
+22 -18
View File
@@ -96,27 +96,31 @@ export const createAdminRouter = ({ database, websocket, eventHandler }: {
throw new BadRequest()
}
const userEntryUnsafe = await database.user.findOne({
where: {
mail
},
attributes: ['familyId']
})
await database.transaction(async (transaction) => {
const userEntryUnsafe = await database.user.findOne({
where: {
mail
},
attributes: ['familyId'],
transaction
})
if (!userEntryUnsafe) {
throw new Conflict('no user with specified mail address')
}
if (!userEntryUnsafe) {
throw new Conflict('no user with specified mail address')
}
const userEntry = {
familyId: userEntryUnsafe.familyId
}
const userEntry = {
familyId: userEntryUnsafe.familyId
}
await addPurchase({
database,
familyId: userEntry.familyId,
type,
transactionId: 'manual-' + type + '-' + generatePurchaseId(),
websocket
await addPurchase({
database,
familyId: userEntry.familyId,
type,
transactionId: 'manual-' + type + '-' + generatePurchaseId(),
websocket,
transaction
})
})
res.json({ ok: true })