2022-03-21 19:20:44 +01:00
|
|
|
import cuid from 'cuid'
|
2022-03-01 07:13:09 +01:00
|
|
|
import { Webhook } from 'models'
|
|
|
|
import { sendRequest } from 'utils'
|
|
|
|
|
|
|
|
export const saveWebhook = (webhookId: string, webhook: Partial<Webhook>) =>
|
|
|
|
sendRequest<{ webhook: Webhook }>({
|
|
|
|
method: 'PUT',
|
|
|
|
url: `/api/webhooks/${webhookId}`,
|
|
|
|
body: webhook,
|
|
|
|
})
|
2022-03-21 19:20:44 +01:00
|
|
|
|
|
|
|
export const duplicateWebhook = async (
|
|
|
|
webhookId: string
|
|
|
|
): Promise<Webhook | undefined> => {
|
|
|
|
const { data } = await sendRequest<{ webhook: Webhook }>(
|
|
|
|
`/api/webhooks/${webhookId}`
|
|
|
|
)
|
|
|
|
if (!data) return
|
|
|
|
const newWebhook = { ...data.webhook, id: cuid() }
|
|
|
|
await saveWebhook(newWebhook.id, newWebhook)
|
|
|
|
return newWebhook
|
|
|
|
}
|