-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathseed.js
134 lines (109 loc) · 3.27 KB
/
seed.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
This seed file is only a placeholder. It should be expanded and altered
to fit the development of your application.
It uses the same file the server uses to establish
the database connection:
--- server/db/index.js
The name of the database used is set in your environment files:
--- server/env/*
This seed file has a safety check to see if you already have users
in the database. If you are developing multiple applications with the
fsg scaffolding, keep in mind that fsg always uses the same database
name in the environment files.
*/
var xlsx = require('xlsx');
var workbook = xlsx.readFile('sd.xlsx');
var sheetNames = workbook.SheetNames;
var chalk = require('chalk');
var db = require('./server/db');
var User = db.model('user');
var Client = db.model('client');
var JobLocs = db.model('jobLoc');
var Promise = require('sequelize').Promise;
var seedUsers = function () {
var users = [
{
userName: 'Jane',
email: '[email protected]',
password: 'password'
},
{
userName: 'Barack',
email: '[email protected]',
password: 'potus'
}
];
var creatingUsers = users.map(function (userObj) {
return User.create(userObj);
});
return Promise.all(creatingUsers);
};
var seedClients = function () {
var clients = xlsx.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]]);
// return Client.bulkCreate(xlsx.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]]))
// var clients = [
// {
// First_Name: 'John',
// Last_Name: 'Doe',
// SSN: 111223333,
// DOB: '1940',
// Gender: '1',
// race: '2',
// VeteranStatus: true,
// hasBC: true,
// hasSSC: false,
// phone: '8885550000',
// }
// ];
var creatingClients = clients.map(function (clientObj) {
return Client.create(clientObj);
});
return Promise.all(creatingClients);
};
var seedJobs = function () {
var jobs = [
{
employer: 'Popeyes Louisiana Chicken',
description: 'Cashier position needs to be fulfilled within a month',
industry: 'restaurant',
latitude: 38.661139,
longitude: -90.216048,
},
{
employer: 'St. Louis Public Library',
description: 'Need someone to organize books',
industry: 'education',
latitude: 38.667472,
longitude: -90.211773,
},
{
employer: 'OReily Auto Shop',
description: 'Manual laborer needed',
industry: 'auto',
latitude: 38.669365,
longitude: -90.235661,
},
];
var creatingJobs = jobs.map(function (jobObj) {
return JobLocs.create(jobObj);
});
return Promise.all(creatingJobs);
};
db.sync({ force: true })
.then(function () {
return seedUsers();
})
.then(function () {
return seedClients();
})
.then(function () {
return seedJobs();
})
.then(function () {
console.log(chalk.green('Seed successful!'));
process.exit(0);
})
.catch(function (err) {
console.error(err);
process.exit(1);
});