diff --git a/auth-web/src/components/auth/staff/continuation-application/HomeJurisdictionInformation.vue b/auth-web/src/components/auth/staff/continuation-application/HomeJurisdictionInformation.vue index b9bf3f9ff..bcafbc707 100644 --- a/auth-web/src/components/auth/staff/continuation-application/HomeJurisdictionInformation.vue +++ b/auth-web/src/components/auth/staff/continuation-application/HomeJurisdictionInformation.vue @@ -314,7 +314,8 @@ export default defineComponent({ if (!documentKey || !documentName) return // safety check state.isDownloading = true - await BusinessService.downloadDocument(documentKey, documentName).catch(error => { + const documentClass = 'CORP' + await BusinessService.downloadDocument(documentKey, documentName, documentClass).catch(error => { // eslint-disable-next-line no-console console.log('downloadDocument() error =', error) state.dialogTitle = 'Unable to download document' diff --git a/auth-web/src/services/business.services.ts b/auth-web/src/services/business.services.ts index 012567b80..f4c0d1813 100644 --- a/auth-web/src/services/business.services.ts +++ b/auth-web/src/services/business.services.ts @@ -159,50 +159,33 @@ export default class BusinessService { } /** - * Downloads a Minio document from Legal API and prompts browser to open/save it. - * @param documentKey the document key - * @param documentName the document filename - * @returns a promise to return the axios response or the error response - * @see CommonUtils.fileDownload() for a similar method + * Get download url from Document Record Service + * @param documentServiceId the unique id on Document Record Service + * @param documentName the file name to download. + * @param documentClass the document class defined for the document service. e.g. 'CORP' + * @returns void */ - static async downloadDocument (documentKey: string, documentName: string): Promise { + static async downloadDocument (documentServiceId: string, documentName: string, documentClass: string): Promise { // safety checks - if (!documentKey || !documentName) throw new Error('Invalid parameters') + if (!documentServiceId || !documentClass) throw new Error('Invalid parameters') - const url = `${ConfigHelper.getLegalAPIV2Url()}/documents/${documentKey}` - const config = { - headers: { 'Accept': 'application/pdf' }, - responseType: 'blob' as 'json' - } + const url = `${ConfigHelper.getLegalAPIV2Url()}/documents/drs/${documentClass}/${documentServiceId}` - return axios.get(url, config).then(response => { + axios.get(url).then(response => { if (!response) throw new Error('Null response') - /* solution below is from https://github.com/axios/axios/issues/1392 */ + const docUrl: string = response.data.documentURL + const link = document.createElement('a') + link.href = docUrl + link.download = documentName + link.target = '_blank' // This opens the link in a new browser tab - // it is necessary to create a new blob object with mime-type explicitly set - // otherwise only Chrome works like it should - const blob = new Blob([response.data], { type: 'application/pdf' }) - - // use Navigator.msSaveOrOpenBlob if available (possibly IE) - // warning: this is now deprecated - // ref: https://developer.mozilla.org/en-US/docs/Web/API/Navigator/msSaveOrOpenBlob - if (window.navigator && window.navigator['msSaveOrOpenBlob']) { - window.navigator['msSaveOrOpenBlob'](blob, documentName) - } else { - // for other browsers, create a link pointing to the ObjectURL containing the blob - const url = window.URL.createObjectURL(blob) - const a = window.document.createElement('a') - window.document.body.appendChild(a) - a.setAttribute('style', 'display: none') - a.href = url - a.download = documentName - a.click() - window.URL.revokeObjectURL(url) - a.remove() - } + // Append to the document and trigger the download + document.body.appendChild(link) + link.click() - return response + // Remove the link after the download is triggered + document.body.removeChild(link) }) } diff --git a/auth-web/tests/unit/components/HomeJurisdictionInformation.spec.ts b/auth-web/tests/unit/components/HomeJurisdictionInformation.spec.ts index 88443e23c..b33d77496 100644 --- a/auth-web/tests/unit/components/HomeJurisdictionInformation.spec.ts +++ b/auth-web/tests/unit/components/HomeJurisdictionInformation.spec.ts @@ -12,20 +12,20 @@ const localVue = createLocalVue() const vuetify = new Vuetify({}) const review = {} - +const documentClass = 'CORP' const filing = { continuationIn: { authorization: { date: '2024-07-01', files: [ { - fileKey: '0071dbd6-6095-46f6-b5e4-cc859b0ebf27.pdf', + fileKey: 'DS01000000', fileName: 'My Authorization Document.pdf' } ] }, foreignJurisdiction: { - affidavitFileKey: '007bd7bd-d421-49a9-9925-03ce561d044f.pdf', + affidavitFileKey: 'DS99999999', affidavitFileName: 'My Director Affidavit.pdf', country: 'CA', identifier: 'AB-5444', @@ -124,8 +124,11 @@ describe('HomeJurisdictionInformation component', () => { const button = wrapper.findAll('section').at(5).find('.download-authorization-btn') button.trigger('click') - expect(BusinessService.downloadDocument).toHaveBeenCalledWith('0071dbd6-6095-46f6-b5e4-cc859b0ebf27.pdf', - 'My Authorization Document.pdf') + expect(BusinessService.downloadDocument).toHaveBeenCalledWith( + 'DS01000000', + 'My Authorization Document.pdf', + documentClass + ) vi.clearAllMocks() })