chore: Remove old pagination helper for GraphQL

This commit is contained in:
Faruk AYDIN
2025-03-20 15:37:08 +01:00
parent 82dd79e106
commit d1d8cc9e4b
8 changed files with 18 additions and 41 deletions

View File

@@ -1,25 +0,0 @@
const paginateRest = async (query, page) => {
const pageSize = 10;
page = parseInt(page, 10);
if (isNaN(page) || page < 1) {
page = 1;
}
const [records, count] = await Promise.all([
query.limit(pageSize).offset((page - 1) * pageSize),
query.resultSize(),
]);
return {
pageInfo: {
currentPage: page,
totalPages: Math.ceil(count / pageSize),
},
totalCount: count,
records,
};
};
export default paginateRest;

View File

@@ -1,23 +1,25 @@
const paginate = async (query, limit, offset) => {
if (limit < 1 || limit > 100) {
throw new Error('Limit must be between 1 and 100');
const paginateRest = async (query, page) => {
const pageSize = 10;
page = parseInt(page, 10);
if (isNaN(page) || page < 1) {
page = 1;
}
const [records, count] = await Promise.all([
query.limit(limit).offset(offset),
query.limit(pageSize).offset((page - 1) * pageSize),
query.resultSize(),
]);
return {
pageInfo: {
currentPage: Math.ceil(offset / limit + 1),
totalPages: Math.ceil(count / limit),
currentPage: page,
totalPages: Math.ceil(count / pageSize),
},
totalCount: count,
edges: records.map((record) => ({
node: record,
})),
records,
};
};
export default paginate;
export default paginateRest;