-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueries.js
78 lines (65 loc) · 2.17 KB
/
queries.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
const Game = require('./models/game');
const Player = require('./models/player');
const PlayerStatistics = require('./models/playerStatistics');
async function findGameById(game_id) {
var query = {"game_id":game_id}; // this is how to query based on size of array
var entries = Game.find(query);
var result = await entries.exec();
}
async function findAllPlayedGames() {
var entries = Game.find();
var result = await entries.exec();
return result;
}
async function findCurrentPlayers() {
var goalies = [8476899, 8478492, 8477472];
var query = { "_id" : { "$nin": goalies } };
var players = Player.find(query);
var result = await players.exec();
return result;
}
async function getPlayersByPointsDescending() {
var mysort = { points : -1 };
var players = PlayerStatistics.find().sort(mysort);
var result = await players.exec();
return result;
}
async function getForwardsIds() {
var forwards = ["LW", "C", "RW"]
var query = { "position" : { "$in": forwards } };
var mysort = { points : -1 };
var players = Player.find(query, {_id: 1}).sort(mysort);
var forwardIds = await players.exec();
return forwardIds;
}
async function getDefenseIds() {
var query = { "position" : "D" };
var mysort = { points : -1 };
var players = Player.find(query, {_id: 1}).sort(mysort);
var forwardIds = await players.exec();
return forwardIds;
}
async function getForwardsByPointsDescending() {
var forwardIds = await getForwardsIds();
var mysort = { points : -1 };
var query = { "_id" : { "$in": forwardIds } };
var players = PlayerStatistics.find(query).sort(mysort);
var result = await players.exec();
return result;
}
async function getDefenseByPointsDescending() {
var defenseIds = await getDefenseIds();
var mysort = { points : -1 };
var query = { "_id" : { "$in": defenseIds } };
var players = PlayerStatistics.find(query).sort(mysort);
var result = await players.exec();
return result;
}
module.exports = {
findGameById,
findAllPlayedGames,
findCurrentPlayers,
getPlayersByPointsDescending,
getForwardsByPointsDescending,
getDefenseByPointsDescending
}