Skip to content

Commit

Permalink
Merge pull request vtex-apps#30 from vtex-apps/bugfix/B2BORG-96_fix-d…
Browse files Browse the repository at this point in the history
…uplicate-check

[B2BORG-96] Fix duplicate check
  • Loading branch information
auroraaaashen authored Apr 25, 2022
2 parents 11bfd06 + 478691e commit 5655fc0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added
- Added duplicate check for create organization request

## [0.16.0] - 2022-04-15

### Added
Expand Down
1 change: 1 addition & 0 deletions graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ type Address {
type MasterDataResponse {
id: String
href: String
status: String
}

type MutationResponse {
Expand Down
1 change: 1 addition & 0 deletions node/resolvers/Mutations/CostCenters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const CostCenters = {
return {
href: createCostCenterResult.Href,
id: createCostCenterResult.DocumentId,
status: '',
}
} catch (e) {
logger.error({
Expand Down
22 changes: 21 additions & 1 deletion node/resolvers/Mutations/Organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const Organizations = {
return {
href: createOrganizationResult.Href,
id: createOrganizationResult.DocumentId,
status: '',
}
} catch (e) {
logger.error({
Expand Down Expand Up @@ -98,6 +99,25 @@ const Organizations = {
// create schema if it doesn't exist
await checkConfig(ctx)

const duplicate = await masterdata
.searchDocumentsWithPaginationInfo({
dataEntity: ORGANIZATION_REQUEST_DATA_ENTITY,
fields: ORGANIZATION_REQUEST_FIELDS,
schema: ORGANIZATION_REQUEST_SCHEMA_VERSION,
sort: `created DESC`,
where: `b2bCustomerAdmin.email=${b2bCustomerAdmin.email}`,
pagination: {
page: 1,
pageSize: 1,
},
})
.then((res: any) => {
return res.data[0]?.status ?? ''
})
.catch(() => '')

if (duplicate !== '') return { href: '', id: '', status: duplicate }

const now = new Date()

const organizationRequest = {
Expand All @@ -116,7 +136,7 @@ const Organizations = {
schema: ORGANIZATION_REQUEST_SCHEMA_VERSION,
})

return { href: result.Href, id: result.DocumentId }
return { href: result.Href, id: result.DocumentId, status: duplicate }
} catch (e) {
logger.error({
message: 'createOrganizationRequest-error',
Expand Down

0 comments on commit 5655fc0

Please sign in to comment.