Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add GET endpoint to incoming webhooks to return all team links
Cursor Agent6a9f768ff0af
diff --git a/pages/api/webhooks/services/[...path]/index.ts b/pages/api/webhooks/services/[...path]/index.tsindex 01775aa4..4758fa04 100644--- a/pages/api/webhooks/services/[...path]/index.ts+++ b/pages/api/webhooks/services/[...path]/index.ts@@ -117,7 +117,7 @@ export default async function incomingWebhookHandler(req: NextApiRequest,res: NextApiResponse,) {- if (req.method !== "POST") {+ if (req.method !== "POST" && req.method !== "GET") {return res.status(405).json({ error: "Method not allowed" });}@@ -203,6 +203,12 @@ export default async function incomingWebhookHandler(return res.status(404).json({ error: "Webhook not found" });}+ // Handle GET requests – return all links for the team+ if (req.method === "GET") {+ return await handleGetTeamLinks(incomingWebhook.teamId, res);+ }++ // Handle POST requests// Validate request body against the schemaconst validationResult = RequestBodySchema.safeParse(req.body);if (!validationResult.success) {@@ -253,6 +259,61 @@ export default async function incomingWebhookHandler(}}+/**+ * Handle GET request – return all links for the team+ */+async function handleGetTeamLinks(teamId: string, res: NextApiResponse) {+ try {+ const links = await prisma.link.findMany({+ where: {+ teamId,+ deletedAt: null,+ },+ select: {+ id: true,+ name: true,+ linkType: true,+ documentId: true,+ dataroomId: true,+ url: true,+ slug: true,+ domainSlug: true,+ expiresAt: true,+ isArchived: true,+ createdAt: true,+ updatedAt: true,+ },+ orderBy: {+ createdAt: "desc",+ },+ });++ const transformedLinks = links.map((link) => ({+ linkId: link.id,+ name: link.name,+ linkType: link.linkType,+ documentId: link.documentId ?? null,+ dataroomId: link.dataroomId ?? null,+ url: link.url,+ slug: link.slug,+ domainSlug: link.domainSlug,+ expiresAt: link.expiresAt,+ isArchived: link.isArchived,+ createdAt: link.createdAt,+ updatedAt: link.updatedAt,+ linkUrl:+ link.domainSlug && link.slug+ ? `https://${link.domainSlug}/${link.slug}`+ : `${process.env.NEXT_PUBLIC_MARKETING_URL}/view/${link.id}`,+ }));++ return res.status(200).json(transformedLinks);+ } catch (error) {+ console.error("Error fetching team links:", error);+ return res.status(500).json({ error: "Failed to fetch team links" });+ }+}+/*** Handle document.create resource type*/