feat: requirefields in backend controllers (class, assignment, submission, group)
This commit is contained in:
parent
d2f5219b69
commit
c52bcde3ae
3 changed files with 38 additions and 63 deletions
|
@ -5,22 +5,22 @@ import { NotFoundException } from '../exceptions/not-found-exception.js';
|
|||
import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js';
|
||||
import { Language, languageMap } from '@dwengo-1/common/util/language';
|
||||
import { SubmissionDTO } from '@dwengo-1/common/interfaces/submission';
|
||||
import { requireFields } from './error-helper.js';
|
||||
|
||||
|
||||
|
||||
export async function getSubmissionHandler(req: Request, res: Response): Promise<void> {
|
||||
const submissionNumber = +req.params.id;
|
||||
const lohruid = req.params.hruid;
|
||||
const lang = languageMap[req.query.language as string] || Language.Dutch;
|
||||
const version = (req.query.version || 1) as number;
|
||||
const submissionNumber = Number(req.params.id);
|
||||
requireFields({ lohruid, submissionNumber });
|
||||
|
||||
if (isNaN(submissionNumber)) {
|
||||
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 loId = new LearningObjectIdentifier(lohruid, lang, version);
|
||||
|
||||
const submission = await getSubmission(loId, submissionNumber);
|
||||
|
||||
res.json({ submission });
|
||||
|
@ -30,9 +30,9 @@ export async function getAllSubmissionsHandler(req: Request, res: Response): Pro
|
|||
const lohruid = req.params.hruid;
|
||||
const lang = languageMap[req.query.language as string] || Language.Dutch;
|
||||
const version = (req.query.version || 1) as number;
|
||||
requireFields({ lohruid });
|
||||
|
||||
const loId = new LearningObjectIdentifier(lohruid, lang, version);
|
||||
|
||||
const submissions = await getAllSubmissions(loId);
|
||||
|
||||
res.json({ submissions });
|
||||
|
@ -40,31 +40,24 @@ export async function getAllSubmissionsHandler(req: Request, res: Response): Pro
|
|||
|
||||
export async function createSubmissionHandler(req: Request, res: Response): Promise<void> {
|
||||
const submissionDTO = req.body as SubmissionDTO;
|
||||
|
||||
const submission = await createSubmission(submissionDTO);
|
||||
|
||||
if (!submission) {
|
||||
res.status(400).json({ error: 'Failed to create submission' });
|
||||
return;
|
||||
}
|
||||
|
||||
res.json({ submission });
|
||||
}
|
||||
|
||||
export async function deleteSubmissionHandler(req: Request, res: Response): Promise<void> {
|
||||
const hruid = req.params.hruid;
|
||||
const submissionNumber = Number(req.params.id);
|
||||
|
||||
const lang = languageMap[req.query.language as string] || Language.Dutch;
|
||||
const version = (req.query.version || 1) as number;
|
||||
const submissionNumber = Number(req.params.id);
|
||||
requireFields({ hruid, submissionNumber });
|
||||
|
||||
if (isNaN(submissionNumber)) {
|
||||
throw new BadRequestException('Submission number must be a number');
|
||||
}
|
||||
|
||||
const loId = new LearningObjectIdentifier(hruid, lang, version);
|
||||
|
||||
const submission = await deleteSubmission(loId, submissionNumber);
|
||||
|
||||
if (!submission) {
|
||||
throw new NotFoundException('Could not delete submission');
|
||||
}
|
||||
|
||||
res.json({ submission });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue