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 2 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.43.3] - 2024-07-31

### Changed
Expand All @@ -21,64 +25,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 @@ -102,6 +119,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
4 changes: 2 additions & 2 deletions node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vtex.checkout-ui-custom",
"version": "1.43.3",
"dependencies": {
"@vtex/api": "6.46.1",
"@vtex/api": "6.47.0",
"atob": "^2.1.2",
"co-body": "^6.0.0",
"cookie": "^0.3.1",
Expand All @@ -21,7 +21,7 @@
"@types/jsonwebtoken": "^8.5.0",
"@types/node": "^12.0.0",
"@types/ramda": "types/npm-ramda#dist",
"@vtex/api": "6.46.1",
"@vtex/api": "6.47.0",
"@vtex/prettier-config": "^0.3.1",
"tslint": "^5.12.0",
"tslint-config-prettier": "^1.18.0",
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
33 changes: 33 additions & 0 deletions node/typings/custom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,36 @@ export interface DeliveryId {
courierName: string | null
quantity: number | null
}

export interface GetCostCenterType {
getCostCenterById: {
name: string | null
paymentTerms: {
id: string | null
name: string | null
} | null
addresses: {
addressId: string | null
addressType: string | null
addressQuery: string | null
postalCode: string | null
country: string | null
receiverName: string | null
city: string | null
state: string | null
street: string | null
number: string | null
complement: string | null
neighborhood: string | null
geoCoordinates: string | null
reference: string | null
}
enzomerca marked this conversation as resolved.
Show resolved Hide resolved
phoneNumber: string | null
businessDocument: string | null
stateRegistration: string | null
sellers: {
id: string | null
name: string | null
}
}
}
10 changes: 5 additions & 5 deletions node/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@
"@types/mime" "^1"
"@types/node" "*"

"@vtex/api@6.46.1":
version "6.46.1"
resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.46.1.tgz#55a8755ae48f5400e7f1ed1921cd547950bb7a2a"
integrity sha512-geoxVvyWoQpOQ70Zmx3M8SBkRoGOS/bp9Gy26M+iCue63jofVSwmFz1zf66EaHA1PKOJNRgQPFwY+oeDE1U2lQ==
"@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==
dependencies:
"@types/koa" "^2.11.0"
"@types/koa-compose" "^3.2.3"
Expand Down Expand Up @@ -1428,7 +1428,7 @@ sprintf-js@~1.0.2:
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=

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
Loading