Extend transaction usage

This commit is contained in:
Jonas Lochmann 2020-09-28 02:00:00 +02:00
parent 62f4e368a6
commit abc2102da5
No known key found for this signature in database
GPG key ID: 8B8C9AEE10FA5B36
47 changed files with 1367 additions and 860 deletions

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 })