// report.js // Copyright (C) 2024 DTP Technologies, LLC // All Rights Reserved 'use strict'; import express from 'express'; import { SiteController } from '../../lib/site-lib.js'; export default class ReportController extends SiteController { static get name ( ) { return 'ReportController'; } static get slug ( ) { return 'report'; } constructor (dtp) { super(dtp, ReportController.slug); } async start ( ) { const { // limiter: limiterService, session: sessionService, } = this.dtp.services; // const limiterConfig = limiterService.config.report; const authCheck = sessionService.authCheckMiddleware({ requireLogin: true }); const router = express.Router(); this.dtp.app.use('/report', authCheck, router); router.get('/', this.getDashboard.bind(this)); } async getDashboard (req, res, next) { const { report: reportService } = this.dtp.services; try { res.locals.pageTitle = 'Weekly Summary Report'; res.locals.pageDescription = 'A breakdown of project and contractor performance for the current week.'; res.locals.weekStartDate = reportService.startOfWeek(); res.locals.weeklyEarnings = await reportService.getWeeklyEarnings(req.user); res.locals.dailyTimeWorked = await reportService.getDailyHoursWorkedForUser(req.user); res.render('report/dashboard'); } catch (error) { this.log.error('failed to present report dashboard', { error }); return next(error); } } }