Files
freeCodeCamp/tools/contributor/dashboard-app/server/routes/pareto.js
Oliver Eyton-Williams c8d7f0a782 feat(tools): remove eslint-plugin-prettier for prettier (#42438)
* feat: remove eslint-plugin-prettier for prettier

This removes the annoying lint warnings when all that needs to change is
formatting

* fix: use .js lint-staged config to ignore properly

* fix: lint everything if a lot of files are changed

It's faster than making lots of individual linter calls

* chore: apply prettier

* fix: ignore code in curriculum-file-structure
2021-10-06 21:02:21 +05:30

39 lines
1.1 KiB
JavaScript

const router = require('express').Router();
const { PR } = require('../models');
const { reqLimiter } = require('../req-limiter');
const createPareto = (reportObj) =>
Object.keys(reportObj)
.reduce((arr, filename) => {
const { count, prs } = reportObj[filename];
if (count > 1) {
arr.push({ filename, count, prs });
}
return arr;
}, [])
.sort((a, b) => b.count - a.count);
router.get('/', reqLimiter, async (request, response) => {
const prs = await PR.find({}).then((data) => data);
prs.sort((a, b) => a._id - b._id);
const reportObj = prs.reduce((obj, pr) => {
const { _id: number, filenames, username, title } = pr;
filenames.forEach((filename) => {
if (obj[filename]) {
const { count, prs } = obj[filename];
obj[filename] = {
count: count + 1,
prs: prs.concat({ number, username, title })
};
} else {
obj[filename] = { count: 1, prs: [{ number, username, title }] };
}
});
return obj;
}, {});
response.json({ ok: true, pareto: createPareto(reportObj) });
});
module.exports = router;