Skip to content

Commit

Permalink
18535 Amalgamating Businesses Part 1 Continuation (bcgov#588)
Browse files Browse the repository at this point in the history
* Refactored saveAmalgamatingBusiness + specified what to search for

* Setup AmalgamatingBusinesses validity

* fixed unit tests

* cleanup

* Populate the table using the business lookup

* Fixed in response to Sev's comments

* Small cleanup in response to Sev's comment

* updated package version
  • Loading branch information
JazzarKarim authored Dec 6, 2023
1 parent 95e789a commit eaca75d
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 43 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "business-create-ui",
"version": "5.6.7",
"version": "5.6.8",
"private": true,
"appName": "Create UI",
"sbcName": "SBC Common Components",
Expand All @@ -17,7 +17,7 @@
"@bcrs-shared-components/approval-type": "1.0.19",
"@bcrs-shared-components/base-address": "2.0.3",
"@bcrs-shared-components/breadcrumb": "2.1.15",
"@bcrs-shared-components/business-lookup": "1.2.3",
"@bcrs-shared-components/business-lookup": "1.2.4",
"@bcrs-shared-components/certify": "2.1.15",
"@bcrs-shared-components/completing-party": "2.1.30",
"@bcrs-shared-components/confirm-dialog": "1.2.1",
Expand Down
73 changes: 43 additions & 30 deletions src/components/Amalgamation/AmalgamatingBusinesses.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
:showErrors="false"
:businessLookup="initialBusinessLookupObject"
:BusinessLookupServices="BusinessLookupServices"
legalTypes="BC,BEN,CC,ULC,A"
label="Business Name or Incorporation Number"
@setBusiness="saveAmalgamatingBusiness($event)"
/>
Expand Down Expand Up @@ -111,7 +112,8 @@
<template v-if="business.foundingDate">
Legal Name: {{ business.legalName }} <br>
Legal Type: {{ business.legalType }} <br>
Mailing Address: {{ business.officeAddress.mailingAddress }} <br>
Mailing Address: {{ business.officeAddress.registeredOffice.mailingAddress }} <br>
Email Address: {{ business.businessContact.email }} <br>
State: {{ business.state }} <br>
Good Standing: {{ business.goodStanding }} <br>
</template>
Expand Down Expand Up @@ -140,9 +142,10 @@ import { Component, Mixins } from 'vue-property-decorator'
import { Action, Getter } from 'pinia-class'
import { useStore } from '@/store/store'
import { CommonMixin } from '@/mixins'
import { BusinessLookupServices, LegalServices } from '@/services'
import { AuthServices, BusinessLookupServices, LegalServices } from '@/services'
import { BusinessLookup } from '@bcrs-shared-components/business-lookup'
import { AmalgamatingBusinessIF, BusinessLookupIF, EmptyBusinessLookup } from '@/interfaces'
import { AmlRoles } from '@/enums'
import BusinessTable from '@/components/Amalgamation/BusinessTable.vue'
@Component({
Expand All @@ -153,11 +156,13 @@ import BusinessTable from '@/components/Amalgamation/BusinessTable.vue'
})
export default class AmalgamatingBusinesses extends Mixins(CommonMixin) {
@Getter(useStore) getAmalgamatingBusinesses!: AmalgamatingBusinessIF[]
@Getter(useStore) getAmalgamatingBusinessesValid!: boolean
@Getter(useStore) getShowErrors!: boolean
@Getter(useStore) isAmalgamationFilingHorizontal!: boolean
@Getter(useStore) isRoleStaff!: boolean
@Action(useStore) setAmalgamatingBusinesses!: (x: Array<any>) => void
@Action(useStore) setAmalgamatingBusinessesValid!: (x: boolean) => void
// Local properties
amalgamatingBusinessesValid = false
Expand All @@ -174,60 +179,68 @@ export default class AmalgamatingBusinesses extends Mixins(CommonMixin) {
// Cancel button in "Add an Amalgamating Business" is pressed.
addAmalgamatingBusinessCancel (): void {
this.isAddingAmalgamatingBusiness = false
this.setAmalgamatingBusinessesValid(true)
}
// "Add an Amalgamating Business" button is pressed.
onAddBusinessClick (): void {
this.isAddingAmalgamatingBusiness = true
this.isAddingAmalgamatingForeignBusiness = false
this.setAmalgamatingBusinessesValid(false)
}
// "Add an Amalgamating Foreign Business" button is pressed.
onAddForeignBusinessClick (): void {
this.isAddingAmalgamatingBusiness = false
this.isAddingAmalgamatingForeignBusiness = true
this.setAmalgamatingBusinessesValid(false)
}
async saveAmalgamatingBusiness (businessLookup: BusinessLookupIF): Promise<void> {
// Get the amalgamating business information
// Will have a different format depending on the business
let business = await LegalServices.fetchBusinessInfo(businessLookup.identifier)
.then((response) => {
return response?.data?.business
}).catch(() => {
return businessLookup
})
// Get the address of the amalgamating business
if (businessLookup.identifier && business.foundingDate) {
const addresses = await LegalServices.fetchAddresses(businessLookup.identifier)
.then((data) => {
// SP and GP have businessOffice instead of registeredOffice
return data?.registeredOffice || data?.businessOffice
}).catch(() => {
return undefined
})
if (addresses) {
business.officeAddress = addresses
}
let business = null
// Get the amalgamating business information, mailing address, and email if in LEAR.
// Otherwise, return the businesslookup object.
const data = await Promise.all([
LegalServices.fetchBusinessInfo(businessLookup.identifier),
AuthServices.fetchAuthInfo(businessLookup.identifier),
LegalServices.fetchAddresses(businessLookup.identifier)
]).catch((error) => {
return error
})
if (data.length === 3) {
business = data[0].data?.business
business.businessContact = data[1].contacts[0]
business.officeAddress = data[2]
}
// If the business is not null (LEAR Entity), create from it a TING business following the interface.
// If the amalgamating businesses array is not empty, check if identifier already exists.
// If identifier already exists, don't add the business to the array.
if (this.amalgamatingBusinesses.length > 0) {
const businessExists = this.amalgamatingBusinesses.find(function (id) {
return id.identifier === business.identifier
})
if (!businessExists) this.amalgamatingBusinesses.push(business)
} else {
this.amalgamatingBusinesses.push(business)
if (business) {
const tingBusiness = {
type: 'lear',
role: AmlRoles.AMALGAMATING,
identifier: business.identifier,
name: business.legalName,
email: business.businessContact.email,
legalType: business.legalType,
address: business.officeAddress.registeredOffice.mailingAddress,
goodStanding: business.goodStanding
} as AmalgamatingBusinessIF
if (!this.amalgamatingBusinesses.find(b => b.identifier === business.identifier)) {
this.amalgamatingBusinesses.push(tingBusiness)
}
}
// Set the amalgamated businesses array in the store.
this.setAmalgamatingBusinesses(this.amalgamatingBusinesses)
// Close the "Add an Amalgamating Business" Panel.
this.isAddingAmalgamatingBusiness = false
this.setAmalgamatingBusinessesValid(true)
}
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ export type AmalgamatingBusinessIF = AmalgamatingLearIF | AmalgamatingForeignIF
export interface AmalgamationStateIF {
amalgamatingBusinesses: Array<AmalgamatingBusinessIF>
courtApproval: boolean
amalgamatingBusinessesValid: boolean
type: AmalgamationTypes
}
7 changes: 4 additions & 3 deletions src/services/business-lookup-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ export default class BusinessLookupServices {
/**
* Searches for business by code or words.
* @param query code or words to search
* @param searchStatus not used here but needed as it's a parameter needed for other UIs
* @param legalTypes the legal types we're searching for
* @returns a promise to return the search results
*/
static async search (query: string): Promise<BusinessLookupResultIF[]> {
const legalType = 'BC,A,ULC,C,S,XP,GP,LP,CUL,XS,LLC,LL,BEN,CP,CC,XL,FI,XCP,PA'
static async search (query: string, searchStatus: string, legalTypes: string): Promise<BusinessLookupResultIF[]> {
const url = this.businessApiUrl +
`businesses/search/facets?start=0&rows=20&categories=legalType:${legalType}::status:ACTIVE` +
`businesses/search/facets?start=0&rows=20&categories=legalType:${legalTypes}::status:ACTIVE` +
`&query=value:${encodeURIComponent(query)}`

return axios.get(url, {
Expand Down
1 change: 1 addition & 0 deletions src/store/state/state-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ export const stateModel: StateModelIF = {
},
amalgamation: {
amalgamatingBusinesses: cloneDeep(AMALGAMATING_BUSINESSES),
amalgamatingBusinessesValid: false,
courtApproval: null,
type: null
},
Expand Down
8 changes: 8 additions & 0 deletions src/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,11 @@ export const useStore = defineStore('store', {
return this.stateModel.amalgamation.amalgamatingBusinesses
},

/** The amalgamating businesses validity. */
getAmalgamatingBusinessesValid (): boolean {
return this.stateModel.amalgamation.amalgamatingBusinessesValid
},

//
// Dissolution getters
//
Expand Down Expand Up @@ -1224,6 +1229,9 @@ export const useStore = defineStore('store', {
setAmalgamatingBusinesses (amalgamatingBusinesses: Array<AmalgamatingBusinessIF>) {
this.stateModel.amalgamation.amalgamatingBusinesses = amalgamatingBusinesses
},
setAmalgamatingBusinessesValid (valid: boolean) {
this.stateModel.amalgamation.amalgamatingBusinessesValid = valid
},
setAmalgamationType (type: AmalgamationTypes) {
this.stateModel.amalgamation.type = type
},
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/business-lookup-services.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ describe('Business Lookup Services', () => {
.returns(new Promise(resolve => resolve({ data: { searchResults: { results: [result] } } })))

// search and look at results
const results = await BusinessLookupServices.search('FM1000002')
const results = await BusinessLookupServices.search(
'FM1000002', 'ACTIVE', 'BC,A,ULC,C,S,XP,GP,LP,CUL,XS,LLC,LL,BEN,CP,CC,XL,FI,XCP,PA'
)
expect(results.length).toBe(1)
expect(results[0]).toEqual(result)

Expand All @@ -39,7 +41,9 @@ describe('Business Lookup Services', () => {
.returns(new Promise(resolve => resolve({ data: { searchResults: { results: [] } } })))

// search and look at results
const results = await BusinessLookupServices.search('FM1000003')
const results = await BusinessLookupServices.search(
'FM1000003', 'ACTIVE', 'BC,A,ULC,C,S,XP,GP,LP,CUL,XS,LLC,LL,BEN,CP,CC,XL,FI,XCP,PA'
)
expect(results.length).toBe(0)

sinon.restore()
Expand Down

0 comments on commit eaca75d

Please sign in to comment.