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:
@@ -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;
|
let fields;
|
||||||
try {
|
try {
|
||||||
fields = validator.validate(req.body,
|
fields = validator.validate(req.body,
|
||||||
@@ -64,8 +79,8 @@ router.post('/report/generate', (req, res) => {
|
|||||||
],
|
],
|
||||||
{
|
{
|
||||||
values: {
|
values: {
|
||||||
type: [],
|
type: [ 'student', 'class', 'test' ],
|
||||||
target: []
|
target: ids
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
).fields;
|
).fields;
|
||||||
|
|||||||
Reference in New Issue
Block a user