import { Request, Response } from 'express';
import ProjectDatabaseService from '../services/db/projectList';

class StatsController {
    //constructor() {
    //  this.getJobsThisYear = this.getJobsThisYear.bind(this);
    //  this.getEarningsThisYear = this.getEarningsThisYear.bind(this);
    //}

    private projectListService = new ProjectDatabaseService();

    getProjectsThisYear(req: Request, res: Response) {
        this.projectListService.countProjectsThisYear().then((amount) => {
            res.send({ amount });
        });
    }

    getEarningsThisYear(req: Request, res: Response) {
        this.projectListService.summarizeEarningsThisYear().then((amount) => {
            res.send({ amount: amount.sum.price });
        });
    }
}

export const statsController = new StatsController();
