-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.js
72 lines (63 loc) · 1.96 KB
/
database.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
const fs = require('fs')
const csv = require('csv-parser')
// Database is indexed by:
const restaurant = {};
const employees = [];
const gender = {};
const country = {};
const type = {};
const division = {};
// Reads through all csv files to create our database object
const csvFiles = ['fogoDeChao.csv', 'gamine.csv', 'hookfish.csv', 'zenYai.csv'];
for (const csvFile of csvFiles) {
fs.createReadStream(csvFile)
.pipe(csv())
.on('error', (e) => console.log(e))
.on('data', function (row) {
if (!gender[row.Gender]) gender[row.Gender] = [];
gender[row.Gender].push(row)
if (!country[row.Country]) country[row.Country] = [];
country[row.Country].push(row)
if (!type[row.Type] && !type[row.employmentType]) {
if (row.Type) {
type[row.Type] = [];
type[row.Type].push(row)
}
if (row.employmentType) {
type[row.employmentType] = [];
type[row.employmentType].push(row)
}
} else {
if (row.Type) {
type[row.Type].push(row)
}
if (row.employmentType) {
type[row.employmentType].push(row)
}
}
if (!division[row.Division] && !division[row.department]) {
if (row.Division) {
division[row.Division] = [];
division[row.Division].push(row)
}
if (row.department) {
division[row.department] = [];
division[row.department].push(row)
}
} else {
if (row.Division) {
division[row.Division].push(row)
}
if (row.department) {
division[row.department].push(row)
}
}
employees.push(row);
const restaurantName = csvFile.split(".csv")[0];
if (!restaurant[restaurantName]) restaurant[restaurantName] = [];
restaurant[restaurantName].push(row);
}).on('end', function () {
console.log()
})
}
module.exports = { restaurant, employees, gender, country, type, division }