-
Notifications
You must be signed in to change notification settings - Fork 0
/
contacts.js
63 lines (54 loc) · 1.41 KB
/
contacts.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
51
52
53
54
55
56
57
58
59
60
61
62
63
// https://www.npmjs.com/package/read-excel-file
const readXlsxFile = require('read-excel-file/node');
// TODO: Read from json file
const schema = {
'Netsuite Parent Account': {
prop: 'parentAccount',
type: String
},
'Netsuite ID#': {
prop: 'employerGroupId',
type: Number
},
'Customer Netsuite Company Name': {
prop: 'companyName',
type: String
},
'Billing Contact(s) Email Address': {
prop: 'emailAddresses',
type: String
},
'Client Engagement Manager': {
prop: 'engagementManagers',
type: String
},
'Invoice Type': {
prop: 'invoiceType',
type: String
}
}
class Contacts{
getContacts(callback){
readXlsxFile('./master_incentive_savings_template.xlsx', { schema }).then((data) => {
if(data.errors.length){
return console.log(data.errors);
}
let contacts = []
for(let i = 0; i < data.rows.length; i++){
contacts.push(new Contact(data.rows[i]))
}
callback(contacts);
});
}
}
class Contact{
constructor(contact){
const { employerGroupId, emailAddresses, engagementManagers, invoiceType, companyName } = contact;
this.employerGroupId = employerGroupId;
this.emailAddresses = emailAddresses.split('; ').join(',');
this.engagementManagers = engagementManagers.split('; ').join(',');
this.invoiceType = invoiceType;
this.companyName = companyName;
}
}
module.exports = Contacts;