@@ -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),
 | 
			
		||||
        };
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user