feat: POST method voor assignment geimplementeerd
This commit is contained in:
parent
3e2c73320b
commit
a1aaf342d7
5 changed files with 81 additions and 5 deletions
|
@ -1,5 +1,7 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { getAllAssignments, getAssignment, getAssignmentsSubmissions } from '../services/assignments.js';
|
||||
import { createAssignment, getAllAssignments, getAssignment, getAssignmentsSubmissions } from '../services/assignments.js';
|
||||
import { AssignmentDTO, mapToAssignment, mapToAssignmentDTO } from '../interfaces/assignment.js';
|
||||
import { getAssignmentRepository, getClassRepository } from '../data/repositories.js';
|
||||
|
||||
// Typescript is annoy with with parameter forwarding from class.ts
|
||||
interface AssignmentParams {
|
||||
|
@ -21,6 +23,34 @@ export async function getAllAssignmentsHandler(
|
|||
});
|
||||
}
|
||||
|
||||
export async function createAssignmentHandler(
|
||||
req: Request<AssignmentParams>,
|
||||
res: Response,
|
||||
): Promise<void> {
|
||||
const classid = req.params.classid;
|
||||
const assignmentData = req.body as AssignmentDTO;
|
||||
|
||||
if (!assignmentData.description
|
||||
|| !assignmentData.language
|
||||
|| !assignmentData.learningPath
|
||||
|| !assignmentData.title
|
||||
) {
|
||||
res.status(400).json({
|
||||
error: 'Missing one or more required fields: title, description, learningPath, title',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const assignment = createAssignment(classid, assignmentData);
|
||||
|
||||
if (!assignment) {
|
||||
res.status(500).json({ error: "Could not create assignment "});
|
||||
return;
|
||||
}
|
||||
|
||||
res.status(201).json({ assignment: assignment });
|
||||
}
|
||||
|
||||
export async function getAssignmentHandler(
|
||||
req: Request<AssignmentParams>,
|
||||
res: Response
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue