feat: delete webhook functionality

This commit is contained in:
Catalin Pit
2024-02-09 16:28:18 +02:00
parent ddb9dd11d7
commit 0209127136
6 changed files with 56 additions and 16 deletions

View File

@ -1,10 +1,12 @@
import { TRPCError } from '@trpc/server';
import { createWebhook } from '@documenso/lib/server-only/webhooks/create-webhook';
import { deleteWebhookById } from '@documenso/lib/server-only/webhooks/delete-webhook-by-id';
import { getWebhooksByUserId } from '@documenso/lib/server-only/webhooks/get-webhooks-by-user-id';
import { authenticatedProcedure, router } from '../trpc';
import { ZCreateWebhookFormSchema } from './schema';
import { ZDeleteWebhookSchema } from './schema';
export const webhookRouter = router({
getWebhooks: authenticatedProcedure.query(async ({ ctx }) => {
@ -32,4 +34,21 @@ export const webhookRouter = router({
});
}
}),
deleteWebhook: authenticatedProcedure
.input(ZDeleteWebhookSchema)
.mutation(async ({ input, ctx }) => {
try {
const { id } = input;
return await deleteWebhookById({
id,
userId: ctx.user.id,
});
} catch (err) {
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We were unable to create this webhook. Please try again later.',
});
}
}),
});

View File

@ -11,4 +11,10 @@ export const ZCreateWebhookFormSchema = z.object({
enabled: z.boolean(),
});
export const ZDeleteWebhookSchema = z.object({
id: z.number(),
});
export type TCreateWebhookFormSchema = z.infer<typeof ZCreateWebhookFormSchema>;
export type TDeleteWebhookSchema = z.infer<typeof ZDeleteWebhookSchema>;