2020-10-05 09:16:21 +00:00
|
|
|
import mongodb from '@ioc:Mongodb/Database'
|
2020-10-05 17:49:03 +00:00
|
|
|
import { Collection } from 'mongodb'
|
2020-10-05 09:16:21 +00:00
|
|
|
|
|
|
|
|
class MatchRepository {
|
|
|
|
|
private season?: number
|
2020-10-05 17:49:03 +00:00
|
|
|
private collection: Collection
|
2020-10-05 09:16:21 +00:00
|
|
|
|
|
|
|
|
constructor () {
|
2020-10-05 17:49:03 +00:00
|
|
|
this.getCollection()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get MongoDB matches collection
|
|
|
|
|
*/
|
|
|
|
|
private async getCollection () {
|
|
|
|
|
this.collection = await mongodb.connection().collection('matches')
|
2020-10-05 09:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Basic matchParams used in a lot of requests
|
|
|
|
|
* @param puuid of the summoner
|
|
|
|
|
*/
|
2020-10-05 17:49:03 +00:00
|
|
|
private matchParams (puuid: string) {
|
2020-10-05 09:16:21 +00:00
|
|
|
return {
|
|
|
|
|
summoner_puuid: puuid,
|
|
|
|
|
result: { $not: { $eq: 'Remake' } },
|
|
|
|
|
gamemode: { $nin: [800, 810, 820, 830, 840, 850] },
|
|
|
|
|
season: this.season ? this.season : { $exists: true },
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-05 17:49:03 +00:00
|
|
|
|
2020-10-05 09:16:21 +00:00
|
|
|
/**
|
|
|
|
|
* Get Summoner's played seasons
|
|
|
|
|
* @param puuid of the summoner
|
|
|
|
|
*/
|
|
|
|
|
public async seasons (puuid: string) {
|
|
|
|
|
this.season = undefined
|
2020-10-05 17:49:03 +00:00
|
|
|
return this.collection.aggregate([
|
2020-10-05 09:16:21 +00:00
|
|
|
{
|
|
|
|
|
$match: {
|
2020-10-05 17:49:03 +00:00
|
|
|
...this.matchParams(puuid),
|
2020-10-05 09:16:21 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
$group: { _id: '$season' },
|
|
|
|
|
},
|
|
|
|
|
]).toArray()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default new MatchRepository()
|