Skip to content

Commit

Permalink
fix: [KI 1055033] - geocoordinates (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
giurigaud authored Oct 14, 2024
1 parent 1e2a59d commit 1640c7e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 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

- getRegionId now includes geographic coordinates in parameters when available

## [1.44.11] - 2024-10-10

### Fixed
Expand Down
25 changes: 20 additions & 5 deletions node/clients/checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,27 @@ export class Checkout extends JanusClient {

public getRegionId = (
country: string,
postalCode: string,
salesChannel: string
postalCode: string | null,
salesChannel: string,
geoCoordinates: [number, number] | null
): Promise<RegionsResponse[]> => {
return this.get(
`/api/checkout/pub/regions?country=${country}&postalCode=${postalCode}&sc=${salesChannel}`
)
const baseUrl = '/api/checkout/pub/regions'
const params = new URLSearchParams({
country,
sc: salesChannel,
})

if (postalCode) {
params.append('postalCode', postalCode)
}

if (geoCoordinates) {
params.append('geoCoordinates', geoCoordinates.join(';'))
}

const url = `${baseUrl}?${params.toString()}`

return this.get(url)
}

protected get = <T>(url: string, config: RequestConfig = {}) => {
Expand Down
5 changes: 3 additions & 2 deletions node/resolvers/Routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ export const Routes = {
// Only require CPF if cost center contains an address in Brazil
// This is a workaround to avoid setting CPF as documentType for countries other than Brazil
if (
costCenterResponse?.data?.getCostCenterById?.addresses.some(
costCenterResponse?.data?.getCostCenterById?.addresses?.some(
(address: { country: string }) => address.country === 'BRA'
)
) {
Expand Down Expand Up @@ -460,7 +460,8 @@ export const Routes = {
const [regionId] = await checkout.getRegionId(
address.country,
address.postalCode,
salesChannel.toString()
salesChannel.toString(),
address.geoCoordinates
)

if (regionId?.id) {
Expand Down
2 changes: 1 addition & 1 deletion node/yarn.lock
Original file line number Diff line number Diff line change
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

0 comments on commit 1640c7e

Please sign in to comment.