@@ -107,12 +107,26 @@ export default async function incomingWebhookHandler(
107
107
}
108
108
109
109
// 3. Validate request body
110
- const { fileUrl, name, contentType } = req . body ;
110
+ const { fileUrl, name, contentType, dataroomId } = req . body ;
111
111
112
112
if ( ! fileUrl ) {
113
113
return res . status ( 400 ) . json ( { error : "File URL is required" } ) ;
114
114
}
115
115
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
+
116
130
// Check if the content type is supported
117
131
const supportedContentType = getSupportedContentType ( contentType ) ;
118
132
if ( ! supportedContentType ) {
@@ -171,9 +185,22 @@ export default async function incomingWebhookHandler(
171
185
172
186
const document = await documentCreationResponse . json ( ) ;
173
187
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
+
174
198
return res . status ( 200 ) . json ( {
175
- message : "Document created successfully" ,
199
+ message : `Document created successfully${
200
+ dataroomId ? ` and added to dataroom` : ""
201
+ } `,
176
202
documentId : document . id ,
203
+ dataroomId : dataroomId ?? undefined ,
177
204
} ) ;
178
205
} catch ( error ) {
179
206
console . error ( "Webhook error:" , error ) ;
0 commit comments