-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.js
148 lines (129 loc) · 4.07 KB
/
bootstrap.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
use votingSystemDb
// add constituency
const constituency1 = {
name: 'Doncaster North',
minimum_age: 18,
voting_system: 'FPTP',
};
const constRet = db.constituencies.insertOne(constituency1);
const constituency1Id = ObjectId(constRet.insertedId.str);
// add parties
const labourParty = {
name: 'Labour',
description: 'The Labour Party description'
};
const conservativeParty = {
name: 'Conservative',
description: 'The Conservative Party description'
};
const yorkshireParty = {
name: 'Yorkshire Party',
description: 'The Yorkshire Party description'
};
const partyRet = db.parties.insertMany([labourParty, conservativeParty, yorkshireParty]);
const labourPartyId = ObjectId(partyRet.insertedIds[0].str);
const conservativePartyId = ObjectId(partyRet.insertedIds[1].str);
const yorkshirePartyId = ObjectId(partyRet.insertedIds[2].str);
// add candidates
const labourCandidate = {
name: 'Edward Milliband',
party: labourPartyId,
description: 'Ed Milliband description',
};
const conservativeCandidate = {
name: 'Shade Adoh',
party: conservativePartyId,
description: 'Shade Adoh description',
};
const yorkshireCandidate = {
name: 'Charlie Bridges',
party: yorkshirePartyId,
description: 'Charlie Bridges description',
};
const candidateRet = db.candidates.insertMany([labourCandidate, conservativeCandidate, yorkshireCandidate]);
const labourCandidateStr = candidateRet.insertedIds[0].str;
const conservativeCandidateStr = candidateRet.insertedIds[1].str;
const yorkshireCandidateStr = candidateRet.insertedIds[2].str;
const labourCandidateId = ObjectId(labourCandidateStr);
const conservativeCandidateId = ObjectId(conservativeCandidateStr);
const yorkshireCandidateId = ObjectId(yorkshireCandidateStr);
// add campaign
const campaignRet = db.campaigns.insertOne({
name: 'Local Election for Doncaster North',
total_votes: 14,
candidates: [labourCandidateId, conservativeCandidateId, yorkshireCandidateId],
votes: [{[labourCandidateStr]: 5}, {[conservativeCandidateStr]: 2}, {[yorkshireCandidateStr]: 7}],
campaign_type: 'Local Election',
active: 'Active',
constituencies: [constituency1Id],
start_date: Date.now(),
end_date: Date.now() + 86400000
});
const campaign1Id = ObjectId(campaignRet.insertedId.str);
// add address
const address1 = {
line_one: '10 Barn Road',
line_two: '',
town: 'Sheffield',
county: 'South Yorkshire',
country: 'United Kingdom',
postcode: 'S6 7AD',
constituency: constituency1Id
};
const addressRet = db.addresses.insertOne(address1);
const address1Id = ObjectId(addressRet.insertedId.str);
// add voter
// voter:voterPass
const voter = {
username: 'voter',
name: 'John Smith',
email: '[email protected]',
password: '$2a$10$F6m9.osfkImT6JWlRheyre08he0RodU6ZPQcJwJgINmQhlWF3K2au',
authentication_attempts: 0,
salt: '$2a$10$F6m9.osfkImT6JWlRheyre',
voted: false,
date_of_birth: new Date('01/01/01'),
address: address1Id,
__t: 'voter'
};
const voterRet = db.users.insertOne(voter);
const voter1Id = ObjectId(voterRet.insertedId.str);
// add admin
// admin:adminPass
const admin = {
username: 'admin',
name: 'Jane Doe',
email: '[email protected]',
password: '$2a$10$Zqxnz0Zg37fZLixoFfBYgeSsHUe61tVpa7wCDg2LE8hLFzsAi2guK',
authentication_attempts: 0,
salt: '$2a$10$Zqxnz0Zg37fZLixoFfBYge',
__t: 'admin'
};
db.users.insert(admin);
const pollingStation = {
address: address1Id,
open_time: new Date().toISOString(),
close_time: new Date(Date.now() + 86400000).toISOString()
};
const pollingStationRet = db.pollingstations.insertOne(pollingStation);
const pollingStation1Id = ObjectId(pollingStationRet.insertedId.str);
// add auditor
// auditor:auditorPass
const auditor = {
username: 'auditor',
name: 'Bob Jones',
email: '[email protected]',
password: '$2a$10$7A.zv9h/SGk7c8Q9jjSrT.m2PvJ6KiuPed/RdcVKCrHnhuan2pCTq',
authentication_attempts: 0,
salt: '$2a$10$7A.zv9h/SGk7c8Q9jjSrT.',
__t: 'auditor',
polling_station: pollingStation1Id
};
db.users.insert(auditor);
const system = {
station: pollingStation1Id,
voters: [voter1Id],
campaigns: [campaign1Id],
language: 'en-gb',
};
db.systems.insert(system);