-
Notifications
You must be signed in to change notification settings - Fork 1
/
import.js
105 lines (75 loc) · 2.34 KB
/
import.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const csv = require('csv-parser');
const fs = require('fs');
const trello = require ('./trello.js')
let data = []
let boardId = "n6VBFMpa"
let log = console.log
fs.createReadStream('./engineer.csv')
.pipe(csv())
.on('data', (row) => {
data.push(row)
})
.on('end', () => {
importData()
});
let importData = async () => {
console.log(data)
let cardData = await trello.getAllBoardData(boardId)
let lists = await trello.getLists()
let listsAndCards = await trello.addCards(lists, cardData, ["Project Start Date", "SC","Not SC Eligible", "Skills", "Employee ID"])
// let trello.createCard
data = data.slice(0,1)
const reduceLoop = async _ => {
console.log('Start')
const sum = await fruitsToGet.reduce(async (promisedSum, fruit) => {
const sum = await promisedSum
const numFruit = await getNumFruit(fruit)
return sum + numFruit
}, 0)
console.log(sum)
console.log('End')
}
let results = data.reduce( async (acc, person)=>{
//person: Employee Id,First Name,Last Name,Work Email,Start Date,Job Role,Department,Post Code
//find their card
let existingCard = ""
let matchingCards = cardData.filter(c => {
if (c.customFieldItems.length > 0) {
let employeeIdCustomField = c.customFieldItems.filter(i => i.name === "Employee ID")
if (employeeIdCustomField.length > 0) {
let currentCardEmployeeId = employeeIdCustomField[0].value.number
if (currentCardEmployeeId === person["Employee Id"]) {
return c
}
}
}
})
return acc.then(()=>{
if (matchingCards.length == 0) {
return trello.createCard(
person.Department,
{
name: `${person["First Name"]} ${person["Last Name"]}`,
location: person["Post Code"],
customFields: {
Email: person["Work Email"],
"Employee ID": person["Employee Id"]
}
})
} else if (matchingCards.length > 1 ){
console.error("There are two cards with the same employee ID field : " + matchingCards.map(c => c.id).join(",") )
} else {
// one matching card - update its fields
// existingCard = matchingCards[0])
// trello.updateCard(existingCard.id,{
//
// })
}
})
},Promise.resolve())
let g = results;
// let createList =
// for each person, if there's already a card for them
// update the custom fields
// move them to the correct list (creating it if it doesnt exist)
}