Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: sort datarooms in database

Marc Seitz4a7379f3c9c1
diff --git a/components/sidebar/app-sidebar.tsx b/components/sidebar/app-sidebar.tsx
index 0b6c0dcf..5b72d6f0 100644
--- a/components/sidebar/app-sidebar.tsx
+++ b/components/sidebar/app-sidebar.tsx
@@ -95,19 +95,13 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
// Prepare datarooms items for sidebar (limit to first 5, sorted by most recent)
const dataroomItems =
datarooms && datarooms.length > 0
- ? datarooms
- .sort(
- (a, b) =>
- new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(),
- )
- .slice(0, 5)
- .map((dataroom) => ({
- title: dataroom.name,
- url: `/datarooms/${dataroom.id}/documents`,
- current:
- router.pathname.includes("/datarooms/[id]") &&
- String(router.query.id) === String(dataroom.id),
- }))
+ ? datarooms.slice(0, 5).map((dataroom) => ({
+ title: dataroom.name,
+ url: `/datarooms/${dataroom.id}/documents`,
+ current:
+ router.pathname.includes("/datarooms/[id]") &&
+ String(router.query.id) === String(dataroom.id),
+ }))
: undefined;
const data = {
diff --git a/pages/api/teams/[teamId]/datarooms/index.ts b/pages/api/teams/[teamId]/datarooms/index.ts
index ba0cfa3d..2578670f 100644
--- a/pages/api/teams/[teamId]/datarooms/index.ts
+++ b/pages/api/teams/[teamId]/datarooms/index.ts
@@ -24,22 +24,23 @@ export default async function handle(
const { teamId } = req.query as { teamId: string };
try {
- // Check if the user is part of the team
- const team = await prisma.team.findUnique({
+ const teamAccess = await prisma.userTeam.findUnique({
where: {
- id: teamId,
- users: {
- some: {
- userId: userId,
- },
+ userId_teamId: {
+ userId: userId,
+ teamId: teamId,
},
},
+ select: {
+ teamId: true,
+ },
});
- if (!team) {
+ if (!teamAccess) {
return res.status(401).end("Unauthorized");
}
+ // Check if the user is part of the team
const datarooms = await prisma.dataroom.findMany({
where: {
teamId: teamId,
@@ -72,6 +73,9 @@ export default async function handle(
},
},
},
+ orderBy: {
+ createdAt: "desc",
+ },
});
return res.status(200).json(datarooms);