mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-01 22:59:28 +00:00
Replaced sample data with real data
This commit is contained in:
@@ -3,7 +3,24 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
router.get('/reports', (req, res) => {
|
const User = require('../lib/User');
|
||||||
|
|
||||||
|
const validator = require('../lib/validator');
|
||||||
|
|
||||||
|
router.get('/reports', async (req, res) => {
|
||||||
|
const u = await new User(req.db, req.session.userId);
|
||||||
|
const classes = await u.getClasses();
|
||||||
|
const tests = await u.getTests();
|
||||||
|
|
||||||
|
let studentIds = [];
|
||||||
|
let students = [];
|
||||||
|
classes.forEach(c => studentIds.push(...c.studentIds));
|
||||||
|
classes.forEach(c => students.push(...c.students));
|
||||||
|
|
||||||
|
studentIds = studentIds.map((s, i) =>
|
||||||
|
studentIds.indexOf(s) === i ? s : '');
|
||||||
|
students = students.filter((_, i) => studentIds[i] !== '');
|
||||||
|
|
||||||
return res.render('reports', {
|
return res.render('reports', {
|
||||||
...req.hbsContext,
|
...req.hbsContext,
|
||||||
title: 'Stratos - Reports',
|
title: 'Stratos - Reports',
|
||||||
@@ -16,38 +33,49 @@ router.get('/reports', (req, res) => {
|
|||||||
{
|
{
|
||||||
key: 'class',
|
key: 'class',
|
||||||
value: 'Class'
|
value: 'Class'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'test',
|
||||||
|
value: 'Test'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
targets: JSON.stringify({
|
targets: JSON.stringify({
|
||||||
student: [
|
student: students.map(s => ({
|
||||||
{
|
id: s.id, name: s.shortName
|
||||||
id: '1',
|
})),
|
||||||
name: 'joe'
|
class: classes.map(c => ({ id: c.id, name: c.name })),
|
||||||
}
|
test: tests.map(t => ({
|
||||||
],
|
id: t.id,
|
||||||
class: [
|
name: `${t.template.name} - ` +
|
||||||
{
|
`${t.class.name} - ` +
|
||||||
id: '1',
|
`${t.dateString}`
|
||||||
name: 'joeseph'
|
}))
|
||||||
},
|
|
||||||
{
|
|
||||||
id: '2',
|
|
||||||
name: 'bob'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: '3',
|
|
||||||
name: 'fred'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: '4',
|
|
||||||
name: 'mike'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('/report/generate', (req, res) => {
|
router.post('/report/generate', (req, res) => {
|
||||||
|
let fields;
|
||||||
|
try {
|
||||||
|
fields = validator.validate(req.body,
|
||||||
|
[
|
||||||
|
'type',
|
||||||
|
'target'
|
||||||
|
],
|
||||||
|
{
|
||||||
|
values: {
|
||||||
|
type: [],
|
||||||
|
target: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
).fields;
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
return res.status(400).json({ status: 'Invalid' });
|
||||||
|
}
|
||||||
|
|
||||||
|
fields.get('type');
|
||||||
|
|
||||||
return res.redirect('/admin/reports');
|
return res.redirect('/admin/reports');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user