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