chore(webhooks): rename repository functions

This commit is contained in:
Alessandro Magionami 2024-09-17 10:25:03 +02:00
Родитель c88c464842
Коммит 194d49dc61
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: EC367516F896CBA4
4 изменённых файлов: 24 добавлений и 24 удалений

Просмотреть файл

@ -1,6 +1,6 @@
import { Webhook, WebhookEvent } from '@/modules/webhooks/domain/types'
export type CreateWebhook = (
export type CreateWebhookConfig = (
webhook: Pick<
Webhook,
'id' | 'streamId' | 'url' | 'description' | 'secret' | 'enabled' | 'triggers'
@ -13,7 +13,7 @@ export type CountWebhooksByStreamId = ({
export type GetWebhookById = ({ id }: Pick<Webhook, 'id'>) => Promise<Webhook | null>
export type UpdateWebhook = ({
export type UpdateWebhookConfig = ({
webhookId,
webhookInput
}: {
@ -27,7 +27,7 @@ export type UpdateWebhook = ({
>
}) => Promise<string>
export type DeleteWebhook = ({ id }: Pick<Webhook, 'id'>) => Promise<number>
export type DeleteWebhookConfig = ({ id }: Pick<Webhook, 'id'>) => Promise<number>
export type GetStreamWebhooks = ({
streamId

Просмотреть файл

@ -8,13 +8,13 @@ import {
import { Roles } from '@speckle/shared'
import {
countWebhooksByStreamIdFactory,
createWebhookFactory,
deleteWebhookFactory,
createWebhookConfigFactory,
deleteWebhookConfigFactory,
getLastWebhookEventsFactory,
getStreamWebhooksFactory,
getWebhookByIdFactory,
getWebhookEventsCountFactory,
updateWebhookFactory
updateWebhookConfigFactory
} from '@/modules/webhooks/repositories/webhooks'
import { db } from '@/db/knex'
import { ForbiddenError } from '@/modules/shared/errors'
@ -74,7 +74,7 @@ export = {
)
const id = await createWebhook({
createWebhookConfig: createWebhookFactory({ db }),
createWebhookConfig: createWebhookConfigFactory({ db }),
countWebhooksByStreamId: countWebhooksByStreamIdFactory({ db })
})({
streamId: args.webhook.streamId,
@ -102,7 +102,7 @@ export = {
)
const updated = await updateWebhook({
updateWebhookConfig: updateWebhookFactory({ db })
updateWebhookConfig: updateWebhookConfigFactory({ db })
})({
id: args.webhook.id,
url: args.webhook.url,
@ -123,7 +123,7 @@ export = {
)
return await deleteWebhook({
deleteWebhookConfig: deleteWebhookFactory({ db }),
deleteWebhookConfig: deleteWebhookConfigFactory({ db }),
getWebhookById: getWebhookByIdFactory({ db })
})(args.webhook)
}

Просмотреть файл

@ -2,14 +2,14 @@ import { Knex } from 'knex'
import { Webhook, WebhookEvent } from '@/modules/webhooks/domain/types'
import {
CountWebhooksByStreamId,
CreateWebhook,
CreateWebhookConfig,
CreateWebhookEvent,
DeleteWebhook,
DeleteWebhookConfig,
GetLastWebhookEvents,
GetStreamWebhooks,
GetWebhookById,
GetWebhookEventsCount,
UpdateWebhook
UpdateWebhookConfig
} from '@/modules/webhooks/domain/operations'
type WebhookConfig = Omit<Webhook, 'triggers'> & { triggers: Record<string, true> }
@ -25,8 +25,8 @@ const toTriggersObj = (triggers: string[]): Record<string, true> =>
const toTriggersArray = (triggers: Record<string, true>): string[] =>
Object.keys(triggers)
export const createWebhookFactory =
({ db }: { db: Knex }): CreateWebhook =>
export const createWebhookConfigFactory =
({ db }: { db: Knex }): CreateWebhookConfig =>
async ({ id, streamId, url, description, secret, enabled, triggers }) => {
const triggersObj = toTriggersObj(triggers)
@ -62,8 +62,8 @@ export const getWebhookByIdFactory =
return { ...webhook, triggers: toTriggersArray(webhook.triggers) }
}
export const updateWebhookFactory =
({ db }: { db: Knex }): UpdateWebhook =>
export const updateWebhookConfigFactory =
({ db }: { db: Knex }): UpdateWebhookConfig =>
async ({ webhookId, webhookInput }) => {
const { triggers, ...update } = webhookInput
let triggersObj: Record<string, true> | undefined
@ -78,8 +78,8 @@ export const updateWebhookFactory =
return webhookId
}
export const deleteWebhookFactory =
({ db }: { db: Knex }): DeleteWebhook =>
export const deleteWebhookConfigFactory =
({ db }: { db: Knex }): DeleteWebhookConfig =>
async ({ id }) => {
return await tables(db).webhooksConfigs.where({ id }).del()
}

Просмотреть файл

@ -2,11 +2,11 @@ import { getServerInfo as getServerInfoFn } from '@/modules/core/services/generi
import { ForbiddenError } from '@/modules/shared/errors'
import {
CountWebhooksByStreamId,
CreateWebhook,
CreateWebhookConfig,
CreateWebhookEvent,
DeleteWebhook,
DeleteWebhookConfig,
GetWebhookById,
UpdateWebhook
UpdateWebhookConfig
} from '@/modules/webhooks/domain/operations'
import { Webhook } from '@/modules/webhooks/domain/types'
import { SetValuesNullable } from '@speckle/shared'
@ -28,7 +28,7 @@ export const createWebhook =
createWebhookConfig,
countWebhooksByStreamId
}: {
createWebhookConfig: CreateWebhook
createWebhookConfig: CreateWebhookConfig
countWebhooksByStreamId: CountWebhooksByStreamId
}) =>
async ({
@ -59,7 +59,7 @@ export const createWebhook =
}
export const updateWebhook =
({ updateWebhookConfig }: { updateWebhookConfig: UpdateWebhook }) =>
({ updateWebhookConfig }: { updateWebhookConfig: UpdateWebhookConfig }) =>
async (
webhook: Pick<Webhook, 'id'> &
Partial<SetValuesNullable<Omit<Webhook, 'id' | 'updatedAt'>>>
@ -84,7 +84,7 @@ export const deleteWebhook =
deleteWebhookConfig,
getWebhookById
}: {
deleteWebhookConfig: DeleteWebhook
deleteWebhookConfig: DeleteWebhookConfig
getWebhookById: GetWebhookById
}) =>
async ({ id, streamId }: { id: string; streamId: string }) => {