This repository has been archived by the owner on Jun 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extractor.js
50 lines (44 loc) · 1.64 KB
/
extractor.js
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
const _ = require('lodash')
const urlTemplate = process.env.URL_TEMPLATE
var Extractor = {
extract: (recordMap, records) => {
_.forEach(records, (r) => {
const id = r.ADCVD_Case__r.Id
if (!_.isNil(recordMap[id])) return
let htsNums = null
let htsNumsRaw = null
let htsNumberPrefixes = []
if (r.Harmonized_Tariff_Schedules__r) {
htsNums = r.Harmonized_Tariff_Schedules__r.records.map(hts => hts.HTS_Number_Formatted__c)
htsNumsRaw = r.Harmonized_Tariff_Schedules__r.records.map(hts => hts.HTS_Number__c)
htsNumberPrefixes = Extractor.transformHtsNumPrefixes(htsNumsRaw)
}
const newEntry = {
Id: r.ADCVD_Case__r.Id,
caseNumber: r.ADCVD_Case__r.ADCVD_Case_Number__c,
country: r.ADCVD_Case__r.Country_Text__c,
commodity: r.ADCVD_Case__r.Commodity__c,
productName: r.ADCVD_Case__r.Product__c,
productNameSanitized: r.ADCVD_Case__r.Product__c.replace(/,/g, ' ').replace(/\s+/g, ' '),
productShortName: r.ADCVD_Case__r.Product_Short_Name__c,
url: urlTemplate + r.ADCVD_Case__r.ADCVD_Case_Number__c,
htsNums: htsNums,
htsNumsRaw: htsNumsRaw,
htsNumberPrefixes: htsNumberPrefixes
}
console.log(`adding ${newEntry.caseNumber}`)
recordMap[id] = newEntry
})
return recordMap
},
transformHtsNumPrefixes: (htsNumsRaw) => {
const htsNumberPrefixes = []
_.forEach(htsNumsRaw, function (htsNum) {
for (var i = 2; i <= htsNum.length; i++) {
htsNumberPrefixes.push(htsNum.substr(0, i))
}
})
return _.uniq(htsNumberPrefixes)
}
}
module.exports = Extractor