Uses app relationship instead of custom type
parent
39ed8e5201
commit
c87df23cd8
|
@ -1,5 +0,0 @@
|
|||
-- CreateEnum
|
||||
CREATE TYPE "SubscriptionType" AS ENUM ('WEBHOOK', 'ZAPIER');
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Webhook" ADD COLUMN "subscriptionType" "SubscriptionType" NOT NULL DEFAULT E'WEBHOOK';
|
|
@ -1,5 +0,0 @@
|
|||
-- CreateEnum
|
||||
CREATE TYPE "ApiKeyType" AS ENUM ('OTHER', 'ZAPIER');
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "ApiKey" ADD COLUMN "apiKeyType" "ApiKeyType" NOT NULL DEFAULT E'OTHER';
|
|
@ -0,0 +1,11 @@
|
|||
-- AlterTable
|
||||
ALTER TABLE "ApiKey" ADD COLUMN "appId" TEXT;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Webhook" ADD COLUMN "appId" TEXT;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Webhook" ADD CONSTRAINT "Webhook_appId_fkey" FOREIGN KEY ("appId") REFERENCES "App"("slug") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "ApiKey" ADD CONSTRAINT "ApiKey_appId_fkey" FOREIGN KEY ("appId") REFERENCES "App"("slug") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@ -376,28 +376,19 @@ enum WebhookTriggerEvents {
|
|||
BOOKING_CANCELLED
|
||||
}
|
||||
|
||||
enum SubscriptionType {
|
||||
WEBHOOK
|
||||
ZAPIER
|
||||
}
|
||||
|
||||
model Webhook {
|
||||
id String @id @unique
|
||||
userId Int?
|
||||
eventTypeId Int?
|
||||
subscriberUrl String
|
||||
payloadTemplate String?
|
||||
createdAt DateTime @default(now())
|
||||
active Boolean @default(true)
|
||||
eventTriggers WebhookTriggerEvents[]
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
eventType EventType? @relation(fields: [eventTypeId], references: [id], onDelete: Cascade)
|
||||
subscriptionType SubscriptionType @default(WEBHOOK)
|
||||
}
|
||||
|
||||
enum ApiKeyType {
|
||||
OTHER
|
||||
ZAPIER
|
||||
id String @id @unique
|
||||
userId Int?
|
||||
eventTypeId Int?
|
||||
subscriberUrl String
|
||||
payloadTemplate String?
|
||||
createdAt DateTime @default(now())
|
||||
active Boolean @default(true)
|
||||
eventTriggers WebhookTriggerEvents[]
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
eventType EventType? @relation(fields: [eventTypeId], references: [id], onDelete: Cascade)
|
||||
app App? @relation(fields: [appId], references: [slug], onDelete: Cascade)
|
||||
appId String?
|
||||
}
|
||||
|
||||
model Impersonations {
|
||||
|
@ -410,15 +401,16 @@ model Impersonations {
|
|||
}
|
||||
|
||||
model ApiKey {
|
||||
id String @id @unique @default(cuid())
|
||||
id String @id @unique @default(cuid())
|
||||
userId Int
|
||||
note String?
|
||||
createdAt DateTime @default(now())
|
||||
createdAt DateTime @default(now())
|
||||
expiresAt DateTime?
|
||||
lastUsedAt DateTime?
|
||||
hashedKey String @unique()
|
||||
apiKeyType ApiKeyType @default(OTHER)
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
hashedKey String @unique()
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
app App? @relation(fields: [appId], references: [slug], onDelete: Cascade)
|
||||
appId String?
|
||||
}
|
||||
|
||||
model HashedLink {
|
||||
|
@ -476,4 +468,6 @@ model App {
|
|||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
credentials Credential[]
|
||||
Webhook Webhook[]
|
||||
ApiKey ApiKey[]
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as z from "zod"
|
||||
import * as imports from "../zod-utils"
|
||||
import { WebhookTriggerEvents, SubscriptionType } from "@prisma/client"
|
||||
import { CompleteUser, UserModel, CompleteEventType, EventTypeModel } from "./index"
|
||||
import { WebhookTriggerEvents } from "@prisma/client"
|
||||
import { CompleteUser, UserModel, CompleteEventType, EventTypeModel, CompleteApp, AppModel } from "./index"
|
||||
|
||||
export const _WebhookModel = z.object({
|
||||
id: z.string(),
|
||||
|
@ -12,12 +12,13 @@ export const _WebhookModel = z.object({
|
|||
createdAt: z.date(),
|
||||
active: z.boolean(),
|
||||
eventTriggers: z.nativeEnum(WebhookTriggerEvents).array(),
|
||||
subscriptionType: z.nativeEnum(SubscriptionType),
|
||||
appId: z.string().nullish(),
|
||||
})
|
||||
|
||||
export interface CompleteWebhook extends z.infer<typeof _WebhookModel> {
|
||||
user?: CompleteUser | null
|
||||
eventType?: CompleteEventType | null
|
||||
app?: CompleteApp | null
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,4 +29,5 @@ export interface CompleteWebhook extends z.infer<typeof _WebhookModel> {
|
|||
export const WebhookModel: z.ZodSchema<CompleteWebhook> = z.lazy(() => _WebhookModel.extend({
|
||||
user: UserModel.nullish(),
|
||||
eventType: EventTypeModel.nullish(),
|
||||
app: AppModel.nullish(),
|
||||
}))
|
||||
|
|
Loading…
Reference in New Issue