Adds missing webhook user relationship (#1070)

pull/1077/head
Omar López 2021-10-29 08:13:51 -06:00 committed by GitHub
parent 5291dade42
commit cc25a772a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 58 deletions

View File

@ -147,6 +147,9 @@
"./{*,{ee,pages,components,lib}/**/*}.{js,ts,jsx,tsx}": [ "./{*,{ee,pages,components,lib}/**/*}.{js,ts,jsx,tsx}": [
"prettier --write", "prettier --write",
"eslint" "eslint"
],
"./prisma/schema.prisma": [
"prisma format"
] ]
} }
} }

View File

@ -0,0 +1,2 @@
-- AddForeignKey
ALTER TABLE "Webhook" ADD FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -7,13 +7,13 @@ datasource db {
} }
generator client { generator client {
provider = "prisma-client-js" provider = "prisma-client-js"
previewFeatures = ["selectRelationCount"] previewFeatures = ["selectRelationCount"]
} }
enum SchedulingType { enum SchedulingType {
ROUND_ROBIN @map("roundRobin") ROUND_ROBIN @map("roundRobin")
COLLECTIVE @map("collective") COLLECTIVE @map("collective")
} }
model EventType { model EventType {
@ -33,7 +33,7 @@ model EventType {
eventName String? eventName String?
customInputs EventTypeCustomInput[] customInputs EventTypeCustomInput[]
timeZone String? timeZone String?
periodType String @default("unlimited") // unlimited | rolling | range periodType String @default("unlimited") // unlimited | rolling | range
periodStartDate DateTime? periodStartDate DateTime?
periodEndDate DateTime? periodEndDate DateTime?
periodDays Int? periodDays Int?
@ -45,6 +45,7 @@ model EventType {
Schedule Schedule[] Schedule Schedule[]
price Int @default(0) price Int @default(0)
currency String @default("usd") currency String @default("usd")
@@unique([userId, slug]) @@unique([userId, slug])
} }
@ -86,26 +87,25 @@ model User {
availability Availability[] availability Availability[]
selectedCalendars SelectedCalendar[] selectedCalendars SelectedCalendar[]
completedOnboarding Boolean @default(false) completedOnboarding Boolean @default(false)
locale String? locale String?
twoFactorSecret String? twoFactorSecret String?
twoFactorEnabled Boolean @default(false) twoFactorEnabled Boolean @default(false)
plan UserPlan @default(PRO)
Schedule Schedule[]
plan UserPlan @default(PRO) webhooks Webhook[]
Schedule Schedule[]
@@map(name: "users") @@map(name: "users")
} }
model Team { model Team {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
name String? name String?
slug String? @unique slug String? @unique
logo String? logo String?
bio String? bio String?
hideBranding Boolean @default(false) hideBranding Boolean @default(false)
members Membership[] members Membership[]
eventTypes EventType[] eventTypes EventType[]
} }
enum MembershipRole { enum MembershipRole {
@ -156,17 +156,17 @@ model Attendee {
} }
enum BookingStatus { enum BookingStatus {
CANCELLED @map("cancelled") CANCELLED @map("cancelled")
ACCEPTED @map("accepted") ACCEPTED @map("accepted")
REJECTED @map("rejected") REJECTED @map("rejected")
PENDING @map("pending") PENDING @map("pending")
} }
model DailyEventReference { model DailyEventReference {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
dailyurl String @default("dailycallurl") dailyurl String @default("dailycallurl")
dailytoken String @default("dailytoken") dailytoken String @default("dailytoken")
booking Booking? @relation(fields: [bookingId], references: [id]) booking Booking? @relation(fields: [bookingId], references: [id])
bookingId Int? bookingId Int?
} }
@ -187,14 +187,14 @@ model Booking {
attendees Attendee[] attendees Attendee[]
location String? location String?
dailyRef DailyEventReference? dailyRef DailyEventReference?
createdAt DateTime @default(now()) createdAt DateTime @default(now())
updatedAt DateTime? updatedAt DateTime?
confirmed Boolean @default(true) confirmed Boolean @default(true)
rejected Boolean @default(false) rejected Boolean @default(false)
status BookingStatus @default(ACCEPTED) status BookingStatus @default(ACCEPTED)
paid Boolean @default(false) paid Boolean @default(false)
payment Payment[] payment Payment[]
} }
@ -272,18 +272,18 @@ enum PaymentType {
} }
model Payment { model Payment {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
uid String @unique uid String @unique
type PaymentType type PaymentType
bookingId Int bookingId Int
booking Booking? @relation(fields: [bookingId], references: [id]) booking Booking? @relation(fields: [bookingId], references: [id])
amount Int amount Int
fee Int fee Int
currency String currency String
success Boolean success Boolean
refunded Boolean refunded Boolean
data Json data Json
externalId String @unique externalId String @unique
} }
enum WebhookTriggerEvents { enum WebhookTriggerEvents {
@ -293,10 +293,11 @@ enum WebhookTriggerEvents {
} }
model Webhook { model Webhook {
id String @unique @id id String @id @unique
userId Int userId Int
subscriberUrl String subscriberUrl String
createdAt DateTime @default(now()) createdAt DateTime @default(now())
active Boolean @default(true) active Boolean @default(true)
eventTriggers WebhookTriggerEvents[] eventTriggers WebhookTriggerEvents[]
user User @relation(fields: [userId], references: [id])
} }

View File

@ -65,21 +65,20 @@ export const webhookRouter = createProtectedRouter()
}), }),
async resolve({ ctx, input }) { async resolve({ ctx, input }) {
const { id } = input; const { id } = input;
const webhook = await ctx.prisma.webhook.findFirst({
await ctx.prisma.user.update({
where: { where: {
userId: ctx.user.id, id: ctx.user.id,
id, },
}, data: {
}); webhooks: {
if (!webhook) { delete: {
// user does not own this webhook id,
return null; },
} },
await ctx.prisma.webhook.delete({
where: {
id,
}, },
}); });
return { return {
id, id,
}; };