Adds missing webhook user relationship (#1070)
This commit is contained in:
parent
5291dade42
commit
cc25a772a1
4 changed files with 63 additions and 58 deletions
|
@ -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"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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[]
|
Schedule Schedule[]
|
||||||
price Int @default(0)
|
price Int @default(0)
|
||||||
currency String @default("usd")
|
currency String @default("usd")
|
||||||
|
|
||||||
@@unique([userId, slug])
|
@@unique([userId, slug])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,10 +90,9 @@ model User {
|
||||||
locale String?
|
locale String?
|
||||||
twoFactorSecret String?
|
twoFactorSecret String?
|
||||||
twoFactorEnabled Boolean @default(false)
|
twoFactorEnabled Boolean @default(false)
|
||||||
|
|
||||||
|
|
||||||
plan UserPlan @default(PRO)
|
plan UserPlan @default(PRO)
|
||||||
Schedule Schedule[]
|
Schedule Schedule[]
|
||||||
|
webhooks Webhook[]
|
||||||
|
|
||||||
@@map(name: "users")
|
@@map(name: "users")
|
||||||
}
|
}
|
||||||
|
@ -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])
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
webhooks: {
|
||||||
|
delete: {
|
||||||
id,
|
id,
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
if (!webhook) {
|
|
||||||
// user does not own this webhook
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
await ctx.prisma.webhook.delete({
|
|
||||||
where: {
|
|
||||||
id,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue