Skip to content

Commit

Permalink
Merge branch 'master' into feature/add-emails-create-organization
Browse files Browse the repository at this point in the history
  • Loading branch information
arturmagalhaesjr committed Dec 10, 2024
2 parents 903d2af + 51f625a commit 3515020
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 13 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,25 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- Added mail notification to `createOrganizationAndCostCenterWithAdminUser` mutation

## [0.63.0] - 2024-12-04
### Fixed
- Remove merge marker from code

## [0.62.1] - 2024-12-04
### Added
- Add TopBarSettings type in B2B settings and updated saveB2BSettings to use the new topBar field in UISettings

## [0.62.0] - 2024-12-03
### 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
16 changes: 16 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 Expand Up @@ -521,10 +525,16 @@ type TransactionEmailSettings {
organizationStatusChanged: Boolean
}

type TopBarSettings {
name: String
hexColor: String
}

type UISettings {
showModal: Boolean
clearCart: Boolean
fullImpersonation: Boolean
topBar: TopBarSettings
}

scalar Data
Expand Down Expand Up @@ -677,10 +687,16 @@ input TransactionEmailSettingsInput {
organizationStatusChanged: Boolean
}

input TopBarSettingsInput {
name: String
hexColor: String
}

input UISettingsInput {
showModal: Boolean
clearCart: Boolean
fullImpersonation: Boolean
topBar: TopBarSettingsInput
}

input B2BSettingsInput {
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "b2b-organizations-graphql",
"vendor": "vtex",
"version": "0.61.1",
"version": "0.63.0",
"title": "B2B Organizations",
"description": "App to create and manage B2B Organizations and Cost Centers",
"mustUpdateAt": "2022-08-28",
Expand Down
6 changes: 3 additions & 3 deletions node/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "vtex.b2b-organizations",
"version": "0.61.1",
"version": "0.63.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
6 changes: 5 additions & 1 deletion node/resolvers/Mutations/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ const Settings = {
transactionEmailSettings:
transactionEmailSettings ??
currentB2BSettings?.transactionEmailSettings,
uiSettings,
uiSettings: {
showModal: uiSettings.showModal,
clearCart: uiSettings.clearCart,
topBar: uiSettings.topBar ?? currentB2BSettings?.uiSettings?.topBar,
},
}

await vbase.saveJSON(B2B_SETTINGS_DATA_ENTITY, 'settings', b2bSettings)
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
14 changes: 14 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 Expand Up @@ -231,10 +239,16 @@ interface Price {
id: string
}

interface TopBarSetting {
name: string
hexColor: string
}

interface UISettings {
showModal: boolean
clearCart: boolean
fullImpersonation: boolean
topBar?: TopBarSetting | null
}

interface CustomField {
Expand Down
8 changes: 4 additions & 4 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

0 comments on commit 3515020

Please sign in to comment.