forked from nghoangphu/o2o
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample-models.jj
52 lines (49 loc) · 1.62 KB
/
sample-models.jj
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
var async = require('async');
module.exports = function(app) {
var Role = app.models.Role;
var RoleMapping = app.models.RoleMapping;
var mysqlDs = app.dataSources.mysqlDs;
/*
async.parallel({
users: async.apply(createUsers),
}, function(err, results) {
if (err) {console.log('Error create users'); throw err;}
createJobs(results.users, function(err) {
if (err) {console.log('Error create jobs'); throw err;}
console.log('> models create successfully');
});
});
*/
createUsers(function(err, result) {
if (err) throw err;
createJobs(result, function(err) {
if (err) throw err;
console.log('> models create successfully');
});
});
function createUsers(cb) {
// mysqlDs.automigrate('user', function(err) {
// if (err) return cb(err);
var User = app.models.user;
User.create([
{username: 'Hoang Phu', email: '[email protected]', password: 'hoangphu'},
{username: 'Phuong Lan', email: '[email protected]', password: 'phuonglan'}
], cb);
// });
}
function createJobs(users, cb) {
// mysqlDs.automigrate('Jobs', function(err) {
// if (err) return cb(err);
var Job = app.models.Jobs;
Job.create([
{
serviceName: 'Service name for Phu',
serverFirstName: 'Server first name for Phu',
ownerId: users[0].id
},
{serviceName: 'Service name 1 for Lan', serverFirstName: 'Server first name 1 for Lan', ownerId: users[1].id},
{serviceName: 'Service name 2 for Lan', serverFirstName: 'Server first name 2 for Lan', ownerId: users[1].id}
], cb);
// });
}
}