Added team and org stats

ref #56
This commit is contained in:
Nicolai Ort 2020-12-29 16:08:50 +01:00
parent 1b7424f750
commit 6a762f570d
1 changed files with 7 additions and 1 deletions

View File

@ -3,6 +3,8 @@ import { OpenAPI } from 'routing-controllers-openapi';
import { getConnection } from 'typeorm';
import { Donation } from '../models/entities/Donation';
import { Runner } from '../models/entities/Runner';
import { RunnerOrganisation } from '../models/entities/RunnerOrganisation';
import { RunnerTeam } from '../models/entities/RunnerTeam';
import { Scan } from '../models/entities/Scan';
import { User } from '../models/entities/User';
@ -14,13 +16,17 @@ export class StatsController {
async get() {
let connection = getConnection();
let runners = await connection.getRepository(Runner).find({ relations: ["scans"] });
let teams = await connection.getRepository(RunnerTeam).find();
let orgs = await connection.getRepository(RunnerOrganisation).find();
let users = await connection.getRepository(User).find();
let scans = await connection.getRepository(Scan).find();
let donations = await connection.getRepository(Donation).find({ relations: ["runner", "runner.scans"] });
return {
"total_runners": runners.length,
"total_teams": teams.length,
"total_orgs": orgs.length,
"total_users": users.length,
"total_scans": scans.length,
"total_scans": scans.filter(scan => { scan.valid === true }).length,
"total_distance": runners.reduce((sum, current) => sum + current.distance, 0),
"total_donation_amount": donations.reduce((sum, current) => sum + current.amount, 0),
};