Revert "Revert "Webhooks to support event type association"" (#2033)
* Revert "Revert "Webhooks to support event type association (#1889)" (#2032)"
This reverts commit 71e74b8320.
* Fixes turbo DB deploy
* Update turbo.json
This commit is contained in:
1 parent
c93e8774c9
commit
382d56ab54
17 files changed
+1453
-1175
No files matched your search
@@ -0,0 +1,6 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Webhook" ADD COLUMN "eventTypeId" INTEGER,
|
||||
ALTER COLUMN "userId" DROP NOT NULL;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Webhook" ADD CONSTRAINT "Webhook_eventTypeId_fkey" FOREIGN KEY ("eventTypeId") REFERENCES "EventType"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -46,6 +46,7 @@ model EventType {
|
||||
teamId Int?
|
||||
bookings Booking[]
|
||||
availability Availability[]
|
||||
webhooks Webhook[]
|
||||
destinationCalendar DestinationCalendar?
|
||||
eventName String?
|
||||
customInputs EventTypeCustomInput[]
|
||||
@@ -345,11 +346,13 @@ enum WebhookTriggerEvents {
|
||||
|
||||
model Webhook {
|
||||
id String @id @unique
|
||||
userId Int
|
||||
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)
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
eventType EventType? @relation(fields: [eventTypeId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import * as z from "zod"
|
||||
import * as imports from "../zod-utils"
|
||||
import { PeriodType, SchedulingType } from "@prisma/client"
|
||||
import { CompleteUser, UserModel, CompleteTeam, TeamModel, CompleteBooking, BookingModel, CompleteAvailability, AvailabilityModel, CompleteWebhook, WebhookModel, CompleteDestinationCalendar, DestinationCalendarModel, CompleteEventTypeCustomInput, EventTypeCustomInputModel, CompleteSchedule, ScheduleModel } from "./index"
|
||||
|
||||
// Helper schema for JSON fields
|
||||
type Literal = boolean | number | string
|
||||
type Json = Literal | { [key: string]: Json } | Json[]
|
||||
const literalSchema = z.union([z.string(), z.number(), z.boolean()])
|
||||
const jsonSchema: z.ZodSchema<Json> = z.lazy(() => z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)]))
|
||||
|
||||
export const _EventTypeModel = z.object({
|
||||
id: z.number().int(),
|
||||
title: z.string().nonempty(),
|
||||
slug: imports.eventTypeSlug,
|
||||
description: z.string().nullish(),
|
||||
position: z.number().int(),
|
||||
locations: imports.eventTypeLocations,
|
||||
length: z.number().int(),
|
||||
hidden: z.boolean(),
|
||||
userId: z.number().int().nullish(),
|
||||
teamId: z.number().int().nullish(),
|
||||
eventName: z.string().nullish(),
|
||||
timeZone: z.string().nullish(),
|
||||
periodType: z.nativeEnum(PeriodType),
|
||||
periodStartDate: z.date().nullish(),
|
||||
periodEndDate: z.date().nullish(),
|
||||
periodDays: z.number().int().nullish(),
|
||||
periodCountCalendarDays: z.boolean().nullish(),
|
||||
requiresConfirmation: z.boolean(),
|
||||
disableGuests: z.boolean(),
|
||||
minimumBookingNotice: z.number().int(),
|
||||
schedulingType: z.nativeEnum(SchedulingType).nullish(),
|
||||
price: z.number().int(),
|
||||
currency: z.string(),
|
||||
slotInterval: z.number().int().nullish(),
|
||||
metadata: jsonSchema,
|
||||
})
|
||||
|
||||
export interface CompleteEventType extends z.infer<typeof _EventTypeModel> {
|
||||
users: CompleteUser[]
|
||||
team?: CompleteTeam | null
|
||||
bookings: CompleteBooking[]
|
||||
availability: CompleteAvailability[]
|
||||
webhooks: CompleteWebhook[]
|
||||
destinationCalendar?: CompleteDestinationCalendar | null
|
||||
customInputs: CompleteEventTypeCustomInput[]
|
||||
Schedule: CompleteSchedule[]
|
||||
}
|
||||
|
||||
/**
|
||||
* EventTypeModel contains all relations on your model in addition to the scalars
|
||||
*
|
||||
* NOTE: Lazy required in case of potential circular dependencies within schema
|
||||
*/
|
||||
export const EventTypeModel: z.ZodSchema<CompleteEventType> = z.lazy(() => _EventTypeModel.extend({
|
||||
users: UserModel.array(),
|
||||
team: TeamModel.nullish(),
|
||||
bookings: BookingModel.array(),
|
||||
availability: AvailabilityModel.array(),
|
||||
webhooks: WebhookModel.array(),
|
||||
destinationCalendar: DestinationCalendarModel.nullish(),
|
||||
customInputs: EventTypeCustomInputModel.array(),
|
||||
Schedule: ScheduleModel.array(),
|
||||
}))
|
||||
@@ -0,0 +1,30 @@
|
||||
import * as z from "zod"
|
||||
import * as imports from "../zod-utils"
|
||||
import { WebhookTriggerEvents } from "@prisma/client"
|
||||
import { CompleteUser, UserModel, CompleteEventType, EventTypeModel } from "./index"
|
||||
|
||||
export const _WebhookModel = z.object({
|
||||
id: z.string(),
|
||||
userId: z.number().int().nullish(),
|
||||
eventTypeId: z.number().int().nullish(),
|
||||
subscriberUrl: z.string(),
|
||||
payloadTemplate: z.string().nullish(),
|
||||
createdAt: z.date(),
|
||||
active: z.boolean(),
|
||||
eventTriggers: z.nativeEnum(WebhookTriggerEvents).array(),
|
||||
})
|
||||
|
||||
export interface CompleteWebhook extends z.infer<typeof _WebhookModel> {
|
||||
user?: CompleteUser | null
|
||||
eventType?: CompleteEventType | null
|
||||
}
|
||||
|
||||
/**
|
||||
* WebhookModel contains all relations on your model in addition to the scalars
|
||||
*
|
||||
* NOTE: Lazy required in case of potential circular dependencies within schema
|
||||
*/
|
||||
export const WebhookModel: z.ZodSchema<CompleteWebhook> = z.lazy(() => _WebhookModel.extend({
|
||||
user: UserModel.nullish(),
|
||||
eventType: EventTypeModel.nullish(),
|
||||
}))
|
||||
Reference in new issue
Block a user