feat: Convert helpers to use JS files

This commit is contained in:
Faruk AYDIN
2024-01-04 19:55:41 +01:00
parent 8819ddefa7
commit 85141812d9
48 changed files with 259 additions and 384 deletions

View 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;