huridocs/uwazi

View on GitHub
app/api/stats/routes.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import { Application } from 'express';
import needsAuthorization from 'api/auth/authMiddleware';
import { RetrieveStatsService } from 'api/stats/services/RetrieveStatsService';
import { tenants } from 'api/tenants';
import { DB } from 'api/odm';

export default (app: Application) => {
  app.get('/api/stats', needsAuthorization(['admin']), async (_req, res, _next) => {
    const { db } = DB.connectionForDB(tenants.current().dbName);
    const action = new RetrieveStatsService(db);
    const stats = await action.execute();

    res.json(stats);
  });
};