forked from ealeksandrov/NodeAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateData.js
61 lines (49 loc) · 1.46 KB
/
generateData.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
var faker = require('faker');
var libs = process.cwd() + '/libs/';
var log = require(libs + 'log')(module);
var db = require(libs + 'db/mongoose');
var config = require(libs + 'config');
var User = require(libs + 'model/user');
var Client = require(libs + 'model/client');
var AccessToken = require(libs + 'model/accessToken');
var RefreshToken = require(libs + 'model/refreshToken');
User.remove({}, function(err) {
var user = new User({
username: config.get("default:user:username"),
password: config.get("default:user:password")
});
user.save(function(err, user) {
if(!err) {
log.info("New user - %s:%s", user.username, user.password);
}else {
return log.error(err);
}
});
});
Client.remove({}, function(err) {
var client = new Client({
name: config.get("default:client:name"),
clientId: config.get("default:client:clientId"),
clientSecret: config.get("default:client:clientSecret")
});
client.save(function(err, client) {
if(!err) {
log.info("New client - %s:%s", client.clientId, client.clientSecret);
} else {
return log.error(err);
}
});
});
AccessToken.remove({}, function (err) {
if (err) {
return log.error(err);
}
});
RefreshToken.remove({}, function (err) {
if (err) {
return log.error(err);
}
});
setTimeout(function() {
db.disconnect();
}, 3000);