merge: merged into feat/error-flow-backend
This commit is contained in:
commit
effaeb0277
249 changed files with 6832 additions and 3679 deletions
|
@ -1,71 +1,59 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { createAssignment, getAllAssignments, getAssignment, getAssignmentsSubmissions } from '../services/assignments.js';
|
||||
import { AssignmentDTO } from '../interfaces/assignment.js';
|
||||
import { AssignmentDTO } from '@dwengo-1/common/interfaces/assignment';
|
||||
import {requireFields} from "./error-helper";
|
||||
import {BadRequestException} from "../exceptions/bad-request-exception";
|
||||
|
||||
export async function getAllAssignmentsHandler(req: Request, res: Response): Promise<void> {
|
||||
const classid = req.params.classid;
|
||||
const classId = req.params.classid;
|
||||
const full = req.query.full === 'true';
|
||||
requireFields({ classId });
|
||||
|
||||
const assignments = await getAllAssignments(classid, full);
|
||||
const assignments = await getAllAssignments(classId, full);
|
||||
|
||||
res.json({
|
||||
assignments: assignments,
|
||||
});
|
||||
res.json({ assignments });
|
||||
}
|
||||
|
||||
export async function createAssignmentHandler(req: Request, res: Response): Promise<void> {
|
||||
const classid = req.params.classid;
|
||||
const assignmentData = req.body as AssignmentDTO;
|
||||
const description = req.body.description;
|
||||
const language = req.body.language;
|
||||
const learningPath = req.body.learningPath;
|
||||
const title = req.body.title;
|
||||
|
||||
if (!assignmentData.description || !assignmentData.language || !assignmentData.learningPath || !assignmentData.title) {
|
||||
res.status(400).json({
|
||||
error: 'Missing one or more required fields: title, description, learningPath, language',
|
||||
});
|
||||
return;
|
||||
}
|
||||
requireFields({ description, language, learningPath, title });
|
||||
const assignmentData = req.body as AssignmentDTO;
|
||||
|
||||
const assignment = await createAssignment(classid, assignmentData);
|
||||
|
||||
if (!assignment) {
|
||||
res.status(500).json({ error: 'Could not create assignment ' });
|
||||
return;
|
||||
}
|
||||
|
||||
res.status(201).json(assignment);
|
||||
res.json({ assignment });
|
||||
}
|
||||
|
||||
export async function getAssignmentHandler(req: Request, res: Response): Promise<void> {
|
||||
const id = +req.params.id;
|
||||
const id = Number(req.params.id);
|
||||
const classid = req.params.classid;
|
||||
requireFields({ id, classid });
|
||||
|
||||
if (isNaN(id)) {
|
||||
res.status(400).json({ error: 'Assignment id must be a number' });
|
||||
return;
|
||||
throw new BadRequestException("Assignment id should be a number")
|
||||
}
|
||||
|
||||
const assignment = await getAssignment(classid, id);
|
||||
|
||||
if (!assignment) {
|
||||
res.status(404).json({ error: 'Assignment not found' });
|
||||
return;
|
||||
}
|
||||
|
||||
res.json(assignment);
|
||||
res.json({ assignment });
|
||||
}
|
||||
|
||||
export async function getAssignmentsSubmissionsHandler(req: Request, res: Response): Promise<void> {
|
||||
const classid = req.params.classid;
|
||||
const assignmentNumber = +req.params.id;
|
||||
const assignmentNumber = Number(req.params.id);
|
||||
const full = req.query.full === 'true';
|
||||
requireFields({ assignmentNumber, classid });
|
||||
|
||||
if (isNaN(assignmentNumber)) {
|
||||
res.status(400).json({ error: 'Assignment id must be a number' });
|
||||
return;
|
||||
throw new BadRequestException("Assignment id should be a number")
|
||||
}
|
||||
|
||||
const submissions = await getAssignmentsSubmissions(classid, assignmentNumber, full);
|
||||
|
||||
res.json({
|
||||
submissions: submissions,
|
||||
});
|
||||
res.json({ submissions });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue