Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Record Service Continuation In Integration #3203

Open
wants to merge 3 commits into
base: feature-drs-integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
55 changes: 19 additions & 36 deletions auth-web/src/services/business.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AxiosResponse> {
static async downloadDocument (documentServiceId: string, documentName: string, documentClass: string): Promise<void> {
// 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)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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()
})
Expand Down
Loading