1
0
mirror of https://github.com/matt-fidd/stratos.git synced 2026-01-01 18:19:25 +00:00

Added real data to validator function POST /reports/generate

This commit is contained in:
2022-04-22 02:41:07 +00:00
parent c0cde8a08a
commit b6c66b8e16

View File

@@ -54,7 +54,22 @@ router.get('/reports', async (req, res) => {
});
});
router.post('/report/generate', (req, res) => {
router.post('/report/generate', async (req, res) => {
const u = await new User(req.db, req.session.userId);
const classes = await u.getClasses();
const tests = await u.getTests();
const studentIds = [];
classes.forEach(c => studentIds.push(...c.studentIds));
const extractIds = (obj) => obj.id;
const ids = [
...classes.map(extractIds),
...tests.map(extractIds),
...studentIds
];
let fields;
try {
fields = validator.validate(req.body,
@@ -64,8 +79,8 @@ router.post('/report/generate', (req, res) => {
],
{
values: {
type: [],
target: []
type: [ 'student', 'class', 'test' ],
target: ids
}
}
).fields;