Skip to content

Commit 811ef58

Browse files
authored
Merge pull request #1399 from mfts/feat/extend-webhooks
feat: add dataroomId to add new document to dataroom automatically
2 parents 5636e98 + 073e39a commit 811ef58

File tree

1 file changed

+29
-2
lines changed
  • pages/api/webhooks/services/[...path]

1 file changed

+29
-2
lines changed

pages/api/webhooks/services/[...path]/index.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,26 @@ export default async function incomingWebhookHandler(
107107
}
108108

109109
// 3. Validate request body
110-
const { fileUrl, name, contentType } = req.body;
110+
const { fileUrl, name, contentType, dataroomId } = req.body;
111111

112112
if (!fileUrl) {
113113
return res.status(400).json({ error: "File URL is required" });
114114
}
115115

116+
if (dataroomId) {
117+
// Verify dataroom exists and belongs to team
118+
const dataroom = await prisma.dataroom.findUnique({
119+
where: {
120+
id: dataroomId,
121+
teamId: incomingWebhook.teamId,
122+
},
123+
});
124+
125+
if (!dataroom) {
126+
return res.status(400).json({ error: "Invalid dataroom ID" });
127+
}
128+
}
129+
116130
// Check if the content type is supported
117131
const supportedContentType = getSupportedContentType(contentType);
118132
if (!supportedContentType) {
@@ -171,9 +185,22 @@ export default async function incomingWebhookHandler(
171185

172186
const document = await documentCreationResponse.json();
173187

188+
// If dataroomId was provided, create the relationship
189+
if (dataroomId) {
190+
await prisma.dataroomDocument.create({
191+
data: {
192+
dataroomId,
193+
documentId: document.id,
194+
},
195+
});
196+
}
197+
174198
return res.status(200).json({
175-
message: "Document created successfully",
199+
message: `Document created successfully${
200+
dataroomId ? ` and added to dataroom` : ""
201+
}`,
176202
documentId: document.id,
203+
dataroomId: dataroomId ?? undefined,
177204
});
178205
} catch (error) {
179206
console.error("Webhook error:", error);

0 commit comments

Comments
 (0)