-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (30 loc) · 1.25 KB
/
index.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
var fs = require('fs');
var { parse, CsvError } = require('csv-parse');
var path = require('path');
const { createUser, assignRole } = require('./api');
const createUsersInCentral = async () => {
try {
const filePath = path.join(__dirname, './csv/data.csv');
console.log("Starting user creation on central")
fs.createReadStream(filePath)
.pipe(parse({ delimiter: ',' }))
.on('data', async function (csvrow) {
// Creating user in central
let userRes = await createUser(csvrow[0], csvrow[1])
if (userRes && userRes.id) {
let assignRes = await assignRole(userRes.id);
if (assignRes && assignRes.success) {
console.log(csvrow[0], " created on central as Data Collector")
} else {
console.log("Couldn't assign Data Collector role to user: ", csvrow[0])
}
} else {
console.log("Couldn't create user: ", csvrow[0])
}
// Assigning Data Collector role to user in central
})
} catch (err) {
console.log("An error occured: ", err);
}
}
createUsersInCentral();