chore: use cuids for webhooks

This commit is contained in:
Mythie
2024-02-27 12:13:56 +11:00
parent a31057d0d1
commit c2daa964c0
9 changed files with 46 additions and 30 deletions

View File

@ -33,7 +33,7 @@ type TEditWebhookFormSchema = z.infer<typeof ZEditWebhookFormSchema>;
export type WebhookPageOptions = { export type WebhookPageOptions = {
params: { params: {
id: number; id: string;
}; };
}; };
@ -43,7 +43,7 @@ export default function WebhookPage({ params }: WebhookPageOptions) {
const { data: webhook, isLoading } = trpc.webhook.getWebhookById.useQuery( const { data: webhook, isLoading } = trpc.webhook.getWebhookById.useQuery(
{ {
id: Number(params.id), id: params.id,
}, },
{ enabled: !!params.id }, { enabled: !!params.id },
); );
@ -63,7 +63,7 @@ export default function WebhookPage({ params }: WebhookPageOptions) {
const onSubmit = async (data: TEditWebhookFormSchema) => { const onSubmit = async (data: TEditWebhookFormSchema) => {
try { try {
await updateWebhook({ await updateWebhook({
id: Number(params.id), id: params.id,
...data, ...data,
}); });

View File

@ -1,7 +1,7 @@
import { prisma } from '@documenso/prisma'; import { prisma } from '@documenso/prisma';
export type DeleteWebhookByIdOptions = { export type DeleteWebhookByIdOptions = {
id: number; id: string;
userId: number; userId: number;
}; };

View File

@ -3,7 +3,7 @@ import type { Prisma } from '@prisma/client';
import { prisma } from '@documenso/prisma'; import { prisma } from '@documenso/prisma';
export type EditWebhookOptions = { export type EditWebhookOptions = {
id: number; id: string;
data: Prisma.WebhookUpdateInput; data: Prisma.WebhookUpdateInput;
userId: number; userId: number;
}; };

View File

@ -1,7 +1,7 @@
import { prisma } from '@documenso/prisma'; import { prisma } from '@documenso/prisma';
export type GetWebhookByIdOptions = { export type GetWebhookByIdOptions = {
id: number; id: string;
userId: number; userId: number;
}; };

View File

@ -7,7 +7,9 @@ import { validateApiToken } from './validateApiToken';
export const subscribeHandler = async (req: NextApiRequest, res: NextApiResponse) => { export const subscribeHandler = async (req: NextApiRequest, res: NextApiResponse) => {
try { try {
const { authorization } = req.headers; const { authorization } = req.headers;
const { webhookUrl, eventTrigger } = req.body; const { webhookUrl, eventTrigger } = req.body;
const user = await validateApiToken({ authorization }); const user = await validateApiToken({ authorization });
const createdWebhook = await prisma.webhook.create({ const createdWebhook = await prisma.webhook.create({

View File

@ -7,7 +7,9 @@ import { validateApiToken } from './validateApiToken';
export const unsubscribeHandler = async (req: NextApiRequest, res: NextApiResponse) => { export const unsubscribeHandler = async (req: NextApiRequest, res: NextApiResponse) => {
try { try {
const { authorization } = req.headers; const { authorization } = req.headers;
const { webhookId } = req.body; const { webhookId } = req.body;
const user = await validateApiToken({ authorization }); const user = await validateApiToken({ authorization });
const deletedWebhook = await prisma.webhook.delete({ const deletedWebhook = await prisma.webhook.delete({

View File

@ -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";

View File

@ -19,19 +19,19 @@ enum Role {
} }
model User { model User {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
name String? name String?
customerId String? @unique customerId String? @unique
email String @unique email String @unique
emailVerified DateTime? emailVerified DateTime?
password String? password String?
source String? source String?
signature String? signature String?
createdAt DateTime @default(now()) createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt updatedAt DateTime @default(now()) @updatedAt
lastSignedIn DateTime @default(now()) lastSignedIn DateTime @default(now())
roles Role[] @default([USER]) roles Role[] @default([USER])
identityProvider IdentityProvider @default(DOCUMENSO) identityProvider IdentityProvider @default(DOCUMENSO)
accounts Account[] accounts Account[]
sessions Session[] sessions Session[]
Document Document[] Document Document[]
@ -41,7 +41,7 @@ model User {
ownedPendingTeams TeamPending[] ownedPendingTeams TeamPending[]
teamMembers TeamMember[] teamMembers TeamMember[]
twoFactorSecret String? twoFactorSecret String?
twoFactorEnabled Boolean @default(false) twoFactorEnabled Boolean @default(false)
twoFactorBackupCodes String? twoFactorBackupCodes String?
VerificationToken VerificationToken[] VerificationToken VerificationToken[]
@ -106,7 +106,7 @@ enum WebhookTriggerEvents {
} }
model Webhook { model Webhook {
id Int @id @default(autoincrement()) id String @id @default(cuid())
webhookUrl String webhookUrl String
eventTriggers WebhookTriggerEvents[] eventTriggers WebhookTriggerEvents[]
secret String? secret String?

View File

@ -11,22 +11,22 @@ export const ZCreateWebhookFormSchema = z.object({
enabled: z.boolean(), 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 type TCreateWebhookFormSchema = z.infer<typeof ZCreateWebhookFormSchema>;
export const ZGetWebhookByIdQuerySchema = z.object({
id: z.string(),
});
export type TGetWebhookByIdQuerySchema = z.infer<typeof ZGetWebhookByIdQuerySchema>; 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 type TEditWebhookMutationSchema = z.infer<typeof ZEditWebhookMutationSchema>;
export const ZDeleteWebhookMutationSchema = z.object({
id: z.string(),
});
export type TDeleteWebhookMutationSchema = z.infer<typeof ZDeleteWebhookMutationSchema>;