From 8bcd81fc6e6fd248015d70569b9fed10c85866d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9verin=20Beauvais?= Date: Mon, 11 Dec 2023 17:30:58 -0800 Subject: [PATCH] 18640 More amalgamating fetch / validations work (#593) * - app version = 5.6.11 - imported latest BusinessLookup shared component - updated fetchBusinessInfo return object - simplified Amalg Businesses button and panel logic - added Cancel button to Foreign panel - added snackbar for save business errors - deleted debugging template code * - added fetch for business filings (for more validations) - renamed AmalgamatingStatuses -> AmlStatuses - added AmlTypes enum and replaced strings - added some properties to TING business object (for more validations) - added LegalServices.fetchFilings() - misc updates * - changed all to allSettled so I can get partial fetches - fall back to lookup properties if some fetches fail (eg, not amalgamated) - added empty table message - temporarily start with empty (instead of pre-populated) table * wip * wip * - logic cleanup * - added proper check for limited restoration - now fetch only first filing (to check for FED) - fixed fetchFirstOrOnlyFiling() (for use with array response) * - fixed unit test --------- Co-authored-by: Severin Beauvais --- package-lock.json | 12 +- package.json | 4 +- src/App.vue | 6 +- .../Amalgamation/AmalgamatingBusinesses.vue | 212 +++++++++------- .../Amalgamation/BusinessStatus.vue | 72 +++--- src/components/Amalgamation/BusinessTable.vue | 45 ++-- .../Amalgamation/BusinessTableSummary.vue | 27 ++- src/enums/amalgamationEnums.ts | 11 +- .../amalgamation-state-interface.ts | 14 +- src/mixins/amalgamation-mixin.ts | 84 +++---- src/services/legal-services.ts | 70 ++++-- src/store/state/state-model.ts | 228 +++++++++--------- src/store/store.ts | 8 + tests/unit/legal-services.spec.ts | 43 ++-- 14 files changed, 463 insertions(+), 373 deletions(-) diff --git a/package-lock.json b/package-lock.json index d7da19105..f988245a5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,18 @@ { "name": "business-create-ui", - "version": "5.6.10", + "version": "5.6.11", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "business-create-ui", - "version": "5.6.10", + "version": "5.6.11", "dependencies": { "@babel/compat-data": "^7.21.5", "@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.4", + "@bcrs-shared-components/business-lookup": "1.2.5", "@bcrs-shared-components/certify": "2.1.15", "@bcrs-shared-components/completing-party": "2.1.30", "@bcrs-shared-components/confirm-dialog": "1.2.1", @@ -271,9 +271,9 @@ } }, "node_modules/@bcrs-shared-components/business-lookup": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/@bcrs-shared-components/business-lookup/-/business-lookup-1.2.4.tgz", - "integrity": "sha512-YkMgEJH5Ant5zlqfZBZda8U95x0ZJOxxifh4XLADZEdFdznf2NrvwlQI0fOT5mL1Zp9OyrJa/uOgPWuh2KeDKQ==", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/@bcrs-shared-components/business-lookup/-/business-lookup-1.2.5.tgz", + "integrity": "sha512-HEqjK+MxkweJm+YuvRQ0/Z4Nw4Whk7kdx56awvYBijlf0mC6xylbN2Pr2hmqDX/kxiieNZBpjtCtA83/Pm/3uw==", "dependencies": { "@bcrs-shared-components/interfaces": "^1.1.2", "lodash": "4.17.21", diff --git a/package.json b/package.json index 04a0645d3..d4cceb8f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "business-create-ui", - "version": "5.6.10", + "version": "5.6.11", "private": true, "appName": "Create UI", "sbcName": "SBC Common Components", @@ -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.4", + "@bcrs-shared-components/business-lookup": "1.2.5", "@bcrs-shared-components/certify": "2.1.15", "@bcrs-shared-components/completing-party": "2.1.30", "@bcrs-shared-components/confirm-dialog": "1.2.1", diff --git a/src/App.vue b/src/App.vue index 7edfe4609..0e4944131 100644 --- a/src/App.vue +++ b/src/App.vue @@ -249,7 +249,7 @@ import * as Views from '@/views' // Mixins, interfaces, etc import { CommonMixin, DateMixin, FilingTemplateMixin, NameRequestMixin } from '@/mixins' -import { AccountInformationIF, AddressIF, BreadcrumbIF, BusinessIF, BusinessWarningIF, CompletingPartyIF, +import { AccountInformationIF, AddressIF, BreadcrumbIF, BusinessWarningIF, CompletingPartyIF, ConfirmDialogType, EmptyFees, FeesIF, FilingDataIF, NameRequestIF, OrgInformationIF, PartyIF, ResourceIF, StepIF } from '@/interfaces' import { AmalgamationRegResources, DissolutionResources, IncorporationResources, RegistrationResources, @@ -1158,9 +1158,7 @@ export default class App extends Mixins(CommonMixin, DateMixin, FilingTemplateMi /** Fetches and stores business info. */ private async loadBusinessInfo (businessId: string): Promise { - const response = await LegalServices.fetchBusinessInfo(businessId) - - const business = response?.data?.business as BusinessIF + const business = await LegalServices.fetchBusinessInfo(businessId).catch(() => {}) if (!business) { throw new Error('Invalid business info') diff --git a/src/components/Amalgamation/AmalgamatingBusinesses.vue b/src/components/Amalgamation/AmalgamatingBusinesses.vue index 0e26540e1..2cd13b5ba 100644 --- a/src/components/Amalgamation/AmalgamatingBusinesses.vue +++ b/src/components/Amalgamation/AmalgamatingBusinesses.vue @@ -6,7 +6,7 @@ color="primary" class="btn-outlined-primary" :disabled="isAddingAmalgamatingBusiness || isAddingAmalgamatingForeignBusiness" - @click="onAddBusinessClick()" + @click="isAddingAmalgamatingBusiness = true" > mdi-domain-plus Add an Amalgamating Business @@ -19,7 +19,7 @@ color="primary" class="ml-2 btn-outlined-primary" :disabled="isAddingAmalgamatingBusiness || isAddingAmalgamatingForeignBusiness" - @click="onAddForeignBusinessClick()" + @click="isAddingAmalgamatingForeignBusiness = true" > mdi-domain-plus Add an Amalgamating Foreign Business @@ -46,8 +46,8 @@ class="ml-8" > Enter the name or the incorporation number of the registered BC business - to add to this application. - + to add to this application. + + @@ -64,7 +65,7 @@ large outlined color="primary" - @click="addAmalgamatingBusinessCancel()" + @click="isAddingAmalgamatingBusiness = false" > Cancel @@ -95,6 +96,20 @@ class="ml-8" > **TODO** + + + + Cancel + + @@ -102,30 +117,25 @@ - + + {{ snackbarText }} + + + ) => void + @Action(useStore) pushAmalgamatingBusiness!: (x: AmalgamatingBusinessIF) => void @Action(useStore) setAmalgamatingBusinessesValid!: (x: boolean) => void // Local properties initialBusinessLookupObject = EmptyBusinessLookup businessTableValid = false + snackbar = false + snackbarText = '' // Button properties isAddingAmalgamatingBusiness = false isAddingAmalgamatingForeignBusiness = false - readonly BusinessLookupServices = BusinessLookupServices + async saveAmalgamatingBusiness (businessLookup: BusinessLookupResultIF): Promise { + // 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)) - // Cancel button in "Add an Amalgamating Business" is pressed. - addAmalgamatingBusinessCancel (): void { - this.isAddingAmalgamatingBusiness = false - this.setAmalgamatingBusinessesValid(true) - } + const authInfo = data[0] + const businessInfo = data[1] + const addresses = data[2] + const firstFiling = data[3] - // "Add an Amalgamating Business" button is pressed. - onAddBusinessClick (): void { - this.isAddingAmalgamatingBusiness = true - this.isAddingAmalgamatingForeignBusiness = false - this.setAmalgamatingBusinessesValid(false) - } + // Check for unaffiliated business. + if (!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.' + this.snackbar = true + return + } - // "Add an Amalgamating Foreign Business" button is pressed. - onAddForeignBusinessClick (): void { - this.isAddingAmalgamatingBusiness = false - this.isAddingAmalgamatingForeignBusiness = true - this.setAmalgamatingBusinessesValid(false) - } + // Otherwise, assume the business is unaffiliated and add it to the table. + this.pushAmalgamatingBusiness({ + type: AmlTypes.LEAR, + role: AmlRoles.AMALGAMATING, + identifier: businessLookup.identifier, + name: businessLookup.name, + legalType: businessLookup.legalType as unknown as CorpTypeCd + }) - async saveAmalgamatingBusiness (businessLookup: BusinessLookupIF): Promise { - let business = null + // Close the "Add an Amalgamating Business" panel. + this.isAddingAmalgamatingBusiness = false - // 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] + return } - // 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 (business) { - const amalgamatingBusinesses = this.getAmalgamatingBusinesses + // Check for Legal API fetch issues. + if (!businessInfo || !addresses || !firstFiling) { + this.snackbarText = 'Unable to add that business.' + this.snackbar = true + return + } - 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 (!amalgamatingBusinesses.find((b: any) => b.identifier === business.identifier)) { - amalgamatingBusinesses.push(tingBusiness) - - // Set the new amalgamated businesses array in the store. - this.setAmalgamatingBusinesses(amalgamatingBusinesses) - } + // Verify that identifier doesn't already exist. + if (this.getAmalgamatingBusinesses.find((b: any) => b.identifier === businessInfo.identifier)) { + this.snackbarText = 'Business is already in table.' + this.snackbar = true + return } - // Close the "Add an Amalgamating Business" Panel. + // 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 => { + // 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() + } + + // Add the new business to the amalgamating businesses list. + this.pushAmalgamatingBusiness(tingBusiness) + + // Close the "Add an Amalgamating Business" panel. this.isAddingAmalgamatingBusiness = false - this.setAmalgamatingBusinessesValid(true) } /** Sets validity according to various flags. */ diff --git a/src/components/Amalgamation/BusinessStatus.vue b/src/components/Amalgamation/BusinessStatus.vue index d10b4dd4f..d04a10ff7 100644 --- a/src/components/Amalgamation/BusinessStatus.vue +++ b/src/components/Amalgamation/BusinessStatus.vue @@ -25,24 +25,24 @@ diff --git a/src/components/Amalgamation/BusinessTableSummary.vue b/src/components/Amalgamation/BusinessTableSummary.vue index 3c4faa109..1b47295c7 100644 --- a/src/components/Amalgamation/BusinessTableSummary.vue +++ b/src/components/Amalgamation/BusinessTableSummary.vue @@ -10,6 +10,14 @@ + + +

+ No businesses added +

+ + + -