Adds missing webhook user relationship (#1070)
parent
5291dade42
commit
cc25a772a1
|
@ -147,6 +147,9 @@
|
|||
"./{*,{ee,pages,components,lib}/**/*}.{js,ts,jsx,tsx}": [
|
||||
"prettier --write",
|
||||
"eslint"
|
||||
],
|
||||
"./prisma/schema.prisma": [
|
||||
"prisma format"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
-- AddForeignKey
|
||||
ALTER TABLE "Webhook" ADD FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@ -45,6 +45,7 @@ model EventType {
|
|||
Schedule Schedule[]
|
||||
price Int @default(0)
|
||||
currency String @default("usd")
|
||||
|
||||
@@unique([userId, slug])
|
||||
}
|
||||
|
||||
|
@ -89,10 +90,9 @@ model User {
|
|||
locale String?
|
||||
twoFactorSecret String?
|
||||
twoFactorEnabled Boolean @default(false)
|
||||
|
||||
|
||||
plan UserPlan @default(PRO)
|
||||
Schedule Schedule[]
|
||||
webhooks Webhook[]
|
||||
|
||||
@@map(name: "users")
|
||||
}
|
||||
|
@ -293,10 +293,11 @@ enum WebhookTriggerEvents {
|
|||
}
|
||||
|
||||
model Webhook {
|
||||
id String @unique @id
|
||||
id String @id @unique
|
||||
userId Int
|
||||
subscriberUrl String
|
||||
createdAt DateTime @default(now())
|
||||
active Boolean @default(true)
|
||||
eventTriggers WebhookTriggerEvents[]
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
}
|
||||
|
|
|
@ -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: ctx.user.id,
|
||||
},
|
||||
data: {
|
||||
webhooks: {
|
||||
delete: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
if (!webhook) {
|
||||
// user does not own this webhook
|
||||
return null;
|
||||
}
|
||||
await ctx.prisma.webhook.delete({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
id,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue