2
0

fix: 🐛 Webhook duplication

This commit is contained in:
Baptiste Arnaud
2022-05-13 06:46:17 -07:00
parent 936dde2195
commit 7507a1ab1e
2 changed files with 101 additions and 77 deletions

View File

@ -1,4 +1,3 @@
import cuid from 'cuid'
import { Webhook } from 'models'
import { sendRequest } from 'utils'
@ -10,13 +9,15 @@ export const saveWebhook = (webhookId: string, webhook: Partial<Webhook>) =>
})
export const duplicateWebhook = async (
webhookId: string
typebotId: string,
existingWebhookId: string,
newWebhookId: string
): Promise<Webhook | undefined> => {
const { data } = await sendRequest<{ webhook: Webhook }>(
`/api/webhooks/${webhookId}`
`/api/webhooks/${existingWebhookId}`
)
if (!data) return
const newWebhook = { ...data.webhook, id: cuid() }
const newWebhook = { ...data.webhook, id: newWebhookId, typebotId }
await saveWebhook(newWebhook.id, newWebhook)
return newWebhook
}