From 95bda4b2f7f9260a3ba0c970dedd1e76e16b2d07 Mon Sep 17 00:00:00 2001 From: giurigaud Date: Fri, 25 Oct 2024 10:07:55 -0300 Subject: [PATCH] feat: add new method getActiveOrganizationsByEmail --- CHANGELOG.md | 4 +-- graphql/schema.graphql | 4 +++ node/package.json | 4 +-- node/resolvers/Queries/Organizations.ts | 40 ++++++++++++++++++++++--- node/typings.d.ts | 9 ------ node/yarn.lock | 10 +++---- 6 files changed, 49 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0de822fd..67d07e45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/graphql/schema.graphql b/graphql/schema.graphql index a6a49414..ced55741 100644 --- a/graphql/schema.graphql +++ b/graphql/schema.graphql @@ -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 diff --git a/node/package.json b/node/package.json index b0e937d7..6e8d571c 100644 --- a/node/package.json +++ b/node/package.json @@ -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", @@ -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", diff --git a/node/resolvers/Queries/Organizations.ts b/node/resolvers/Queries/Organizations.ts index 4ca5d396..cc86b57a 100644 --- a/node/resolvers/Queries/Organizations.ts +++ b/node/resolvers/Queries/Organizations.ts @@ -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 = [] @@ -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 }) => { diff --git a/node/typings.d.ts b/node/typings.d.ts index 71468229..29113e57 100644 --- a/node/typings.d.ts +++ b/node/typings.d.ts @@ -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 diff --git a/node/yarn.lock b/node/yarn.lock index afd8369f..54d10540 100644 --- a/node/yarn.lock +++ b/node/yarn.lock @@ -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" @@ -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: