mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
wrap select in a auth transaction
This commit is contained in:
parent
a9779a51e8
commit
d79cc1c39f
1 changed files with 11 additions and 6 deletions
|
|
@ -90,17 +90,22 @@ export const createLabelResolver = authorized<
|
|||
CreateLabelError,
|
||||
MutationCreateLabelArgs
|
||||
>(async (_, { input }, { authTrx, uid }) => {
|
||||
const existingLabel = await labelRepository.findByName(input.name, uid)
|
||||
if (existingLabel) {
|
||||
const label = await authTrx(async (tx) => {
|
||||
const repo = tx.withRepository(labelRepository)
|
||||
const existingLabel = await repo.findByName(input.name, uid)
|
||||
if (existingLabel) {
|
||||
return null
|
||||
}
|
||||
|
||||
return repo.createLabel(input, uid)
|
||||
})
|
||||
|
||||
if (!label) {
|
||||
return {
|
||||
errorCodes: [CreateLabelErrorCode.LabelAlreadyExists],
|
||||
}
|
||||
}
|
||||
|
||||
const label = await authTrx(async (tx) =>
|
||||
tx.withRepository(labelRepository).createLabel(input, uid)
|
||||
)
|
||||
|
||||
analytics.capture({
|
||||
distinctId: uid,
|
||||
event: 'label_created',
|
||||
|
|
|
|||
Loading…
Reference in a new issue