A web application allowing people to create an account, configure a profile, and share a list of URLs on that profile.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

58 lines
1.7 KiB

// dashboard.js
// Copyright (C) 2021 Digital Telepresence, LLC
// License: Apache-2.0
'use strict';
const DTP_COMPONENT_NAME = 'dashboard';
const express = require('express');
const { SiteController } = require('../../lib/site-lib');
class DashboardController extends SiteController {
constructor (dtp) {
super(dtp, DTP_COMPONENT_NAME);
}
async start ( ) {
const { dtp } = this;
const { limiter: limiterService, session: sessionService } = dtp.services;
const authRequired = sessionService.authCheckMiddleware({ requireLogin: true });
const router = express.Router();
dtp.app.use('/dashboard', router);
router.use(async (req, res, next) => {
res.locals.currentView = DTP_COMPONENT_NAME;
return next();
});
router.get('/',
limiterService.create(limiterService.config.dashboard.getDashboardView),
authRequired,
this.getDashboardView.bind(this),
);
}
async getDashboardView (req, res, next) {
const { dashboard: dashboardService, link: linkService } = this.dtp.services;
try {
res.locals.userVisitStats = await dashboardService.getUserVisitStats(req.user);
res.locals.userCountryStats = await dashboardService.getUserCountryStats(req.user);
res.locals.userCityStats = await dashboardService.getUserCityStats(req.user);
res.locals.userLinks = await linkService.getForUser(req.user);
res.render('dashboard/view');
} catch (error) {
this.log.error('failed to display dashboard', { userId: req.user._id, error });
return next(error);
}
}
}
module.exports = async (dtp) => {
let controller = new DashboardController(dtp);
return controller;
};