forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload-ssl-by-key.js
More file actions
34 lines (31 loc) · 989 Bytes
/
load-ssl-by-key.js
File metadata and controls
34 lines (31 loc) · 989 Bytes
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
import DataLoader from 'dataloader'
import { t } from '@lingui/macro'
export const loadSslByKey = ({ query, userKey, i18n }) =>
new DataLoader(async (keys) => {
let cursor
try {
cursor = await query`
WITH ssl
FOR sslScan IN ssl
FILTER sslScan._key IN ${keys}
RETURN MERGE({ id: sslScan._key, _type: "ssl" }, sslScan)
`
} catch (err) {
console.error(
`Database error occurred when user: ${userKey} running loadSslByKey: ${err}`,
)
throw new Error(i18n._(t`Unable to find SSL scan(s). Please try again.`))
}
const sslMap = {}
try {
await cursor.forEach((sslScan) => {
sslMap[sslScan._key] = sslScan
})
} catch (err) {
console.error(
`Cursor error occurred when user: ${userKey} running loadSslByKey: ${err}`,
)
throw new Error(i18n._(t`Unable to find SSL scan(s). Please try again.`))
}
return keys.map((key) => sslMap[key])
})