Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: delete convo endpoint
Marc Seitzc6bc33228f04
diff --git a/ee/features/conversations/api/team-conversations-route.ts b/ee/features/conversations/api/team-conversations-route.tsindex 18e600a8..1764e1fa 100644--- a/ee/features/conversations/api/team-conversations-route.ts+++ b/ee/features/conversations/api/team-conversations-route.ts@@ -631,6 +631,69 @@ const routeHandlers = {return res.status(500).json({ error: "Internal server error" });}},++ // DELETE /api/teams/[teamId]/datarooms/[dataroomId]/conversations/[conversationId]+ "DELETE /[conversationId]": async (+ req: NextApiRequest,+ res: NextApiResponse,+ ) => {+ const session = await getServerSession(req, res, authOptions);+ if (!session) {+ return res.status(401).json({ error: "Unauthorized" });+ }++ const {+ teamId,+ id: dataroomId,+ conversations: [conversationId],+ } = req.query as {+ teamId: string;+ id: string;+ conversations: string[];+ };++ const userId = (session.user as CustomUser).id;++ try {+ // Verify user has access to the dataroom+ const dataroom = await prisma.dataroom.findUnique({+ where: {+ id: dataroomId,+ team: {+ id: teamId,+ users: { some: { userId } },+ },+ },+ });++ if (!dataroom) {+ return res.status(404).json({ error: "Dataroom not found" });+ }++ // Delete the conversation using the service+ await conversationService.deleteConversation(+ conversationId,+ userId,+ dataroomId,+ teamId,+ );++ return res.status(200).json({ success: true });+ } catch (error) {+ console.error("Error deleting conversation:", error);+ if (error instanceof Error) {+ if (error.message === "Conversation not found") {+ return res.status(404).json({ error: "Conversation not found" });+ }+ if (error.message === "Unauthorized to delete this conversation") {+ return res+ .status(403)+ .json({ error: "Unauthorized to delete this conversation" });+ }+ }+ return res.status(500).json({ error: "Internal server error" });+ }+ },};// Main handler that will be imported by the catchall routediff --git a/ee/features/conversations/lib/api/conversations/index.ts b/ee/features/conversations/lib/api/conversations/index.tsindex df86538c..2c5a8074 100644--- a/ee/features/conversations/lib/api/conversations/index.ts+++ b/ee/features/conversations/lib/api/conversations/index.ts@@ -296,4 +296,45 @@ export const conversationService = {return { success: true, markedCount: conversation.messages.length };},++ // Delete a conversation and all related data+ async deleteConversation(+ conversationId: string,+ userId: string,+ dataroomId: string,+ teamId: string,+ ) {+ // First verify the conversation exists and user has access+ const conversation = await prisma.conversation.findUnique({+ where: {+ id: conversationId,+ dataroomId,+ teamId,+ team: { users: { some: { userId } } },+ },+ include: {+ team: {+ include: {+ users: true,+ },+ },+ },+ });++ if (!conversation) {+ throw new Error("Conversation not found");+ }++ // Check if user has access to this conversation's dataroom+ if (conversation.team.users.length === 0) {+ throw new Error("Unauthorized to delete this conversation");+ }++ // Delete the conversation (cascade will handle related data like messages, participants, etc.)+ await prisma.conversation.delete({+ where: { id: conversationId },+ });++ return { success: true };+ },};