Skip to content

Commit

Permalink
- provided fallback for account id (#417)
Browse files Browse the repository at this point in the history
- app version = 4.0.22
  • Loading branch information
severinbeauvais authored Jun 24, 2022
1 parent e8cfed4 commit db924bb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "business-create-ui",
"version": "4.0.21",
"version": "4.0.22",
"private": true,
"appName": "Create UI",
"sbcName": "SBC Common Components",
Expand Down
34 changes: 27 additions & 7 deletions src/services/business-lookup.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,43 @@ import { axios } from '@/utils'
* Class that provides integration with the BusinessLookup API.
*/
export default class BusinessLookupServices {
/** The Business API URL, from session storage. */
static get businessApiUrl (): string {
return sessionStorage.getItem('REGISTRIES_SEARCH_API_URL')
}

/** The Business API Key, from session storage. */
static get businessApiKey (): string {
return sessionStorage.getItem('BUSINESS_API_KEY')
}

/** The Account ID, from session storage. */
static get accountId (): string {
// if we can't get account id from ACCOUNT_ID
// then try to get it from CURRENT_ACCOUNT
let accountId: string = sessionStorage.getItem('ACCOUNT_ID')
if (!accountId) {
const currentAccount = sessionStorage.getItem('CURRENT_ACCOUNT')
accountId = JSON.parse(currentAccount)?.id
}
return accountId
}

/**
* Searches for code or words.
* @param query words to search
* @returns a promise to return the search results
*/
static async search (query: string): Promise<BusinessLookupResultIF[]> {
const businessApiKey = sessionStorage.getItem('BUSINESS_API_KEY')
const accountId = JSON.parse(sessionStorage.getItem('CURRENT_ACCOUNT'))?.id || null
const legalType = 'BC' // Will be updating to a list once search api support it.
let url = sessionStorage.getItem('REGISTRIES_SEARCH_API_URL')
url = `${url}businesses/search/facets?num_of_rows=20&status=active&legalType=${legalType}`
url = `${url}&query=${encodeURIComponent(query)}`
const url = this.businessApiUrl +
`businesses/search/facets?num_of_rows=20&status=active&legalType=${legalType}` +
`&query=${encodeURIComponent(query)}`

return axios.get(url, {
headers: {
'x-apikey': businessApiKey,
'Account-Id': accountId
'x-apikey': this.businessApiKey,
'Account-Id': this.accountId
}
}).then(response => {
const results: Array<BusinessLookupResultIF> = response?.data?.results
Expand Down

0 comments on commit db924bb

Please sign in to comment.