feat: getallsubmissions endpoint toegevoegd
This commit is contained in:
parent
c9739a1420
commit
f0eb4822d9
4 changed files with 36 additions and 20 deletions
|
@ -1,14 +1,9 @@
|
||||||
import { Request, Response } from 'express';
|
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 { Language, languageMap } from '../entities/content/language.js';
|
||||||
import { SubmissionDTO } from '../interfaces/submission';
|
import { SubmissionDTO } from '../interfaces/submission';
|
||||||
|
|
||||||
interface SubmissionParams {
|
export async function getSubmissionHandler(req: Request, res: Response): Promise<void> {
|
||||||
hruid: string;
|
|
||||||
id: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getSubmissionHandler(req: Request<SubmissionParams>, res: Response): Promise<void> {
|
|
||||||
const lohruid = req.params.hruid;
|
const lohruid = req.params.hruid;
|
||||||
const submissionNumber = +req.params.id;
|
const submissionNumber = +req.params.id;
|
||||||
|
|
||||||
|
@ -17,6 +12,7 @@ export async function getSubmissionHandler(req: Request<SubmissionParams>, res:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const lang = languageMap[req.query.language as string] || Language.Dutch;
|
const lang = languageMap[req.query.language as string] || Language.Dutch;
|
||||||
const version = (req.query.version || 1) as number;
|
const version = (req.query.version || 1) as number;
|
||||||
|
|
||||||
|
@ -30,6 +26,17 @@ export async function getSubmissionHandler(req: Request<SubmissionParams>, res:
|
||||||
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 submissions = await getAllSubmissions(lohruid, lang, version);
|
||||||
|
|
||||||
|
res.json({ submissions: submissions });
|
||||||
|
}
|
||||||
|
|
||||||
export async function createSubmissionHandler(req: Request, res: Response) {
|
export async function createSubmissionHandler(req: Request, res: Response) {
|
||||||
const submissionDTO = req.body as SubmissionDTO;
|
const submissionDTO = req.body as SubmissionDTO;
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,14 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public findSubmissionsByLearningObject(loId: LearningObjectIdentifier): Promise<Submission[]> {
|
||||||
|
return this.find({
|
||||||
|
learningObjectHruid: loId.hruid,
|
||||||
|
learningObjectLanguage: loId.language,
|
||||||
|
learningObjectVersion: loId.version,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
public findMostRecentSubmissionForStudent(loId: LearningObjectIdentifier, submitter: Student): Promise<Submission | null> {
|
public findMostRecentSubmissionForStudent(loId: LearningObjectIdentifier, submitter: Student): Promise<Submission | null> {
|
||||||
return this.findOne(
|
return this.findOne(
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,6 +21,19 @@ export async function getSubmission(
|
||||||
return mapToSubmissionDTO(submission);
|
return mapToSubmissionDTO(submission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getAllSubmissions(
|
||||||
|
lohruid: string,
|
||||||
|
language: Language,
|
||||||
|
version: number,
|
||||||
|
): Promise<SubmissionDTO[]> {
|
||||||
|
const loId = new LearningObjectIdentifier(lohruid, language, version);
|
||||||
|
|
||||||
|
const submissionRepository = getSubmissionRepository();
|
||||||
|
const submissions = await submissionRepository.findSubmissionsByLearningObject(loId);
|
||||||
|
|
||||||
|
return submissions.map(mapToSubmissionDTO);
|
||||||
|
}
|
||||||
|
|
||||||
export async function createSubmission(submissionDTO: SubmissionDTO) {
|
export async function createSubmission(submissionDTO: SubmissionDTO) {
|
||||||
const submissionRepository = getSubmissionRepository();
|
const submissionRepository = getSubmissionRepository();
|
||||||
const submission = mapToSubmission(submissionDTO);
|
const submission = mapToSubmission(submissionDTO);
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { setupTestApp } from '../setup-tests.js';
|
||||||
import { describe, it, expect, beforeAll, beforeEach, vi, Mock } from 'vitest';
|
import { describe, it, expect, beforeAll, beforeEach, vi, Mock } from 'vitest';
|
||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
import { getAssignmentHandler, getAllAssignmentsHandler, getAssignmentsSubmissionsHandler } from '../../src/controllers/assignments.js';
|
import { getAssignmentHandler, getAllAssignmentsHandler, getAssignmentsSubmissionsHandler } from '../../src/controllers/assignments.js';
|
||||||
|
import { checkReturn404, checkReturnList } from './qol.js'
|
||||||
|
|
||||||
function createRequestObject(classid: string, assignmentid: string) {
|
function createRequestObject(classid: string, assignmentid: string) {
|
||||||
return {
|
return {
|
||||||
|
@ -13,19 +14,6 @@ function createRequestObject(classid: string, assignmentid: string) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkReturnList(jsonMock: Mock, listName: string) {
|
|
||||||
expect(jsonMock).toHaveBeenCalled();
|
|
||||||
|
|
||||||
const result = jsonMock.mock.lastCall![0];
|
|
||||||
|
|
||||||
expect(listName in result).toBeTruthy();
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkReturn404(jsonMock: Mock, statusMock: Mock) {
|
|
||||||
expect(statusMock).toHaveBeenCalledWith(404);
|
|
||||||
expect(jsonMock).toHaveBeenCalled();
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('Assignment controllers', () => {
|
describe('Assignment controllers', () => {
|
||||||
let req: Partial<Request>;
|
let req: Partial<Request>;
|
||||||
let res: Partial<Response>;
|
let res: Partial<Response>;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue