Skip to content

Commit

Permalink
Merge pull request #184 from giurigaud/fix/remove-inactive-orgs
Browse files Browse the repository at this point in the history
fix: [KI 1092989] getOrganizationsByEmail to return only active organizations
  • Loading branch information
ataideverton authored Dec 3, 2024
2 parents f98f461 + 456d279 commit 72feb21
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added

- Add getActiveOrganizationsByEmail to return only active organizations

## [0.61.1] - 2024-10-29

### Fixed
- Avoid calls to checkUserPermissions when session data is not available


## [0.61.0] - 2024-10-16

### Added
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]
@cacheControl(scope: PRIVATE)
@validateStoreUserAccess

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.1",
"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
57 changes: 53 additions & 4 deletions node/resolvers/Queries/Organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import {
ORGANIZATION_REQUEST_SCHEMA_VERSION,
ORGANIZATION_SCHEMA_VERSION,
} from '../../mdSchema'
import type { Organization } from '../../typings'
import type {
GetOrganizationsByEmailWithStatus,
Organization,
} from '../../typings'
import GraphQLError, { getErrorMessage } from '../../utils/GraphQLError'
import checkConfig from '../config'
import { organizationStatus } from '../fieldResolvers'

const getWhereByStatus = ({ status }: { status: string[] }) => {
const whereArray = []
Expand Down Expand Up @@ -182,11 +186,13 @@ const Organizations = {
getOrganizationsByEmail: async (
_: void,
{ email }: { email: string },
{
ctx: Context
) => {
const {
clients: { storefrontPermissions, session },
vtex: { logger, sessionToken, adminUserAuthToken },
}: any
) => {
} = ctx

const organizationFilters: string[] = []
let fromSession = false

Expand Down Expand Up @@ -270,6 +276,49 @@ const Organizations = {
}
},

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 }) => {
const status = await organizationStatus(
{ orgId: organization.orgId },
_,
ctx
)

return { ...organization, status }
})
)

const activeOrganizations = organizationsWithStatus.filter(
(organization) => organization.status === 'active'
)

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

getOrganizationByIdStorefront: async (
_: void,
{ id }: { id: string },
Expand Down
8 changes: 8 additions & 0 deletions node/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ interface Collection {
id: string
name: string
}
interface GetOrganizationsByEmailWithStatus {
costId: string
orgId: string
roleId: string
id: string
clId: string
status: string
}

interface CostCenter {
id: 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 72feb21

Please sign in to comment.