Skip to content

Commit

Permalink
Refactored the code + centralized fetch calls
Browse files Browse the repository at this point in the history
  • Loading branch information
JazzarKarim committed Dec 13, 2023
1 parent 8bcd81f commit c18ba63
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 53 deletions.
63 changes: 17 additions & 46 deletions src/components/Amalgamation/AmalgamatingBusinesses.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@
import { Component, Mixins, Watch } from 'vue-property-decorator'
import { Action, Getter } from 'pinia-class'
import { useStore } from '@/store/store'
import { CommonMixin } from '@/mixins'
import { AuthServices, BusinessLookupServices, LegalServices } from '@/services'
import { AmalgamationMixin, CommonMixin } from '@/mixins'
import { BusinessLookupServices } from '@/services'
import { BusinessLookup } from '@bcrs-shared-components/business-lookup'
import { AmalgamatingBusinessIF, BusinessLookupResultIF, EmptyBusinessLookup } from '@/interfaces'
import { AmlRoles, AmlTypes, RestorationTypes } from '@/enums'
import { AmlRoles, AmlTypes } from '@/enums'
import BusinessTable from '@/components/Amalgamation/BusinessTable.vue'
import { CorpTypeCd } from '@bcrs-shared-components/corp-type-module'
Expand All @@ -163,15 +163,12 @@ import { CorpTypeCd } from '@bcrs-shared-components/corp-type-module'
BusinessTable
}
})
export default class AmalgamatingBusinesses extends Mixins(CommonMixin) {
export default class AmalgamatingBusinesses extends Mixins(AmalgamationMixin, CommonMixin) {
readonly BusinessLookupServices = BusinessLookupServices
@Getter(useStore) getAmalgamatingBusinesses!: AmalgamatingBusinessIF[]
@Getter(useStore) getAmalgamatingBusinessesValid!: boolean
@Getter(useStore) getCurrentDate!: string
@Getter(useStore) getShowErrors!: boolean
@Getter(useStore) isAmalgamationFilingHorizontal!: boolean
@Getter(useStore) isRoleStaff!: boolean
@Action(useStore) pushAmalgamatingBusiness!: (x: AmalgamatingBusinessIF) => void
@Action(useStore) setAmalgamatingBusinessesValid!: (x: boolean) => void
Expand All @@ -187,22 +184,11 @@ export default class AmalgamatingBusinesses extends Mixins(CommonMixin) {
isAddingAmalgamatingForeignBusiness = false
async saveAmalgamatingBusiness (businessLookup: BusinessLookupResultIF): Promise<void> {
// Get the auth info, business info, addresses and filings in parallel.
// Return data array; if any call failed, that item will be undefined.
const data = await Promise.allSettled([
AuthServices.fetchAuthInfo(businessLookup.identifier),
LegalServices.fetchBusinessInfo(businessLookup.identifier),
LegalServices.fetchAddresses(businessLookup.identifier),
LegalServices.fetchFirstOrOnlyFiling(businessLookup.identifier)
]).then(results => results.map((result: any) => result.value))
const authInfo = data[0]
const businessInfo = data[1]
const addresses = data[2]
const firstFiling = data[3]
// Get the business information
const business = await this.fetchBusinessInfoForTing(businessLookup)
// Check for unaffiliated business.
if (!authInfo) {
if (!business.authInfo) {
// If a staff account couldn't fetch the auth info then the business doesn't exist.
if (this.isRoleStaff) {
this.snackbarText = 'Business doesn\'t exist in LEAR.'
Expand All @@ -226,46 +212,31 @@ export default class AmalgamatingBusinesses extends Mixins(CommonMixin) {
}
// Check for Legal API fetch issues.
if (!businessInfo || !addresses || !firstFiling) {
if (!business.businessInfo || !business.addresses || !business.firstFiling) {
this.snackbarText = 'Unable to add that business.'
this.snackbar = true
return
}
// Verify that identifier doesn't already exist.
if (this.getAmalgamatingBusinesses.find((b: any) => b.identifier === businessInfo.identifier)) {
if (this.getAmalgamatingBusinesses.find((b: any) => b.identifier === business.businessInfo.identifier)) {
this.snackbarText = 'Business is already in table.'
this.snackbar = true
return
}
// If there is a state filing and restoration expiry date isn't in the past and the state filing is a
// limited restoration or limited restoration extension, then this business is in limited restoration.
const isLimitedRestoration = async (): Promise<boolean> => {
// check for no state filing
if (!businessInfo.stateFiling) return false
// check for expired restoration
if (this.getCurrentDate > businessInfo.restorationExpiryDate) return false
// fetch state filing
const stateFiling = await LegalServices.fetchFiling(businessInfo.stateFiling)
return (
stateFiling.restoration.type === RestorationTypes.LIMITED ||
stateFiling.restoration.type === RestorationTypes.LTD_EXTEND
)
}
// Create amalgamating business object.
const tingBusiness: AmalgamatingBusinessIF = {
type: AmlTypes.LEAR,
role: AmlRoles.AMALGAMATING,
identifier: businessInfo.identifier,
name: businessInfo.legalName,
email: authInfo.contacts[0].email,
legalType: businessInfo.legalType,
address: addresses.registeredOffice.mailingAddress,
isNotInGoodStanding: (businessInfo.goodStanding === false),
isFutureEffective: (firstFiling.isFutureEffective === true),
isLimitedRestoration: await isLimitedRestoration()
identifier: business.businessInfo.identifier,
name: business.businessInfo.legalName,
email: business.authInfo.contacts[0].email,
legalType: business.businessInfo.legalType,
address: business.addresses.registeredOffice.mailingAddress,
isNotInGoodStanding: (business.businessInfo.goodStanding === false),
isFutureEffective: (business.firstFiling.isFutureEffective === true),
isLimitedRestoration: await this.isLimitedRestoration(business)
}
// Add the new business to the amalgamating businesses list.
Expand Down
89 changes: 87 additions & 2 deletions src/mixins/amalgamation-mixin.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { Component, Vue } from 'vue-property-decorator'
import { Getter } from 'pinia-class'
import { Action, Getter } from 'pinia-class'
import { useStore } from '@/store/store'
import { AmlStatuses, AmlTypes } from '@/enums'
import { AmlRoles, AmlStatuses, AmlTypes, RestorationTypes } from '@/enums'
import { AmalgamatingBusinessIF } from '@/interfaces'
import { CorpTypeCd } from '@bcrs-shared-components/corp-type-module'
import { AuthServices, LegalServices } from '@/services'

/**
* Mixin that provides amalgamation rules, etc.
*/
@Component({})
export default class AmalgamationMixin extends Vue {
@Getter(useStore) getAmalgamatingBusinesses!: AmalgamatingBusinessIF[]
@Getter(useStore) getCurrentDate!: string
@Getter(useStore) isRoleStaff!: boolean
@Getter(useStore) isTypeBcCcc!: boolean
@Getter(useStore) isTypeBcUlcCompany!: boolean

@Action(useStore) setAmalgamatingBusinesses!: (x: Array<any>) => void

// *** TODO: finish this, maybe name them something recognizable...
/** Iterable array of rule functions, sorted by importance. */
readonly rules = [
Expand All @@ -41,6 +45,87 @@ export default class AmalgamationMixin extends Vue {
)
}

/**
* Get the business information, mailing address, email, and first filing if in LEAR.
* Otherwise, return error.
*/
async fetchBusinessInfoForTing (item: any): Promise<any> {
// Get the auth info, business info, addresses and filings in parallel.
// Return data array; if any call failed, that item will be undefined.
const data = await Promise.allSettled([
AuthServices.fetchAuthInfo(item.identifier),
LegalServices.fetchBusinessInfo(item.identifier),
LegalServices.fetchAddresses(item.identifier),
LegalServices.fetchFirstOrOnlyFiling(item.identifier)
]).then(results => results.map((result: any) => result.value))

const authInfo = data[0]
const businessInfo = data[1]
const addresses = data[2]
const firstFiling = data[3]

return {
authInfo,
businessInfo,
addresses,
firstFiling
}
}

/**
* If there is a state filing and restoration expiry date isn't in the past and the state filing is a
* limited restoration or limited restoration extension, then this business is in limited restoration.
* @param business The business to check if is in Limited Restoration or not.
*/
isLimitedRestoration = async (business: any): Promise<boolean> => {
// check for no state filing
if (!business.businessInfo.stateFiling) return false
// check for expired restoration
if (this.getCurrentDate > business.businessInfo.restorationExpiryDate) return false
// fetch state filing
const stateFiling = await LegalServices.fetchFiling(business.businessInfo.stateFiling)
return (
stateFiling.restoration.type === RestorationTypes.LIMITED ||
stateFiling.restoration.type === RestorationTypes.LTD_EXTEND
)
}

/**
* Re-fetch the draft amalgamating businesses information and set in the store.
* Need to do that because the businesses might have changed from last draft save.
*/
async refetchAmalgamatingBusinessesInfo (): Promise<void> {
const fetchTingInfo = async (item: any): Promise<AmalgamatingBusinessIF> => {
let tingBusiness = await this.fetchBusinessInfoForTing(item)
if (!tingBusiness.authInfo) {
return {
type: AmlTypes.LEAR,
role: AmlRoles.AMALGAMATING,
identifier: item.identifier,
name: item.name,
legalType: item.legalType as unknown as CorpTypeCd
}
} else {
return {
type: AmlTypes.LEAR,
role: AmlRoles.AMALGAMATING,
identifier: tingBusiness.businessInfo.identifier,
name: tingBusiness.businessInfo.legalName,
email: tingBusiness.authInfo.contacts[0].email,
legalType: tingBusiness.businessInfo.legalType,
address: tingBusiness.addresses.registeredOffice.mailingAddress,
isNotInGoodStanding: (tingBusiness.businessInfo.goodStanding === false),
isFutureEffective: (tingBusiness.firstFiling.isFutureEffective === true),
isLimitedRestoration: await this.isLimitedRestoration(tingBusiness)
}
}
}

this.setAmalgamatingBusinesses(
await Promise.all(this.getAmalgamatingBusinesses.map(fetchTingInfo))
)
}

// *** TODO
// A BC Company cannot amalgamate with an existing Unlimited Liability Company from Alberta,
// Nova Scotia, or the USA to form a BC Unlimited Liability Company.
Expand Down
9 changes: 4 additions & 5 deletions src/mixins/filing-template-mixin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Component, Mixins } from 'vue-property-decorator'
import { Getter, Action } from 'pinia-class'
import { useStore } from '@/store/store'
import { DateMixin } from '@/mixins'
import { AmalgamationMixin, DateMixin } from '@/mixins'
import {
AmalgamatingBusinessIF, AmalgamationFilingIF, BusinessAddressIF, ContactPointIF, CertifyIF, CompletingPartyIF,
AmalgamationFilingIF, BusinessAddressIF, ContactPointIF, CertifyIF, CompletingPartyIF,
CourtOrderIF, CourtOrderStepIF, CreateMemorandumIF, CreateResolutionIF, CreateRulesIF, DefineCompanyIF,
DissolutionFilingIF, DissolutionStatementIF, DocumentDeliveryIF, EffectiveDateTimeIF, EmptyContactPoint,
EmptyNaics, IncorporationAgreementIF, IncorporationFilingIF, NaicsIF, NameRequestFilingIF,
Expand All @@ -21,10 +21,9 @@ import { CorpTypeCd } from '@bcrs-shared-components/corp-type-module/'
* Mixin that provides the integration with the Legal API.
*/
@Component({})
export default class FilingTemplateMixin extends Mixins(DateMixin) {
export default class FilingTemplateMixin extends Mixins(AmalgamationMixin, DateMixin) {
@Getter(useStore) getAddPeopleAndRoleStep!: PeopleAndRoleIF
@Getter(useStore) getAffidavitStep!: UploadAffidavitIF
@Getter(useStore) getAmalgamatingBusinesses!: AmalgamatingBusinessIF[]
@Getter(useStore) getAmalgamationCourtApproval!: boolean
@Getter(useStore) getAmalgamationType!: AmalgamationTypes
@Getter(useStore) getBusinessContact!: ContactPointIF
Expand Down Expand Up @@ -65,7 +64,6 @@ export default class FilingTemplateMixin extends Mixins(DateMixin) {
@Getter(useStore) getTempId!: string
@Getter(useStore) getTransactionalFolioNumber!: string
@Getter(useStore) isPremiumAccount!: boolean
@Getter(useStore) isRoleStaff!: boolean
@Getter(useStore) isTypeCoop!: boolean
@Getter(useStore) isTypeFirm!: boolean
@Getter(useStore) isTypeSoleProp!: boolean
Expand Down Expand Up @@ -226,6 +224,7 @@ export default class FilingTemplateMixin extends Mixins(DateMixin) {
// restore the amalgamating businesses array
if (draftFiling.amalgamation.amalgamatingBusinesses) {
this.setAmalgamatingBusinesses(draftFiling.amalgamation.amalgamatingBusinesses)
this.refetchAmalgamatingBusinessesInfo()
}

// restore the amalgamation court approval
Expand Down

0 comments on commit c18ba63

Please sign in to comment.