Use skip/take cursors instead of page number

This commit is contained in:
jeffvli
2022-07-30 15:28:30 -07:00
parent b8cf1d8283
commit aa673ac854
15 changed files with 154 additions and 132 deletions
+5 -7
View File
@@ -35,7 +35,7 @@ const findMany = async (
req: Request,
options: { serverFolderIds: string; user: User } & OffsetPagination
) => {
const { user, limit, page, serverFolderIds: rServerFolderIds } = options;
const { user, skip, take, serverFolderIds: rServerFolderIds } = options;
const serverFolderIds = splitNumberString(rServerFolderIds);
if (!(await folderPermissions(serverFolderIds!, user))) {
@@ -52,23 +52,21 @@ const findMany = async (
};
});
const startIndex = limit * page;
const totalEntries = await prisma.artist.count({
where: { OR: serverFoldersFilter },
});
const artists = await prisma.artist.findMany({
include: { genres: true },
skip: startIndex,
take: limit,
skip,
take,
where: { OR: serverFoldersFilter },
});
return ApiSuccess.ok({
data: artists,
paginationItems: {
limit,
page,
startIndex,
skip,
take,
totalEntries,
url: req.originalUrl,
},