Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: addUser to not accept invalid cost center #150

Merged
merged 9 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 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]

### Fixed

- addUser function to not accept invalid cost center

## [1.44.0] - 2024-08-14

### Changed
Expand Down Expand Up @@ -36,64 +40,77 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [1.43.1] - 2024-07-24

### Changed

- Changed the token validation directive of some operations

## [1.43.0] - 2024-07-23

### Added

- Add admin validation directive

## [1.42.0] - 2024-07-17

### Fixed

- Get tokens from headers when necessary

## [1.41.1] - 2024-07-15

### Added

- Add validation metrics for admin and api tokens

## [1.41.0] - 2024-07-01

### Added

- Add token validation directive

## [1.40.7] - 2024-06-11

### Fixed

- Provide correct tokens to clients

## [1.40.6] - 2024-05-28

### Changed

- Check user is part of buyer org instead of "active" on checkUserAccess directive

## [1.40.5] - 2024-05-22

### Changed

- Improved metrics and logging for checkUserAccess and checkAdminAccess directives

## [1.40.4] - 2024-04-29

### Added

- Add token validation logs

### Removed

- Reverted changes from versions 1.40.3, 1.40.2 and 1.40.1

## [1.40.3] - 2024-04-24

### Fixed

- Provide correct auth tokens to clients

## [1.40.2] - 2024-04-19

### Fixed

- Fix auth issue by adding additional admin token check to checkUserAccess and checkAdminAccess

## [1.40.1] - 2024-04-18

### Fixed

- Fix auth issue by adding role check to checkUserAccess directive

## [1.40.0] - 2024-03-20
Expand All @@ -117,6 +134,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [1.39.2] - 2024-02-26

### Changed

- Add intro description about Session Watcher

## [1.39.1] - 2024-02-09
Expand Down
7 changes: 4 additions & 3 deletions node/clients/Organizations.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { InstanceOptions, IOContext } from '@vtex/api'
import type { GraphQLResponse, InstanceOptions, IOContext } from '@vtex/api'
import { AppGraphQLClient } from '@vtex/api'

import { QUERIES } from '../resolvers/Routes/utils'
import { getTokenToHeader } from './index'
import type { GetCostCenterType } from '../typings/custom'

const getPersistedQuery = () => {
return {
Expand Down Expand Up @@ -36,14 +37,14 @@ export class OrganizationsGraphQLClient extends AppGraphQLClient {
})
}

public getCostCenterById = async (costId: string): Promise<unknown> => {
public getCostCenterById = async (costId: string) => {
return this.query({
extensions: getPersistedQuery(),
query: QUERIES.getCostCenterById,
variables: {
id: costId,
},
})
}) as Promise<GraphQLResponse<GetCostCenterType>>
}

public getMarketingTags = async (costId: string): Promise<unknown> => {
Expand Down
8 changes: 8 additions & 0 deletions node/resolvers/Mutations/Users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ export const addUser = async (_: any, params: any, ctx: Context) => {
} = ctx

try {
const costCenter = await ctx.clients.organizations.getCostCenterById(
params.costId
)

if (!costCenter?.data?.getCostCenterById.name) {
enzomerca marked this conversation as resolved.
Show resolved Hide resolved
throw new Error(`Invalid cost center`)
}

const cId = await addUserToMasterdata({ masterdata, params })

const organizations = await getOrganizationsByEmail(
Expand Down
1 change: 1 addition & 0 deletions node/resolvers/Routes/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const QUERIES = {
id
name
}
name
addresses {
addressId
addressType
Expand Down
18 changes: 18 additions & 0 deletions node/typings/custom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,21 @@ export interface DeliveryId {
courierName: string | null
quantity: number | null
}

export interface GetCostCenterType {
getCostCenterById: {
name: string | null
paymentTerms: {
id: string | null
name: string | null
} | null
address: Address
phoneNumber: string | null
businessDocument: string | null
stateRegistration: string | null
sellers: {
id: string | null
name: string | null
}
}
}
Loading