Skip to content

Commit

Permalink
Merge pull request #122 from osstotalsoft/fix/MissingCursorPaginationFnc
Browse files Browse the repository at this point in the history
add missing function
  • Loading branch information
alexandra-c authored Sep 20, 2023
2 parents dc3e93c + c52dc9d commit 68a920d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion generators/app/templates/infrastructure/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": ["eslint:recommended", "plugin:node/recommended", "plugin:jest/recommended"],
"extends": ["eslint:recommended", "plugin:node/recommended", "plugin:jest/recommended", "plugin:import/recommended"],
"parserOptions": {
// Only ESLint 6.2.0 and later support ES2020.
"ecmaVersion": 2020
Expand Down
1 change: 1 addition & 0 deletions generators/app/templates/infrastructure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
"@graphql-eslint/eslint-plugin": "^3.16.0",
"cross-env": "7.0.3",
"eslint": "^8.35.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-node": "^11.1.0",
"graphql-schema-linter": "^3.0.1",
Expand Down
20 changes: 20 additions & 0 deletions generators/app/templates/infrastructure/src/prisma/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
function cursorPaginationOptions(pager, direction = pager?.direction || 1) {
const { afterId, pageSize, sortBy = 'name' } = pager
const options = afterId
? {
skip: 1,
cursor: {
id: afterId
}
}
: {}

return {
...options,
take: pageSize,
orderBy: {
[sortBy]: direction ? 'asc' : 'desc'
}
}
}

/**
*
* @param prismaModel Prisma queried model
Expand Down

0 comments on commit 68a920d

Please sign in to comment.