Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export default async function handle(
dataroomId: dataroomId,
folderId: folder.id,
},
orderBy: {
document: {
name: "asc",
},
},
select: {
id: true,
dataroomId: true,
Expand All @@ -85,11 +90,24 @@ export default async function handle(
},
},
},
orderBy: {
document: {
name: "asc",
},
},
});

// Sort documents by name considering the numerical part
documents.sort((a, b) => {
const getNumber = (str: string): number => {
const match = str.match(/^\d+/);
return match ? parseInt(match[0], 10) : 0;
};

const numA = getNumber(a.document.name);
const numB = getNumber(b.document.name);

if (numA !== numB) {
return numA - numB;
}

// If numerical parts are the same, fall back to lexicographical order
return a.document.name.localeCompare(b.document.name);
});

return res.status(200).json(documents);
Expand Down