-
Notifications
You must be signed in to change notification settings - Fork 0
/
participants.js
88 lines (76 loc) · 2.28 KB
/
participants.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
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
var XLSX = require('xlsx');
var moment = require('moment');
var _ = require('lodash');
function createParticipant(participant) {
var firstName = participant['Ticket First Name'] || '';
var lastName = participant['Ticket Last Name'] || '';
if (firstName.trim() && lastName.trim()) {
var fullName = [firstName.trim(), lastName.trim()].join(' ');
} else {
console.log(
'Unassigned ticket for ticket ' +
participant['Ticket Reference'] +
'. Using order name ' + participant['Order Name']
);
var fullName = participant['Order Name'];
}
var company = participant['Ticket Company Name'];
var email = participant['Ticket Email'];
var ticketId = participant['Ticket Reference'];
var crewType = participant['Crew type'];
var number = participant['Number'];
var modifiedDate = moment(
participant['Ticket Last Updated Date'],
'MM/DD/YY'
); // Last Updated | Created
var twitter =
participant['Twitter handle to print on your badge'] &&
participant['Twitter handle to print on your badge'] !== '-'
? '@' +
_.trimStart(
participant['Twitter handle to print on your badge']
.replace('https://twitter.com/', '')
.replace('https://github.com/', ''),
'@'
)
: null;
return {
fullName,
company,
modifiedDate,
twitter,
firstName,
lastName,
email,
ticketId,
crewType,
number
};
}
function participants(filename, startingDate) {
var workbook = XLSX.readFile(filename);
var worksheet = workbook.Sheets[workbook.SheetNames[0]];
var participantsRaw = XLSX.utils.sheet_to_json(worksheet);
var participantsProcessed = participantsRaw
.map(function (participant) {
return createParticipant(participant);
})
.filter(function (p) {
if (startingDate) {
if (p.modifiedDate.isSameOrAfter(startingDate)) {
console.log('Modified date: ' + p.modifiedDate.format());
STATS.filteredByDate++;
return true;
} else {
return true; // Set to false when filtering by date
}
} else {
return true;
}
})
.sort(function (a, b) {
return a.fullName.localeCompare(b.fullName);
});
return participantsProcessed;
}
module.exports = participants;