feat: get all submissions route toegevoegd
This commit is contained in:
parent
7ae2f1de0c
commit
6290d3dd9b
4 changed files with 59 additions and 41 deletions
|
@ -1,33 +1,41 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { createSubmission, deleteSubmission, getSubmission } from '../services/submissions.js';
|
||||
import { createSubmission, deleteSubmission, getAllSubmissions, getSubmission } from '../services/submissions.js';
|
||||
import { Language, languageMap } from '../entities/content/language.js';
|
||||
import { SubmissionDTO } from '../interfaces/submission';
|
||||
import { BadRequestException } from '../exceptions/bad-request-exception.js';
|
||||
import { NotFoundException } from '../exceptions/not-found-exception.js';
|
||||
import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js';
|
||||
|
||||
interface SubmissionParams {
|
||||
hruid: string;
|
||||
id: number;
|
||||
}
|
||||
|
||||
export async function getSubmissionHandler(req: Request<SubmissionParams>, res: Response): Promise<void> {
|
||||
const lohruid = req.params.hruid;
|
||||
|
||||
export async function getSubmissionHandler(req: Request, res: Response): Promise<void> {
|
||||
const submissionNumber = +req.params.id;
|
||||
|
||||
|
||||
if (isNaN(submissionNumber)) {
|
||||
res.status(400).json({ error: 'Submission number is not a number' });
|
||||
return;
|
||||
throw new BadRequestException('Submission number must be a number');
|
||||
}
|
||||
|
||||
|
||||
const lohruid = req.params.hruid;
|
||||
const lang = languageMap[req.query.language as string] || Language.Dutch;
|
||||
const version = (req.query.version || 1) as number;
|
||||
|
||||
const submission = await getSubmission(lohruid, lang, version, submissionNumber);
|
||||
const loId = new LearningObjectIdentifier(lohruid, lang, version);
|
||||
|
||||
if (!submission) {
|
||||
res.status(404).json({ error: 'Submission not found' });
|
||||
return;
|
||||
}
|
||||
const submission = await getSubmission(loId, submissionNumber);
|
||||
|
||||
res.json(submission);
|
||||
res.json({ submission });
|
||||
}
|
||||
|
||||
export async function getAllSubmissionsHandler(req: Request, res: Response): Promise<void> {
|
||||
const lohruid = req.params.hruid;
|
||||
const lang = languageMap[req.query.language as string] || Language.Dutch;
|
||||
const version = (req.query.version || 1) as number;
|
||||
|
||||
const loId = new LearningObjectIdentifier(lohruid, lang, version);
|
||||
|
||||
const submissions = await getAllSubmissions(loId);
|
||||
|
||||
res.json({ submissions });
|
||||
}
|
||||
|
||||
export async function createSubmissionHandler(req: Request, res: Response) {
|
||||
|
@ -40,22 +48,23 @@ export async function createSubmissionHandler(req: Request, res: Response) {
|
|||
return;
|
||||
}
|
||||
|
||||
res.json(submission);
|
||||
res.json({ submission });
|
||||
}
|
||||
|
||||
export async function deleteSubmissionHandler(req: Request, res: Response) {
|
||||
const hruid = req.params.hruid;
|
||||
const submissionNumber = +req.params.id;
|
||||
|
||||
|
||||
const hruid = req.params.hruid;
|
||||
const lang = languageMap[req.query.language as string] || Language.Dutch;
|
||||
const version = (req.query.version || 1) as number;
|
||||
|
||||
const submission = await deleteSubmission(hruid, lang, version, submissionNumber);
|
||||
const loId = new LearningObjectIdentifier(hruid, lang, version);
|
||||
|
||||
const submission = await deleteSubmission(loId, submissionNumber);
|
||||
|
||||
if (!submission) {
|
||||
res.status(404).json({ error: 'Submission not found' });
|
||||
return;
|
||||
throw new NotFoundException('Could not delete submission');
|
||||
}
|
||||
|
||||
res.json(submission);
|
||||
res.json({ submission });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue