feat: Convert helpers to use JS files
This commit is contained in:
23
packages/backend/src/helpers/pagination.js
Normal file
23
packages/backend/src/helpers/pagination.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const paginate = async (query, limit, offset) => {
|
||||
if (limit < 1 || limit > 100) {
|
||||
throw new Error('Limit must be between 1 and 100');
|
||||
}
|
||||
|
||||
const [records, count] = await Promise.all([
|
||||
query.limit(limit).offset(offset),
|
||||
query.resultSize(),
|
||||
]);
|
||||
|
||||
return {
|
||||
pageInfo: {
|
||||
currentPage: Math.ceil(offset / limit + 1),
|
||||
totalPages: Math.ceil(count / limit),
|
||||
},
|
||||
totalCount: count,
|
||||
edges: records.map((record) => ({
|
||||
node: record,
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
||||
export default paginate;
|
Reference in New Issue
Block a user