mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
chore: use cuids for webhooks
This commit is contained in:
@ -33,7 +33,7 @@ type TEditWebhookFormSchema = z.infer<typeof ZEditWebhookFormSchema>;
|
||||
|
||||
export type WebhookPageOptions = {
|
||||
params: {
|
||||
id: number;
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
|
||||
@ -43,7 +43,7 @@ export default function WebhookPage({ params }: WebhookPageOptions) {
|
||||
|
||||
const { data: webhook, isLoading } = trpc.webhook.getWebhookById.useQuery(
|
||||
{
|
||||
id: Number(params.id),
|
||||
id: params.id,
|
||||
},
|
||||
{ enabled: !!params.id },
|
||||
);
|
||||
@ -63,7 +63,7 @@ export default function WebhookPage({ params }: WebhookPageOptions) {
|
||||
const onSubmit = async (data: TEditWebhookFormSchema) => {
|
||||
try {
|
||||
await updateWebhook({
|
||||
id: Number(params.id),
|
||||
id: params.id,
|
||||
...data,
|
||||
});
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
export type DeleteWebhookByIdOptions = {
|
||||
id: number;
|
||||
id: string;
|
||||
userId: number;
|
||||
};
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ import type { Prisma } from '@prisma/client';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
export type EditWebhookOptions = {
|
||||
id: number;
|
||||
id: string;
|
||||
data: Prisma.WebhookUpdateInput;
|
||||
userId: number;
|
||||
};
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
export type GetWebhookByIdOptions = {
|
||||
id: number;
|
||||
id: string;
|
||||
userId: number;
|
||||
};
|
||||
|
||||
|
||||
@ -7,7 +7,9 @@ import { validateApiToken } from './validateApiToken';
|
||||
export const subscribeHandler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
try {
|
||||
const { authorization } = req.headers;
|
||||
|
||||
const { webhookUrl, eventTrigger } = req.body;
|
||||
|
||||
const user = await validateApiToken({ authorization });
|
||||
|
||||
const createdWebhook = await prisma.webhook.create({
|
||||
|
||||
@ -7,7 +7,9 @@ import { validateApiToken } from './validateApiToken';
|
||||
export const unsubscribeHandler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
try {
|
||||
const { authorization } = req.headers;
|
||||
|
||||
const { webhookId } = req.body;
|
||||
|
||||
const user = await validateApiToken({ authorization });
|
||||
|
||||
const deletedWebhook = await prisma.webhook.delete({
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- The primary key for the `Webhook` table will be changed. If it partially fails, the table could be left without primary key constraint.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "Webhook" DROP CONSTRAINT "Webhook_pkey",
|
||||
ALTER COLUMN "id" DROP DEFAULT,
|
||||
ALTER COLUMN "id" SET DATA TYPE TEXT,
|
||||
ADD CONSTRAINT "Webhook_pkey" PRIMARY KEY ("id");
|
||||
DROP SEQUENCE "Webhook_id_seq";
|
||||
@ -106,7 +106,7 @@ enum WebhookTriggerEvents {
|
||||
}
|
||||
|
||||
model Webhook {
|
||||
id Int @id @default(autoincrement())
|
||||
id String @id @default(cuid())
|
||||
webhookUrl String
|
||||
eventTriggers WebhookTriggerEvents[]
|
||||
secret String?
|
||||
|
||||
@ -11,22 +11,22 @@ export const ZCreateWebhookFormSchema = z.object({
|
||||
enabled: z.boolean(),
|
||||
});
|
||||
|
||||
export const ZGetWebhookByIdQuerySchema = z.object({
|
||||
id: z.number(),
|
||||
});
|
||||
|
||||
export const ZEditWebhookMutationSchema = ZCreateWebhookFormSchema.extend({
|
||||
id: z.number(),
|
||||
});
|
||||
|
||||
export const ZDeleteWebhookMutationSchema = z.object({
|
||||
id: z.number(),
|
||||
});
|
||||
|
||||
export type TCreateWebhookFormSchema = z.infer<typeof ZCreateWebhookFormSchema>;
|
||||
|
||||
export const ZGetWebhookByIdQuerySchema = z.object({
|
||||
id: z.string(),
|
||||
});
|
||||
|
||||
export type TGetWebhookByIdQuerySchema = z.infer<typeof ZGetWebhookByIdQuerySchema>;
|
||||
|
||||
export type TDeleteWebhookMutationSchema = z.infer<typeof ZDeleteWebhookMutationSchema>;
|
||||
export const ZEditWebhookMutationSchema = ZCreateWebhookFormSchema.extend({
|
||||
id: z.string(),
|
||||
});
|
||||
|
||||
export type TEditWebhookMutationSchema = z.infer<typeof ZEditWebhookMutationSchema>;
|
||||
|
||||
export const ZDeleteWebhookMutationSchema = z.object({
|
||||
id: z.string(),
|
||||
});
|
||||
|
||||
export type TDeleteWebhookMutationSchema = z.infer<typeof ZDeleteWebhookMutationSchema>;
|
||||
|
||||
Reference in New Issue
Block a user