Skip to content

Commit

Permalink
Merge pull request #46 from vtex-apps/feature/add-list-allUsers
Browse files Browse the repository at this point in the history
[B2BORG-29] Highlight organizations without sales managers assigned
  • Loading branch information
arturmagalhaesjr authored May 31, 2022
2 parents 4c4f537 + 095545d commit cf0ec4d
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.idea
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

- Added a graphql query to get all users by using the scroll MD function

## [1.19.0] - 2022-05-09

### Added
Expand Down
2 changes: 2 additions & 0 deletions graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type Query {
# User
getUser(id: ID!): User @cacheControl(scope: PRIVATE)
getUserByEmail(email: String!): User @cacheControl(scope: PRIVATE)
listAllUsers: [User] @cacheControl(scope: PRIVATE, maxAge: SHORT)

listUsers(organizationId: ID, costCenterId: ID, roleId: ID): [User]
@cacheControl(scope: PRIVATE, maxAge: SHORT)
@deprecated(
Expand Down
4 changes: 2 additions & 2 deletions node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vtex.checkout-ui-custom",
"version": "1.19.0",
"dependencies": {
"@vtex/api": "6.45.11-beta",
"@vtex/api": "6.45.12",
"co-body": "^6.0.0",
"jsonwebtoken": "^8.5.0",
"qs": "^6.9.4",
Expand All @@ -22,7 +22,7 @@
"@types/jsonwebtoken": "^8.5.0",
"@types/node": "^12.0.0",
"@types/ramda": "types/npm-ramda#dist",
"@vtex/api": "6.45.11-beta",
"@vtex/api": "6.45.12",
"@vtex/prettier-config": "^0.3.1",
"tslint": "^5.12.0",
"tslint-config-prettier": "^1.18.0",
Expand Down
69 changes: 69 additions & 0 deletions node/resolvers/Queries/Users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ import { getAppSettings } from './Settings'

const config: any = currentSchema('b2b_users')

const SCROLL_AWAIT_TIME = 100
const SLEEP_ADD_PERCENTAGE = 0.1
const SCROLL_SIZE = 1000

const sleep = (ms: number) => {
const time = ms + SLEEP_ADD_PERCENTAGE * ms

return new Promise((resolve) => setTimeout(resolve, time))
}

export const getUserById = async (_: any, params: any, ctx: Context) => {
const {
clients: { masterdata },
Expand Down Expand Up @@ -160,6 +170,65 @@ export const getUserByEmail = async (_: any, params: any, ctx: Context) => {
}
}

export const listAllUsers = async (_: any, __: any, ctx: Context) => {
const {
clients: { masterdata },
} = ctx

try {
let token: string | undefined
let hasMore = true
const users = [] as any[]

const scrollMasterData = async () => {
await sleep(SCROLL_AWAIT_TIME)
const {
mdToken,
data,
}: {
mdToken: string
data: any
} = await masterdata.scrollDocuments({
dataEntity: config.name,
fields: [
'id',
'roleId',
'userId',
'clId',
'orgId',
'costId',
'name',
'email',
'canImpersonate',
],
mdToken: token,
schema: config.version,
size: SCROLL_SIZE,
})

if (!data.length && token) {
hasMore = false
}

if (!token && mdToken) {
token = mdToken
}

users.push(...data)

if (hasMore) {
await scrollMasterData()
}
}

await scrollMasterData()

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

export const listUsers = async (
_: any,
{
Expand Down
2 changes: 2 additions & 0 deletions node/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
checkUserPermission,
getUser,
getUserByEmail,
listAllUsers,
listUsers,
listUsersPaginated,
} from './Queries/Users'
Expand All @@ -44,6 +45,7 @@ export const resolvers = {
getUser,
getUserByEmail,
hasUsers,
listAllUsers,
listFeatures,
listRoles,
listUsers,
Expand Down
22 changes: 11 additions & 11 deletions node/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@
"@types/mime" "^1"
"@types/node" "*"

"@vtex/[email protected].11-beta":
version "6.45.11-beta"
resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.45.11-beta.tgz#edc51a2fdd3903f33caf7d63f198005f0d5a0c98"
integrity sha512-BFHMWU4SEFKXpbW3TWj0CI944p9ysmoCtB8ewpQlyRpUZFhPx2On/qFgBrD+Gqwt1yvysuKIAOfzfpjqKy88Gg==
"@vtex/[email protected].12":
version "6.45.12"
resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.45.12.tgz#b13c04398b12f576263ea823369f09c970d57479"
integrity sha512-SVLKo+Q/TxQy+1UKzH8GswTI3F2OCRCLfgaNQOrVAVdbM6Ci4wzTeX8j/S4Q1aEEnqBFlH/wVpHf8I6NBa+g9A==
dependencies:
"@types/koa" "^2.11.0"
"@types/koa-compose" "^3.2.3"
Expand All @@ -214,7 +214,7 @@
graphql "^14.5.8"
graphql-tools "^4.0.6"
graphql-upload "^8.1.0"
jaeger-client "^3.19.0"
jaeger-client "^3.18.0"
js-base64 "^2.5.1"
koa "^2.11.0"
koa-compose "^4.1.0"
Expand All @@ -224,7 +224,7 @@
mime-types "^2.1.12"
opentracing "^0.14.4"
p-limit "^2.2.0"
prom-client "^14.0.1"
prom-client "^12.0.0"
qs "^6.5.1"
querystring "^0.2.0"
ramda "^0.26.0"
Expand Down Expand Up @@ -971,7 +971,7 @@ iterall@^1.1.3, iterall@^1.2.2:
resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.3.0.tgz#afcb08492e2915cbd8a0884eb93a8c94d0d72fea"
integrity sha512-QZ9qOMdF+QLHxy1QIpUHUU1D5pS2CG2P69LF6L6CPjPYA/XMOmKV3PZpawHoAjHNyB0swdVTRxdYT4tbBbxqwg==

jaeger-client@^3.19.0:
jaeger-client@^3.18.0:
version "3.19.0"
resolved "https://registry.yarnpkg.com/jaeger-client/-/jaeger-client-3.19.0.tgz#9b5bd818ebd24e818616ee0f5cffe1722a53ae6e"
integrity sha512-M0c7cKHmdyEUtjemnJyx/y9uX16XHocL46yQvyqDlPdvAcwPDbHrIbKjQdBqtiE4apQ/9dmr+ZLJYYPGnurgpw==
Expand Down Expand Up @@ -1356,10 +1356,10 @@ process@^0.10.0:
resolved "https://registry.yarnpkg.com/process/-/process-0.10.1.tgz#842457cc51cfed72dc775afeeafb8c6034372725"
integrity sha1-hCRXzFHP7XLcd1r+6vuMYDQ3JyU=

prom-client@^14.0.1:
version "14.0.1"
resolved "https://registry.yarnpkg.com/prom-client/-/prom-client-14.0.1.tgz#bdd9583e02ec95429677c0e013712d42ef1f86a8"
integrity sha512-HxTArb6fkOntQHoRGvv4qd/BkorjliiuO2uSWC2KC17MUTKYttWdDoXX/vxOhQdkoECEM9BBH0pj2l8G8kev6w==
prom-client@^12.0.0:
version "12.0.0"
resolved "https://registry.yarnpkg.com/prom-client/-/prom-client-12.0.0.tgz#9689379b19bd3f6ab88a9866124db9da3d76c6ed"
integrity sha512-JbzzHnw0VDwCvoqf8y1WDtq4wSBAbthMB1pcVI/0lzdqHGJI3KBJDXle70XK+c7Iv93Gihqo0a5LlOn+g8+DrQ==
dependencies:
tdigest "^0.1.1"

Expand Down

0 comments on commit cf0ec4d

Please sign in to comment.