merge: merge fix/183-post-assignment into dev
This commit is contained in:
commit
5a593cb88f
67 changed files with 2205 additions and 2129 deletions
|
@ -1,8 +1,15 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { createQuestion, deleteQuestion, getAllQuestions, getQuestion, updateQuestion } from '../services/questions.js';
|
||||
import {
|
||||
createQuestion,
|
||||
deleteQuestion,
|
||||
getAllQuestions,
|
||||
getQuestion,
|
||||
getQuestionsAboutLearningObjectInAssignment,
|
||||
updateQuestion,
|
||||
} from '../services/questions.js';
|
||||
import { FALLBACK_LANG, FALLBACK_SEQ_NUM, FALLBACK_VERSION_NUM } from '../config.js';
|
||||
import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js';
|
||||
import { QuestionData, QuestionId } from '@dwengo-1/common/interfaces/question';
|
||||
import { QuestionData, QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
import { requireFields } from './error-helper.js';
|
||||
|
||||
|
@ -30,7 +37,18 @@ export async function getAllQuestionsHandler(req: Request, res: Response): Promi
|
|||
|
||||
const learningObjectId = getLearningObjectId(hruid, version, language);
|
||||
|
||||
const questions = await getAllQuestions(learningObjectId, full);
|
||||
let questions: QuestionDTO[] | QuestionId[];
|
||||
if (req.query.classId && req.query.assignmentId) {
|
||||
questions = await getQuestionsAboutLearningObjectInAssignment(
|
||||
learningObjectId,
|
||||
req.query.classId as string,
|
||||
parseInt(req.query.assignmentId as string),
|
||||
full ?? false,
|
||||
req.query.forStudent as string | undefined
|
||||
);
|
||||
} else {
|
||||
questions = await getAllQuestions(learningObjectId, full ?? false);
|
||||
}
|
||||
|
||||
res.json({ questions });
|
||||
}
|
||||
|
@ -60,7 +78,8 @@ export async function createQuestionHandler(req: Request, res: Response): Promis
|
|||
|
||||
const author = req.body.author as string;
|
||||
const content = req.body.content as string;
|
||||
requireFields({ author, content });
|
||||
const inGroup = req.body.inGroup;
|
||||
requireFields({ author, content, inGroup });
|
||||
|
||||
const questionData = req.body as QuestionData;
|
||||
|
||||
|
|
|
@ -1,10 +1,32 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { createSubmission, deleteSubmission, getAllSubmissions, getSubmission } from '../services/submissions.js';
|
||||
import { BadRequestException } from '../exceptions/bad-request-exception.js';
|
||||
import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js';
|
||||
import { Language, languageMap } from '@dwengo-1/common/util/language';
|
||||
import {
|
||||
createSubmission,
|
||||
deleteSubmission,
|
||||
getAllSubmissions,
|
||||
getSubmission,
|
||||
getSubmissionsForLearningObjectAndAssignment,
|
||||
} from '../services/submissions.js';
|
||||
import { SubmissionDTO } from '@dwengo-1/common/interfaces/submission';
|
||||
import { Language, languageMap } from '@dwengo-1/common/util/language';
|
||||
import { BadRequestException } from '../exceptions/bad-request-exception.js';
|
||||
import { requireFields } from './error-helper.js';
|
||||
import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js';
|
||||
|
||||
export async function getSubmissionsHandler(req: Request, res: Response): Promise<void> {
|
||||
const loHruid = req.params.hruid;
|
||||
const lang = languageMap[req.query.language as string] || Language.Dutch;
|
||||
const version = parseInt(req.query.version as string) ?? 1;
|
||||
|
||||
const submissions = await getSubmissionsForLearningObjectAndAssignment(
|
||||
loHruid,
|
||||
lang,
|
||||
version,
|
||||
req.query.classId as string,
|
||||
parseInt(req.query.assignmentId as string)
|
||||
);
|
||||
|
||||
res.json(submissions);
|
||||
}
|
||||
|
||||
export async function getSubmissionHandler(req: Request, res: Response): Promise<void> {
|
||||
const lohruid = req.params.hruid;
|
||||
|
|
66
backend/src/controllers/teacher-invitations.ts
Normal file
66
backend/src/controllers/teacher-invitations.ts
Normal file
|
@ -0,0 +1,66 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { requireFields } from './error-helper.js';
|
||||
import { createInvitation, deleteInvitation, getAllInvitations, getInvitation, updateInvitation } from '../services/teacher-invitations.js';
|
||||
import { TeacherInvitationData } from '@dwengo-1/common/interfaces/teacher-invitation';
|
||||
|
||||
export async function getAllInvitationsHandler(req: Request, res: Response): Promise<void> {
|
||||
const username = req.params.username;
|
||||
const by = req.query.sent === 'true';
|
||||
requireFields({ username });
|
||||
|
||||
const invitations = await getAllInvitations(username, by);
|
||||
|
||||
res.json({ invitations });
|
||||
}
|
||||
|
||||
export async function getInvitationHandler(req: Request, res: Response): Promise<void> {
|
||||
const sender = req.params.sender;
|
||||
const receiver = req.params.receiver;
|
||||
const classId = req.params.classId;
|
||||
requireFields({ sender, receiver, classId });
|
||||
|
||||
const invitation = await getInvitation(sender, receiver, classId);
|
||||
|
||||
res.json({ invitation });
|
||||
}
|
||||
|
||||
export async function createInvitationHandler(req: Request, res: Response): Promise<void> {
|
||||
const sender = req.body.sender;
|
||||
const receiver = req.body.receiver;
|
||||
const classId = req.body.class;
|
||||
requireFields({ sender, receiver, classId });
|
||||
|
||||
const data = req.body as TeacherInvitationData;
|
||||
const invitation = await createInvitation(data);
|
||||
|
||||
res.json({ invitation });
|
||||
}
|
||||
|
||||
export async function updateInvitationHandler(req: Request, res: Response): Promise<void> {
|
||||
const sender = req.body.sender;
|
||||
const receiver = req.body.receiver;
|
||||
const classId = req.body.class;
|
||||
req.body.accepted = req.body.accepted !== 'false';
|
||||
requireFields({ sender, receiver, classId });
|
||||
|
||||
const data = req.body as TeacherInvitationData;
|
||||
const invitation = await updateInvitation(data);
|
||||
|
||||
res.json({ invitation });
|
||||
}
|
||||
|
||||
export async function deleteInvitationHandler(req: Request, res: Response): Promise<void> {
|
||||
const sender = req.params.sender;
|
||||
const receiver = req.params.receiver;
|
||||
const classId = req.params.classId;
|
||||
requireFields({ sender, receiver, classId });
|
||||
|
||||
const data: TeacherInvitationData = {
|
||||
sender,
|
||||
receiver,
|
||||
class: classId,
|
||||
};
|
||||
const invitation = await deleteInvitation(data);
|
||||
|
||||
res.json({ invitation });
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue