chore(webhooks): refactor delete webhook multiregion
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
import { Resolvers } from '@/modules/core/graph/generated/graphql'
|
||||
import { authorizeResolver } from '@/modules/shared'
|
||||
import { createWebhook, updateWebhook } from '@/modules/webhooks/services/webhooks-new'
|
||||
import {
|
||||
createWebhook,
|
||||
deleteWebhook,
|
||||
updateWebhook
|
||||
} from '@/modules/webhooks/services/webhooks-new'
|
||||
import { Roles } from '@speckle/shared'
|
||||
import {
|
||||
countWebhooksByStreamIdFactory,
|
||||
createWebhookFactory,
|
||||
deleteWebhookFactory,
|
||||
getWebhookByIdFactory,
|
||||
updateWebhookFactory
|
||||
} from '@/modules/webhooks/repositories/webhooks'
|
||||
@@ -61,6 +66,19 @@ export = {
|
||||
})
|
||||
|
||||
return updated
|
||||
},
|
||||
webhookDelete: async (_parent, args, context) => {
|
||||
await authorizeResolver(
|
||||
context.userId,
|
||||
args.webhook.streamId,
|
||||
Roles.Stream.Owner,
|
||||
context.resourceAccessRules
|
||||
)
|
||||
|
||||
return await deleteWebhook({
|
||||
deleteWebhookConfig: deleteWebhookFactory({ db }),
|
||||
getWebhookById: getWebhookByIdFactory({ db })
|
||||
})(args.webhook)
|
||||
}
|
||||
}
|
||||
} as Resolvers
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
const { authorizeResolver } = require('@/modules/shared')
|
||||
const {
|
||||
deleteWebhook,
|
||||
getStreamWebhooks,
|
||||
getLastWebhookEvents,
|
||||
getWebhookEventsCount
|
||||
@@ -8,7 +7,6 @@ const {
|
||||
const { Roles } = require('@speckle/shared')
|
||||
const { getWebhookByIdFactory } = require('../../repositories/webhooks')
|
||||
const { db } = require('@/db/knex')
|
||||
const { ForbiddenError } = require('@/modules/shared/errors')
|
||||
|
||||
const streamWebhooksResolver = async (parent, args, context) => {
|
||||
await authorizeResolver(
|
||||
@@ -49,26 +47,5 @@ module.exports = {
|
||||
|
||||
return { items, totalCount }
|
||||
}
|
||||
},
|
||||
|
||||
Mutation: {
|
||||
async webhookDelete(parent, args, context) {
|
||||
await authorizeResolver(
|
||||
context.userId,
|
||||
args.webhook.streamId,
|
||||
Roles.Stream.Owner,
|
||||
context.resourceAccessRules
|
||||
)
|
||||
|
||||
const wh = await getWebhookByIdFactory({ db })({ id: args.webhook.id })
|
||||
if (args.webhook.streamId !== wh.streamId)
|
||||
throw new ForbiddenError(
|
||||
'The webhook id and stream id do not match. Please check your inputs.'
|
||||
)
|
||||
|
||||
const deleted = await deleteWebhook({ id: args.webhook.id })
|
||||
|
||||
return !!deleted
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user