forked from bcgov/supreme-court-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshared.ts
114 lines (107 loc) · 4.49 KB
/
shared.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { CourtDocumentType, DocumentData } from "@/types/shared"
import { splunkLog } from "@/utils/utils"
import base64url from "base64url"
import { v4 as uuidv4 } from "uuid"
export default {
openDocumentsPdf(
documentType: CourtDocumentType,
documentData: DocumentData
): void {
const fileName = this.generateFileName(documentType, documentData).replace(
/\//g,
"_"
)
const isCriminal = documentType == CourtDocumentType.Criminal
const documentId = documentData.documentId
? base64url(documentData.documentId)
: documentData.documentId
const correlationId = uuidv4()
switch (documentType) {
case CourtDocumentType.CSR:
window.open(
`${import.meta.env.BASE_URL}api/files/civil/court-summary-report/${
documentData.appearanceId
}/${encodeURIComponent(fileName)}?vcCivilFileId=${
documentData.fileId
}`
)
break
case CourtDocumentType.ROP:
window.open(
`${
import.meta.env.BASE_URL
}api/files/criminal/record-of-proceedings/${
documentData.partId
}/${encodeURIComponent(fileName)}?profSequenceNumber=${
documentData.profSeqNo
}&courtLevelCode=${documentData.courtLevel}&courtClassCode=${
documentData.courtClass
}`
)
break
default:
this.openRequestedTab(
`${
import.meta.env.BASE_URL
}api/files/document/${documentId}/${encodeURIComponent(
fileName
)}?isCriminal=${isCriminal}&fileId=${
documentData.fileId
}&CorrelationId=${correlationId}`,
correlationId
)
break
}
},
generateFileName(
documentType: CourtDocumentType,
documentData: DocumentData
): string {
const locationAbbreviation = (
documentData.location.match(/[A-Z]/g) || []
).join("")
switch (documentType) {
case CourtDocumentType.Civil:
return `${locationAbbreviation}-${documentData.courtLevel}-${documentData.fileNumberText}-${documentData.documentDescription}-${documentData.dateFiled}-${documentData.documentId}.pdf`
case CourtDocumentType.ProvidedCivil:
return `${locationAbbreviation}-${documentData.courtLevel}-${documentData.fileNumberText}-${documentData.documentDescription}-${documentData.appearanceDate}-${documentData.partyName}.pdf`
case CourtDocumentType.CSR:
return `${locationAbbreviation}-${documentData.courtLevel}-${documentData.fileNumberText}-${documentData.documentDescription}-${documentData.appearanceDate}.pdf`
case CourtDocumentType.Criminal:
return `${locationAbbreviation}-${documentData.courtLevel}-${documentData.courtClass}-${documentData.fileNumberText}-${documentData.documentDescription}-${documentData.dateFiled}-${documentData.documentId}.pdf`
case CourtDocumentType.ROP:
return `${locationAbbreviation}-${documentData.courtLevel}-${documentData.courtClass}-${documentData.fileNumberText}-${documentData.documentDescription}-${documentData.partId}.pdf`
case CourtDocumentType.CivilZip:
return `${locationAbbreviation}-${documentData.courtLevel}-${documentData.fileNumberText}-documents.zip`
case CourtDocumentType.CriminalZip:
return `${locationAbbreviation}-${documentData.courtLevel}-${documentData.courtClass}-${documentData.fileNumberText}-documents.zip`
default:
throw Error(`No file structure for type: ${documentType}`)
}
},
openRequestedTab(url, correlationId) {
const start = new Date()
const startStr = start.toLocaleString("en-US", {
timeZone: "America/Vancouver"
})
const startMsg = `Request Tracking - Frontend request to API - CorrelationId: ${correlationId} Start time: ${startStr}`
//console.log(startMsg);
splunkLog(startMsg)
const windowObjectReference = window.open(url)
if (windowObjectReference !== null) {
const end = new Date()
const endStr = start.toLocaleString("en-US", {
timeZone: "America/Vancouver"
})
const duration = (end.getTime() - start.getTime()) / 1000
const endMsg = `Request Tracking - API response received - CorrelationId: ${correlationId} End time: ${endStr} Duration: ${duration}s`
// eslint-disable-next-line
windowObjectReference.onload = (event) => {
if (windowObjectReference.document.readyState === "complete") {
//console.log(endMsg);
splunkLog(endMsg)
}
}
}
}
}