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

replaced Minio with Document Record Service #760

Open
wants to merge 4 commits into
base: feature-drs-integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
26 changes: 9 additions & 17 deletions src/components/ContinuationIn/AuthorizationInformation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ import { AuthorizationProofIF, ExistingBusinessInfoIF } from '@/interfaces'
import { DateMixin, DocumentMixin } from '@/mixins'
import { CanJurisdictions, IntlJurisdictions, UsaJurisdiction } from '@bcrs-shared-components/jurisdiction/list-data'
import { JurisdictionLocation } from '@bcrs-shared-components/enums'
import { DocumentClasses } from '@/enums'

@Component({
components: {
Expand Down Expand Up @@ -285,28 +286,19 @@ export default class AuthorizationInformation extends Mixins(DateMixin, Document
if (!documentKey || !documentName) return // safety check

this.isDownloading = true
const documentClass = 'CORP'
try {
const docUrl: string = await this.getDownloadLink(documentKey, documentName, documentClass)
const link = document.createElement('a')
link.href = docUrl
link.download = documentName
link.target = '_blank' // This opens the link in a new browser tab

// Append to the document and trigger the download
document.body.appendChild(link)
link.click()

// Remove the link after the download is triggered
document.body.removeChild(link)
this.isDownloading = false
} catch (error) {
await this.downloadDocumentFromDRS(
documentKey,
documentName,
DocumentClasses.CORP
).catch(error => {
// eslint-disable-next-line no-console
console.log('downloadDocument() error =', error)
this.errorDialogTitle = 'Unable to download document'
this.errorDialogText = 'An error occurred while downloading the document. Please try again.'
this.errorDialog = true
}
})

this.isDownloading = false
}

@Watch('isValid', { immediate: true })
Expand Down
4 changes: 2 additions & 2 deletions src/components/ContinuationIn/AuthorizationProof.vue
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ export default class AuthorizationProof extends Mixins(DocumentMixin) {
this.isDocumentLoading = true
const res = await this.uploadDocumentToDRS(
file,
this.DOCUMENT_TYPES.contInAuthorization.class,
this.DOCUMENT_TYPES.contInAuthorization.type,
this.documentTypes.contInAuthorization.class,
this.documentTypes.contInAuthorization.type,
this.getTempId,
this.getContinuationInConsumerDocumentId
severinbeauvais marked this conversation as resolved.
Show resolved Hide resolved
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ export default class UnlimitedLiabilityCorporationInformation extends Mixins(Dat
this.isDocumentLoading = true
const res = await this.uploadDocumentToDRS(
file,
this.DOCUMENT_TYPES.affidavitDocument.class,
this.DOCUMENT_TYPES.affidavitDocument.type,
this.documentTypes.affidavitDocument.class,
this.documentTypes.affidavitDocument.type,
this.getTempId,
this.getContinuationInConsumerDocumentId
)
Expand Down
12 changes: 12 additions & 0 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
import { DocumentClasses } from '@/enums'

export const ADDRESSCHANGED = 'addressChanged'
export const ISFUTUREEFFECTIVE = 'isFutureEffective'
export const ISIMMEDIATE = 'isImmediate'
export const DOCUMENT_TYPES = {
contInAuthorization: {
class: DocumentClasses.CORP,
type: 'CNTO'
},
affidavitDocument: {
class: DocumentClasses.CORP,
type: 'DIRECTOR_AFFIDAVIT'
}
}
3 changes: 3 additions & 0 deletions src/enums/documentTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export enum DocumentClasses {
CORP = 'CORP'
}
1 change: 1 addition & 0 deletions src/enums/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export * from './routeNames'
export * from './ruleIds'
export * from './views'
export * from './errorTypes'
export * from './documentTypes'

// external enums
export {
Expand Down
40 changes: 24 additions & 16 deletions src/mixins/document-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AxiosResponse } from 'axios'
import { AxiosInstance as axios } from '@/utils'
import { PresignedUrlIF, PdfInfoIF } from '@/interfaces'
import { PdfPageSize } from '@/enums'
import { DOCUMENT_TYPES } from '@/constants'
import * as pdfjs from 'pdfjs-dist/legacy/build/pdf'

@Component({})
Expand All @@ -17,25 +18,17 @@ export default class DocumentMixin extends Vue {
validationErrorMsg: 'Document must be set to fit onto 8.5” x 11” letter-size paper.'
}
}
readonly DOCUMENT_TYPES = {
contInAuthorization: {
class: 'CORP',
type: 'CNTA'
},
affidavitDocument: {
class: 'CORP',
type: 'DIRECTOR_AFFIDAVIT'
}
}

pdfjsLib: any
documentTypes: any

// use beforeCreate() instead of created() to avoid type conflict with components that use this mixin
async beforeCreate (): Promise<void> {
// NB: we load the lib and worker this way to avoid a memory leak (esp in unit tests)
// NB: must use legacy build for unit tests not running in Node 18+
this.pdfjsLib = pdfjs
this.pdfjsLib.GlobalWorkerOptions.workerSrc = await import('pdfjs-dist/legacy/build/pdf.worker.entry')
this.documentTypes = DOCUMENT_TYPES
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For cleaner code, I think you can actually do import { DOCUMENT_TYPES as documentTypes } from ....

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used to use documentTypes in the components that extend documentMixin and that's why I redefined documentTypes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is, instead of using a local variable to rename DOCUMENT_TYPES, you can import it with the name you want, as per my example.

}

/**
Expand Down Expand Up @@ -258,21 +251,36 @@ export default class DocumentMixin extends Vue {
return axios.delete(url)
}

async getDownloadLink (
documentKey: string,
/**
* Download the specified file from Document Record Service.
* @param documentKey the unique id on Document Record Service
* @param documentClass the document class defined for the document service. e.g. 'CORP'
* @param documentName the document name to download
* @returns void
*/
async downloadDocumentFromDRS (documentKey: string,
documentName: string,
documentClass: string
): Promise<string> {
): Promise<void> {
// safety checks
if (!documentKey || !documentName) {
throw new Error('Invalid parameters')
}

const url = `documents/drs/${documentClass}/${documentKey}`

return axios.get(url).then(response => {
axios.get(url).then(response => {
if (!response) throw new Error('Null response')
return response.data.documentURL
const link = document.createElement('a')
link.href = response.data.documentURL
link.download = documentName
link.target = '_blank' // This opens the link in a new browser tab

// Append to the document and trigger the download
document.body.appendChild(link)
link.click()

// Remove the link after the download is triggered
document.body.removeChild(link)
})
}
}
1 change: 0 additions & 1 deletion src/utils/AxiosInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const instance = axios.create()
instance.interceptors.request.use(
request => {
// don't add bearer token for Minio requests
console.log(sessionStorage.getItem)
if (request.url?.startsWith('https://minio') || request.url.startsWith(sessionStorage.getItem('DRS_API_URL'))) {
return request
}
Expand Down
Loading