Skip to content
Snippets Groups Projects
Commit 88fa95d5 authored by Alexandros Georgantas's avatar Alexandros Georgantas
Browse files

Merge branch 'users-pagination' into 'graphql-api'

Paginate users query result

See merge request !26
parents fafdcf16 d36d4449
No related branches found
No related tags found
3 merge requests!52Docx,!26Paginate users query result,!17Graphql api
...@@ -83,7 +83,7 @@ const getUser = async (id, options = {}) => { ...@@ -83,7 +83,7 @@ const getUser = async (id, options = {}) => {
const getDisplayName = async user => user.getDisplayName() const getDisplayName = async user => user.getDisplayName()
const getUsers = async (options = {}) => { const getUsers = async (queryParams = {}, options = {}) => {
try { try {
const { trx, ...restOptions } = options const { trx, ...restOptions } = options
return useTransaction( return useTransaction(
...@@ -91,7 +91,7 @@ const getUsers = async (options = {}) => { ...@@ -91,7 +91,7 @@ const getUsers = async (options = {}) => {
logger.info( logger.info(
`${USER_CONTROLLER} getUsers: fetching all users based on provided options ${restOptions}`, `${USER_CONTROLLER} getUsers: fetching all users based on provided options ${restOptions}`,
) )
return User.find({}, { trx: tr, ...restOptions }) return User.find(queryParams, { trx: tr, ...restOptions })
}, },
{ trx, passedTrxOnly: true }, { trx, passedTrxOnly: true },
) )
......
...@@ -3,7 +3,7 @@ scalar DateTime ...@@ -3,7 +3,7 @@ scalar DateTime
# find a better place to inject that # find a better place to inject that
input PageInput { input PageInput {
pageSize: Int! pageSize: Int!
pageNumber: Int! page: Int!
} }
# #
type User { type User {
...@@ -68,9 +68,13 @@ input UpdatePasswordInput { ...@@ -68,9 +68,13 @@ input UpdatePasswordInput {
newPassword: String! newPassword: String!
} }
input UsersQueryParams {
isActive: Boolean
}
extend type Query { extend type Query {
user(id: ID): User user(id: ID): User
users: Users! users(queryParams: UsersQueryParams, options: PageInput): Users!
currentUser: User! currentUser: User!
} }
......
...@@ -38,10 +38,10 @@ const userResolver = async (_, { id }, ctx) => { ...@@ -38,10 +38,10 @@ const userResolver = async (_, { id }, ctx) => {
} }
} }
const usersResolver = async (_, args, ctx) => { const usersResolver = async (_, { queryParams, options }, ctx) => {
try { try {
logger.error(`${USER_RESOLVER} users`) logger.error(`${USER_RESOLVER} users`)
return getUsers() return getUsers(queryParams, options)
} catch (e) { } catch (e) {
logger.error(`${USER_RESOLVER} users: ${e.message}`) logger.error(`${USER_RESOLVER} users: ${e.message}`)
throw new Error(e) throw new Error(e)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment