Skip to content

Commit

Permalink
chore: keep the listUsers as deprecated and added listUserPaginated
Browse files Browse the repository at this point in the history
  • Loading branch information
arturmagalhaesjr committed May 9, 2022
1 parent 4b6b67a commit 51e71a7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
7 changes: 6 additions & 1 deletion graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ type Query {
# User
getUser(id: ID!): User @cacheControl(scope: PRIVATE)
getUserByEmail(email: String!): User @cacheControl(scope: PRIVATE)
listUsers(organizationId: ID, costCenterId: ID, roleId: ID): [User]
@cacheControl(scope: PRIVATE, maxAge: SHORT)
@deprecated(
reason: "This query is deprecated, use listUsersPaginated query instead."
)

listUsers(
listUsersPaginated(
organizationId: ID
costCenterId: ID
roleId: ID
Expand Down
58 changes: 56 additions & 2 deletions node/resolvers/Queries/Users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,62 @@ export const getUserByEmail = async (_: any, params: any, ctx: Context) => {
}

export const listUsers = async (
_: any,
{
organizationId = '',
costCenterId = '',
roleId = '',
}: { organizationId: string; costCenterId: string; roleId: string },
ctx: Context
) => {
const {
clients: { masterdata },
} = ctx

let res: any = []

const whereArray: string[] = []

if (organizationId) {
whereArray.push(`orgId=${organizationId}`)
}

if (costCenterId) {
whereArray.push(`costId=${costCenterId}`)
}

if (roleId) {
whereArray.push(`roleId=${roleId}`)
}

const where = whereArray.join(' AND ')

try {
res = await masterdata.searchDocuments({
dataEntity: config.name,
fields: [
'id',
'roleId',
'userId',
'clId',
'orgId',
'costId',
'name',
'email',
'canImpersonate',
],
schema: config.version,
pagination: { page: 1, pageSize: 50 },
...(where && { where }),
})

return res
} catch (e) {
return { status: 'error', message: e }
}
}

export const listUsersPaginated = async (
_: any,
{
organizationId = '',
Expand Down Expand Up @@ -243,8 +299,6 @@ export const listUsers = async (

return res
} catch (e) {
console.error(e)

return { status: 'error', message: e }
}
}
Expand Down
2 changes: 2 additions & 0 deletions node/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
getUser,
getUserByEmail,
listUsers,
listUsersPaginated,
} from './Queries/Users'
import { Routes } from './Routes'

Expand Down Expand Up @@ -46,6 +47,7 @@ export const resolvers = {
listFeatures,
listRoles,
listUsers,
listUsersPaginated,
},
Routes,
}

0 comments on commit 51e71a7

Please sign in to comment.