mirror of
https://github.com/hanzo-apps/dataroom.git
synced 2026-10-30 14:47:36 +00:00
When a dataroom link has file requests enabled and notifications turned on, the team (admin, managers, link owner) receives an email notification when a visitor uploads documents to the dataroom. Uses the same delayed trigger strategy as existing new document notifications: - Cancels any pending notification for the same dataroom+link - Triggers a new notification with a 5-minute delay - The trigger task collects all uploads in that window and sends a single email Components: - Trigger.dev task: send-dataroom-upload-notification (5-min batched) - Email template: DataroomUploadNotification - API endpoint: /api/jobs/send-dataroom-upload-notification - Modified upload route to trigger notification when link.enableNotification is on Co-authored-by: Marc Seitz <[email protected]>
70 lines
1.5 KiB
TypeScript
70 lines
1.5 KiB
TypeScript
import { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
import { sendDataroomUploadNotification } from "@/lib/emails/send-dataroom-upload-notification";
|
|
import { log } from "@/lib/utils";
|
|
|
|
export const config = {
|
|
maxDuration: 120,
|
|
};
|
|
|
|
export default async function handle(
|
|
req: NextApiRequest,
|
|
res: NextApiResponse,
|
|
) {
|
|
if (req.method !== "POST") {
|
|
res.status(405).json({ message: "Method Not Allowed" });
|
|
return;
|
|
}
|
|
|
|
const authHeader = req.headers.authorization;
|
|
const token = authHeader?.split(" ")[1];
|
|
|
|
if (token !== process.env.INTERNAL_API_KEY) {
|
|
res.status(401).json({ message: "Unauthorized" });
|
|
return;
|
|
}
|
|
|
|
const {
|
|
dataroomId,
|
|
dataroomName,
|
|
uploaderEmail,
|
|
documentNames,
|
|
linkName,
|
|
ownerEmail,
|
|
teamMembers,
|
|
} = req.body as {
|
|
dataroomId: string;
|
|
dataroomName: string;
|
|
uploaderEmail: string | null;
|
|
documentNames: string[];
|
|
linkName: string;
|
|
ownerEmail: string;
|
|
teamMembers: string[];
|
|
teamId: string;
|
|
};
|
|
|
|
try {
|
|
await sendDataroomUploadNotification({
|
|
ownerEmail,
|
|
dataroomId,
|
|
dataroomName,
|
|
uploaderEmail,
|
|
documentNames,
|
|
linkName,
|
|
teamMembers,
|
|
});
|
|
|
|
res.status(200).json({
|
|
message: "Successfully sent dataroom upload notification",
|
|
});
|
|
return;
|
|
} catch (error) {
|
|
log({
|
|
message: `Failed to send dataroom upload notification for dataroom ${dataroomId}. \n\n Error: ${error}`,
|
|
type: "error",
|
|
mention: true,
|
|
});
|
|
return res.status(500).json({ message: (error as Error).message });
|
|
}
|
|
}
|