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

View File

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