forked from softwerkskammer/Agora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
initialDBSetup.js
87 lines (79 loc) · 4.02 KB
/
initialDBSetup.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
'use strict';
require('./configure'); // initializing parameters
var beans = require('nconf').get('beans');
var membersPersistence = beans.get('membersPersistence');
var groupsPersistence = beans.get('groupsPersistence');
var sympaPersistence = beans.get('sympaPersistence');
var Group = beans.get('group');
var Member = beans.get('member');
var async = require('async');
var really = process.argv[2];
if (!really || really !== 'really') {
console.log('If you really want to init the db, append "really" to the command line.');
process.exit();
}
function logResult(err, message) {
if (err) { return console.log('An error occurred: ' + err); }
console.log(message);
}
async.parallel(
[
function createLists(callback) {
var lists = [
{id: 'alle'},
{id: 'commercial'},
{id: 'neueplattform'},
{id: 'craftsmanswap'},
{id: 'internet'}
];
async.map(lists, function (list, callback) {
sympaPersistence.save({"id" : list.id, "users": []}, function (err) {
callback(err, 'List "' + list.id + '"');
});
}, function (err, results) {
callback(err, results.join(', '));
});
},
function createGroups(callback) {
var groups = [
{id: 'alle', emailPrefix: 'alleAlle', description: 'D-Scription', shortName: 'Alle', longName: 'Alle', type: 'Themengruppe', color: '#ff0000', mapX: '100', mapY: '100'},
{id: 'commercial', emailPrefix: 'commercial', description: 'D-Scription', longName: 'Commercial', type: 'Regionalgruppe', color: '#ff00ff', mapX: '200', mapY: '100', shortName: 'C'},
{id: 'neueplattform', emailPrefix: 'neueplattform', description: 'D-Scription', longName: 'Agora', type: 'Regionalgruppe', color: '#ffff00', mapX: '180', mapY: '100', shortName: 'A'},
{id: 'craftsmanswap', emailPrefix: 'craftsmanswap', description: 'D-Scription', longName: 'Craftsman Swaps', type: 'Regionalgruppe', color: '#0000ff', mapX: '100', mapY: '200', shortName: 'CS'},
{id: 'internet', emailPrefix: 'internet', description: 'D-Scription', longName: 'Virtual Group', type: 'Regionalgruppe', color: '#00ff00', mapX: '100', mapY: '300', shortName: 'VG'}
];
async.map(groups, function (group, callback) {
group.description = '';
groupsPersistence.save(new Group(group), function (err) {
callback(err, 'Group "' + group.id + '"');
});
}, function (err, results) {
callback(err, results.join(', '));
});
},
function createMembers(callback) {
var members = [
{id: 'auth01', nickname: 'Testi', firstname: 'Ich', lastname: 'Tester', email: '[email protected]', location: 'Hier', profession: 'Testbeauftragter', reference: '-', authentications: ['auth01']},
{id: 'auth02', nickname: 'Schumi', firstname: 'Michael', lastname: 'Schumacher', email: '[email protected]', location: 'Hürth', profession: 'Ex-Rennfahrer', reference: '-', authentications: ['auth02']},
{id: 'auth03', nickname: 'Balli', firstname: 'Michael', lastname: 'Ballack', email: '[email protected]', location: 'Görlitz', profession: 'Ex-Fußballer', reference: '-', authentications: ['auth03']},
{id: 'auth04', nickname: 'Jamie', firstname: 'James', lastname: 'Hetfield', email: '[email protected]', location: 'Downey, LA', profession: 'Musiker', reference: '-', authentications: ['auth04']}
];
async.map(members, function (member, callback) {
membersPersistence.getById(member.id, function (err, existingMember) {
if (existingMember) {return callback(null, 'Member "' + member.nickname + '" (already existing)'); }
membersPersistence.save(new Member(member).state, function (err) {
callback(err, 'Member "' + member.id + '"');
});
});
}, function (err, results) {
callback(err, results.join(', '));
});
}
],
function (err, loggingmessages) {
console.log('Filling the database...');
logResult(err, loggingmessages.join('\n'));
console.log('were created.');
process.exit();
}
);