-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmock_manage.js
executable file
·69 lines (56 loc) · 1.45 KB
/
mock_manage.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
'use strict';
var slugify = require('slugify');
var optimist = require('optimist');
var Player = require('./models/player');
var Tournament = require('./models/tournament');
function addUser() {
var user = 'fake_user_' + Math.floor((Math.random() * 999) + 100);
var code = [
'function Algorithm () { ',
' this.move = function (availableColumns, gameBoard) { ',
' return availableColumns[0];',
' }',
'}'].join('');
Player({
username: user,
github: 'https://dummy.uri/' + user,
email: user + '@mail.me',
code: code,
draft: code,
})
.save(function (err, player) {
console.log(user + ' created.');
process.exit();
});
}
function addTournament() {
var name = 'Lig4 Championship ' + Math.floor((Math.random() * 999) + 100);
// Set all as active = false.
Tournament.update({ active: true }, { active: false }, { multi: true }, function (err) {
// adds a new Tournament
Tournament({
name: name,
active: true,
isOpen: true,
slug: slugify(name).toLowerCase(),
texts: {
title: name
}
})
.save(function (err, tournament) {
console.log(tournament.name + ' created.');
process.exit();
});
});
}
switch (optimist.argv.add) {
case 'user':
addUser();
break;
case 'tournament':
addTournament();
break
default:
console.log('Invalid option')
process.exit();
}