chore(webhooks): refactor delete webhook multiregion

This commit is contained in:
Alessandro Magionami
2024-09-10 14:55:52 +02:00
parent e8cb13ad20
commit 261389307b
7 changed files with 120 additions and 40 deletions
@@ -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
}
}
}