Skip to content

Commit

Permalink
feat: add new method getActiveOrganizationsByEmail
Browse files Browse the repository at this point in the history
  • Loading branch information
giurigaud committed Oct 25, 2024
1 parent 9b45490 commit 95bda4b
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 22 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed
### Added

- Fix getOrganizationsByEmail to return only active organizations
- Add new getActiveOrganizationsByEmail query to return only active organizations

## [0.61.0] - 2024-10-16

Expand Down
4 changes: 4 additions & 0 deletions graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ type Query {
@checkUserAccess
@cacheControl(scope: PRIVATE)

getActiveOrganizationsByEmail(email: String): [B2BOrganization]
@checkUserAccess
@cacheControl(scope: PRIVATE)

checkOrganizationIsActive(id: String): Boolean
@cacheControl(scope: PRIVATE)
@auditAccess
Expand Down
4 changes: 2 additions & 2 deletions node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.61.0",
"dependencies": {
"@types/lodash": "4.14.74",
"@vtex/api": "6.47.0",
"@vtex/api": "6.48.0",
"atob": "^2.1.2",
"co-body": "^6.0.0",
"graphql": "^14.5.0",
Expand All @@ -20,7 +20,7 @@
"@types/jsonwebtoken": "^8.5.0",
"@types/node": "^12.12.21",
"@types/ramda": "types/npm-ramda#dist",
"@vtex/api": "6.47.0",
"@vtex/api": "6.48.0",
"@vtex/prettier-config": "^0.3.1",
"@vtex/tsconfig": "^0.6.0",
"jest": "27.5.1",
Expand Down
40 changes: 36 additions & 4 deletions node/resolvers/Queries/Organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ import {
ORGANIZATION_REQUEST_SCHEMA_VERSION,
ORGANIZATION_SCHEMA_VERSION,
} from '../../mdSchema'
import type {
GetOrganizationsByEmailWithStatus,
Organization,
} from '../../typings'
import type { Organization } from '../../typings'
import GraphQLError, { getErrorMessage } from '../../utils/GraphQLError'
import checkConfig from '../config'
import { organizationStatus } from '../fieldResolvers'

export interface GetOrganizationsByEmailWithStatus {
costId: string
orgId: string
roleId: string
id: string
clId: string
status: string
}

const getWhereByStatus = ({ status }: { status: string[] }) => {
const whereArray = []

Expand Down Expand Up @@ -261,6 +267,32 @@ const Organizations = {
)
})

try {
return organizations
} catch (error) {
logger.error({
error,
message: 'getOrganizationsByEmail-error',
})
throw new GraphQLError(getErrorMessage(error))
}
},

getActiveOrganizationsByEmail: async (
_: void,
{ email }: { email: string },
ctx: Context
) => {
const {
vtex: { logger },
} = ctx

const organizations = await Organizations.getOrganizationsByEmail(
_,
{ email },
ctx
)

const organizationsWithStatus: GetOrganizationsByEmailWithStatus[] =
await Promise.all(
organizations.map(async (organization: { orgId: string }) => {
Expand Down
9 changes: 0 additions & 9 deletions node/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,6 @@ interface Organization {
sellers?: Seller[]
}

export type GetOrganizationsByEmailWithStatus = {
costId: string
orgId: string
roleId: string
id: string
clId: string
status: string
}

interface Collection {
id: string
name: string
Expand Down
10 changes: 5 additions & 5 deletions node/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -836,10 +836,10 @@
dependencies:
"@types/yargs-parser" "*"

"@vtex/api@6.47.0":
version "6.47.0"
resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.47.0.tgz#6910455d593d8bb76f1f4f2b7660023853fda35e"
integrity sha512-t9gt7Q89EMbSj3rLhho+49Fv+/lQgiy8EPVRgtmmXFp1J4v8hIAZF7GPjCPie111KVs4eG0gfZFpmhA5dafKNA==
"@vtex/api@6.48.0":
version "6.48.0"
resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.48.0.tgz#67f9f11d197d543d4f854b057d31a8d6999241e9"
integrity sha512-mAdT7gbV0/BwiuqUkNH1E7KZqTUczT5NbBBZcPJq5kmTr73PUjbR9wh//70ryJo2EAdHlqIgqgwsCVpozenlhg==
dependencies:
"@types/koa" "^2.11.0"
"@types/koa-compose" "^3.2.3"
Expand Down Expand Up @@ -3475,7 +3475,7 @@ stack-utils@^2.0.3:
dependencies:
escape-string-regexp "^2.0.0"

stats-lite@vtex/node-stats-lite#dist:
"stats-lite@github:vtex/node-stats-lite#dist":
version "2.2.0"
resolved "https://codeload.github.com/vtex/node-stats-lite/tar.gz/1b0d39cc41ef7aaecfd541191f877887a2044797"
dependencies:
Expand Down

0 comments on commit 95bda4b

Please sign in to comment.