feat: verbinding tussen service laag en api endpoint van submissions van een assignment
This commit is contained in:
parent
fd693dc55f
commit
788ca54742
2 changed files with 22 additions and 6 deletions
|
@ -1,5 +1,5 @@
|
||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
import { getAllAssignments, getAssignment } from '../services/assignments.js';
|
import { getAllAssignments, getAssignment, getAssignmentsSubmissions } from '../services/assignments.js';
|
||||||
|
|
||||||
// Typescript is annoy with with parameter forwarding from class.ts
|
// Typescript is annoy with with parameter forwarding from class.ts
|
||||||
interface AssignmentParams {
|
interface AssignmentParams {
|
||||||
|
@ -42,3 +42,22 @@ export async function getAssignmentHandler(
|
||||||
|
|
||||||
res.json(assignment);
|
res.json(assignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getAssignmentsSubmissionsHandler(
|
||||||
|
req: Request<AssignmentParams>,
|
||||||
|
res: Response,
|
||||||
|
): Promise<void> {
|
||||||
|
const classid = req.params.classid;
|
||||||
|
const assignmentNumber = +req.params.id;
|
||||||
|
|
||||||
|
if (isNaN(assignmentNumber)) {
|
||||||
|
res.status(400).json({ error: 'Assignment id must be a number' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const submissions = await getAssignmentsSubmissions(classid, assignmentNumber);
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
submissions: submissions,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ import express from 'express';
|
||||||
import {
|
import {
|
||||||
getAllAssignmentsHandler,
|
getAllAssignmentsHandler,
|
||||||
getAssignmentHandler,
|
getAssignmentHandler,
|
||||||
|
getAssignmentsSubmissionsHandler,
|
||||||
} from '../controllers/assignments.js';
|
} from '../controllers/assignments.js';
|
||||||
import groupRouter from './groups.js';
|
import groupRouter from './groups.js';
|
||||||
|
|
||||||
|
@ -13,11 +14,7 @@ router.get('/', getAllAssignmentsHandler);
|
||||||
// Information about an assignment with id 'id'
|
// Information about an assignment with id 'id'
|
||||||
router.get('/:id', getAssignmentHandler);
|
router.get('/:id', getAssignmentHandler);
|
||||||
|
|
||||||
router.get('/:id/submissions', (req, res) => {
|
router.get('/:id/submissions', getAssignmentsSubmissionsHandler);
|
||||||
res.json({
|
|
||||||
submissions: ['0'],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
router.get('/:id/questions', (req, res) => {
|
router.get('/:id/questions', (req, res) => {
|
||||||
res.json({
|
res.json({
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue