Skip to content

Commit

Permalink
Merge pull request #28 from vtex-apps/feature/B2BORG-82_check-duplica…
Browse files Browse the repository at this point in the history
…te-requests

[B2BORG-82] Check duplicate requests
  • Loading branch information
auroraaaashen authored Apr 8, 2022
2 parents b229cda + fab3fee commit b521ed1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 4 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]

### Added

- add subfield `email` of the `b2bCustomerAdmin` field to check duplicate requests by email

## [0.14.0] - 2022-04-04

### Added
Expand Down
8 changes: 7 additions & 1 deletion node/mdSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ export const schemas = [
b2bCustomerAdmin: {
type: 'object',
title: 'B2B Customer Admin',
properties: {
email: {
type: 'string',
},
},
'v-indexed': ['email'],
},
status: {
type: 'string',
Expand All @@ -66,7 +72,7 @@ export const schemas = [
format: 'date-time',
},
},
'v-indexed': ['name', 'status', 'created'],
'v-indexed': ['name', 'b2bCustomerAdmin', 'status', 'created'],
'v-immediate-indexing': true,
'v-cache': false,
},
Expand Down
10 changes: 9 additions & 1 deletion node/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,15 @@ export const resolvers = {
}

if (search) {
whereArray.push(`name="*${search}*"`)
if (
search.match(
/^([a-zA-Z0-9!#$%&'*+=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?)$/gm
)
) {
whereArray.push(`b2bCustomerAdmin.email=${search}`)
} else {
whereArray.push(`name="*${search}*"`)
}
}

const where = whereArray.join(' AND ')
Expand Down

0 comments on commit b521ed1

Please sign in to comment.