-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.js
More file actions
55 lines (50 loc) · 1.22 KB
/
Copy pathdatabase.js
File metadata and controls
55 lines (50 loc) · 1.22 KB
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
var Map = require("collections/map");
module.exports = {
games: new Map(),
players: new Map(),
messages: new Map(),
rounds: new Map(),
ballots: new Map(),
};
/*
Custom function to retrieve more than one object from storage at once by
providing a list of id's.
*/
Map.prototype.getMany = function(keys) {
return keys.map(function(key) {
return this.get(key);
}, this);
};
/*
Custom function to retrieve only essential properties of an object.
*/
Map.prototype.listify = function(key) {
var object = this.get(key);
return {
id: object.id,
name: object.name
};
};
/*
Custom function to retrieve more than one object from storage at once by
providing a list of id's, and return only object's id and name.
*/
Map.prototype.listifyMany = function(keys) {
return this.getMany(keys).map(function(item) {
return {
id: item.id,
name: item.name
};
});
};
/*
Custom function to retrieve only essential properties of all objects.
*/
Map.prototype.listifyAll = function() {
return this.map(function(item) {
return {
id: item.id,
name: item.name
};
});
};