Merge remote-tracking branch 'origin/feat/questions-answers-en-submissions-groep-specifiek-maken-#163' into feat/endpoints-beschermen-met-authenticatie-#105
This commit is contained in:
commit
bc60c18938
30 changed files with 774 additions and 206 deletions
|
@ -1,11 +1,31 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { createQuestion, deleteQuestion, getAllQuestions, getAnswersByQuestion, getQuestion } from '../services/questions.js';
|
||||
import {
|
||||
createQuestion,
|
||||
deleteQuestion,
|
||||
getAllQuestions,
|
||||
getAnswersByQuestion,
|
||||
getQuestion,
|
||||
getQuestionsAboutLearningObjectInAssignment,
|
||||
} from '../services/questions.js';
|
||||
import { FALLBACK_LANG, FALLBACK_SEQ_NUM } from '../config.js';
|
||||
import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js';
|
||||
import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
import { AnswerDTO, AnswerId } from '@dwengo-1/common/interfaces/answer';
|
||||
|
||||
function getObjectId(req: Request, res: Response): LearningObjectIdentifier | null {
|
||||
interface QuestionPathParams {
|
||||
hruid: string;
|
||||
version: string;
|
||||
}
|
||||
|
||||
interface QuestionQueryParams {
|
||||
lang: string;
|
||||
}
|
||||
|
||||
function getObjectId<ResBody, ReqBody>(
|
||||
req: Request<QuestionPathParams, ResBody, ReqBody, QuestionQueryParams>,
|
||||
res: Response
|
||||
): LearningObjectIdentifier | null {
|
||||
const { hruid, version } = req.params;
|
||||
const lang = req.query.lang;
|
||||
|
||||
|
@ -21,7 +41,13 @@ function getObjectId(req: Request, res: Response): LearningObjectIdentifier | nu
|
|||
};
|
||||
}
|
||||
|
||||
function getQuestionId(req: Request, res: Response): QuestionId | null {
|
||||
interface GetQuestionIdPathParams extends QuestionPathParams {
|
||||
seq: string;
|
||||
}
|
||||
function getQuestionId<ReqBody, ResBody>(
|
||||
req: Request<GetQuestionIdPathParams, ReqBody, ResBody, QuestionQueryParams>,
|
||||
res: Response
|
||||
): QuestionId | null {
|
||||
const seq = req.params.seq;
|
||||
const learningObjectIdentifier = getObjectId(req, res);
|
||||
|
||||
|
@ -35,15 +61,35 @@ function getQuestionId(req: Request, res: Response): QuestionId | null {
|
|||
};
|
||||
}
|
||||
|
||||
export async function getAllQuestionsHandler(req: Request, res: Response): Promise<void> {
|
||||
interface GetAllQuestionsQueryParams extends QuestionQueryParams {
|
||||
classId?: string;
|
||||
assignmentId?: number;
|
||||
forStudent?: string;
|
||||
full?: boolean;
|
||||
}
|
||||
|
||||
export async function getAllQuestionsHandler(
|
||||
req: Request<QuestionPathParams, QuestionDTO[] | QuestionId[], unknown, GetAllQuestionsQueryParams>,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
const objectId = getObjectId(req, res);
|
||||
const full = req.query.full === 'true';
|
||||
const full = req.query.full;
|
||||
|
||||
if (!objectId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const questions = await getAllQuestions(objectId, full);
|
||||
let questions: QuestionDTO[] | QuestionId[];
|
||||
if (req.query.classId && req.query.assignmentId) {
|
||||
questions = await getQuestionsAboutLearningObjectInAssignment(
|
||||
objectId,
|
||||
req.query.classId,
|
||||
req.query.assignmentId,
|
||||
full ?? false,
|
||||
req.query.forStudent
|
||||
);
|
||||
} else {
|
||||
questions = await getAllQuestions(objectId, full ?? false);
|
||||
}
|
||||
|
||||
if (!questions) {
|
||||
res.status(404).json({ error: `Questions not found.` });
|
||||
|
@ -52,7 +98,10 @@ export async function getAllQuestionsHandler(req: Request, res: Response): Promi
|
|||
}
|
||||
}
|
||||
|
||||
export async function getQuestionHandler(req: Request, res: Response): Promise<void> {
|
||||
export async function getQuestionHandler(
|
||||
req: Request<GetQuestionIdPathParams, QuestionDTO[] | QuestionId[], unknown, QuestionQueryParams>,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
const questionId = getQuestionId(req, res);
|
||||
|
||||
if (!questionId) {
|
||||
|
@ -68,9 +117,15 @@ export async function getQuestionHandler(req: Request, res: Response): Promise<v
|
|||
}
|
||||
}
|
||||
|
||||
export async function getQuestionAnswersHandler(req: Request, res: Response): Promise<void> {
|
||||
interface GetQuestionAnswersQueryParams extends QuestionQueryParams {
|
||||
full: boolean;
|
||||
}
|
||||
export async function getQuestionAnswersHandler(
|
||||
req: Request<GetQuestionIdPathParams, { answers: AnswerDTO[] | AnswerId[] }, unknown, GetQuestionAnswersQueryParams>,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
const questionId = getQuestionId(req, res);
|
||||
const full = req.query.full === 'true';
|
||||
const full = req.query.full;
|
||||
|
||||
if (!questionId) {
|
||||
return;
|
||||
|
@ -88,8 +143,8 @@ export async function getQuestionAnswersHandler(req: Request, res: Response): Pr
|
|||
export async function createQuestionHandler(req: Request, res: Response): Promise<void> {
|
||||
const questionDTO = req.body as QuestionDTO;
|
||||
|
||||
if (!questionDTO.learningObjectIdentifier || !questionDTO.author || !questionDTO.content) {
|
||||
res.status(400).json({ error: 'Missing required fields: identifier and content' });
|
||||
if (!questionDTO.learningObjectIdentifier || !questionDTO.author || !questionDTO.inGroup || !questionDTO.content) {
|
||||
res.status(400).json({ error: 'Missing required fields: identifier, author, inGroup, and content' });
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -102,7 +157,10 @@ export async function createQuestionHandler(req: Request, res: Response): Promis
|
|||
}
|
||||
}
|
||||
|
||||
export async function deleteQuestionHandler(req: Request, res: Response): Promise<void> {
|
||||
export async function deleteQuestionHandler(
|
||||
req: Request<GetQuestionIdPathParams, QuestionDTO, unknown, QuestionQueryParams>,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
const questionId = getQuestionId(req, res);
|
||||
|
||||
if (!questionId) {
|
||||
|
|
|
@ -1,13 +1,35 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { createSubmission, deleteSubmission, getSubmission } from '../services/submissions.js';
|
||||
import { createSubmission, deleteSubmission, getSubmission, getSubmissionsForLearningObjectAndAssignment } from '../services/submissions.js';
|
||||
import { SubmissionDTO } from '@dwengo-1/common/interfaces/submission';
|
||||
import { Language, languageMap } from '@dwengo-1/common/util/language';
|
||||
import { Submission } from '../entities/assignments/submission.entity';
|
||||
|
||||
interface SubmissionParams {
|
||||
hruid: string;
|
||||
id: number;
|
||||
}
|
||||
|
||||
interface SubmissionQuery {
|
||||
language: string;
|
||||
version: number;
|
||||
}
|
||||
|
||||
interface SubmissionsQuery extends SubmissionQuery {
|
||||
classId: string;
|
||||
assignmentId: number;
|
||||
studentUsername?: string;
|
||||
}
|
||||
|
||||
export async function getSubmissionsHandler(req: Request<SubmissionParams, Submission[], null, SubmissionsQuery>, res: Response): Promise<void> {
|
||||
const loHruid = req.params.hruid;
|
||||
const lang = languageMap[req.query.language] || Language.Dutch;
|
||||
const version = req.query.version || 1;
|
||||
|
||||
const submissions = await getSubmissionsForLearningObjectAndAssignment(loHruid, lang, version, req.query.classId, req.query.assignmentId);
|
||||
|
||||
res.json(submissions);
|
||||
}
|
||||
|
||||
export async function getSubmissionHandler(req: Request<SubmissionParams>, res: Response): Promise<void> {
|
||||
const lohruid = req.params.hruid;
|
||||
const submissionNumber = Number(req.params.id);
|
||||
|
|
|
@ -6,6 +6,22 @@ export class AssignmentRepository extends DwengoEntityRepository<Assignment> {
|
|||
public async findByClassAndId(within: Class, id: number): Promise<Assignment | null> {
|
||||
return this.findOne({ within: within, id: id });
|
||||
}
|
||||
public async findByClassIdAndAssignmentId(withinClass: string, id: number): Promise<Assignment | null> {
|
||||
return this.findOne({ within: { classId: withinClass }, id: id });
|
||||
}
|
||||
public async findAllByResponsibleTeacher(teacherUsername: string): Promise<Assignment[]> {
|
||||
return this.findAll({
|
||||
where: {
|
||||
within: {
|
||||
teachers: {
|
||||
$some: {
|
||||
username: teacherUsername,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
public async findAllAssignmentsInClass(within: Class): Promise<Assignment[]> {
|
||||
return this.findAll({ where: { within: within } });
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import { Group } from '../../entities/assignments/group.entity.js';
|
|||
import { Submission } from '../../entities/assignments/submission.entity.js';
|
||||
import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier.js';
|
||||
import { Student } from '../../entities/users/student.entity.js';
|
||||
import { Assignment } from '../../entities/assignments/assignment.entity';
|
||||
|
||||
export class SubmissionRepository extends DwengoEntityRepository<Submission> {
|
||||
public async findSubmissionByLearningObjectAndSubmissionNumber(
|
||||
|
@ -42,11 +43,58 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> {
|
|||
}
|
||||
|
||||
public async findAllSubmissionsForGroup(group: Group): Promise<Submission[]> {
|
||||
return this.find({ onBehalfOf: group });
|
||||
return this.find(
|
||||
{ onBehalfOf: group },
|
||||
{
|
||||
populate: ['onBehalfOf.members'],
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up all submissions for the given learning object which were submitted as part of the given assignment.
|
||||
* When forStudentUsername is set, only the submissions of the given user's group are shown.
|
||||
*/
|
||||
public async findAllSubmissionsForLearningObjectAndAssignment(
|
||||
loId: LearningObjectIdentifier,
|
||||
assignment: Assignment,
|
||||
forStudentUsername?: string
|
||||
): Promise<Submission[]> {
|
||||
const onBehalfOf = forStudentUsername
|
||||
? {
|
||||
assignment,
|
||||
members: {
|
||||
$some: {
|
||||
username: forStudentUsername,
|
||||
},
|
||||
},
|
||||
}
|
||||
: {
|
||||
assignment,
|
||||
};
|
||||
|
||||
return this.findAll({
|
||||
where: {
|
||||
learningObjectHruid: loId.hruid,
|
||||
learningObjectLanguage: loId.language,
|
||||
learningObjectVersion: loId.version,
|
||||
onBehalfOf,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
public async findAllSubmissionsForStudent(student: Student): Promise<Submission[]> {
|
||||
return this.find({ submitter: student });
|
||||
const result = await this.find(
|
||||
{ submitter: student },
|
||||
{
|
||||
populate: ['onBehalfOf.members'],
|
||||
}
|
||||
);
|
||||
|
||||
// Workaround: For some reason, without this MikroORM generates an UPDATE query with a syntax error in some tests
|
||||
this.em.clear();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async deleteSubmissionByLearningObjectAndSubmissionNumber(loId: LearningObjectIdentifier, submissionNumber: number): Promise<void> {
|
||||
|
|
|
@ -3,14 +3,17 @@ import { Question } from '../../entities/questions/question.entity.js';
|
|||
import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier.js';
|
||||
import { Student } from '../../entities/users/student.entity.js';
|
||||
import { LearningObject } from '../../entities/content/learning-object.entity.js';
|
||||
import { Group } from '../../entities/assignments/group.entity';
|
||||
import { Assignment } from '../../entities/assignments/assignment.entity';
|
||||
|
||||
export class QuestionRepository extends DwengoEntityRepository<Question> {
|
||||
public async createQuestion(question: { loId: LearningObjectIdentifier; author: Student; content: string }): Promise<Question> {
|
||||
public async createQuestion(question: { loId: LearningObjectIdentifier; author: Student; inGroup: Group; content: string }): Promise<Question> {
|
||||
const questionEntity = this.create({
|
||||
learningObjectHruid: question.loId.hruid,
|
||||
learningObjectLanguage: question.loId.language,
|
||||
learningObjectVersion: question.loId.version,
|
||||
author: question.author,
|
||||
inGroup: question.inGroup,
|
||||
content: question.content,
|
||||
timestamp: new Date(),
|
||||
});
|
||||
|
@ -18,6 +21,7 @@ export class QuestionRepository extends DwengoEntityRepository<Question> {
|
|||
questionEntity.learningObjectLanguage = question.loId.language;
|
||||
questionEntity.learningObjectVersion = question.loId.version;
|
||||
questionEntity.author = question.author;
|
||||
questionEntity.inGroup = question.inGroup;
|
||||
questionEntity.content = question.content;
|
||||
return this.insert(questionEntity);
|
||||
}
|
||||
|
@ -61,4 +65,36 @@ export class QuestionRepository extends DwengoEntityRepository<Question> {
|
|||
orderBy: { timestamp: 'DESC' }, // New to old
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up all questions for the given learning object which were asked as part of the given assignment.
|
||||
* When forStudentUsername is set, only the questions within the given user's group are shown.
|
||||
*/
|
||||
public async findAllQuestionsAboutLearningObjectInAssignment(
|
||||
loId: LearningObjectIdentifier,
|
||||
assignment: Assignment,
|
||||
forStudentUsername?: string
|
||||
): Promise<Question[]> {
|
||||
const inGroup = forStudentUsername
|
||||
? {
|
||||
assignment,
|
||||
members: {
|
||||
$some: {
|
||||
username: forStudentUsername,
|
||||
},
|
||||
},
|
||||
}
|
||||
: {
|
||||
assignment,
|
||||
};
|
||||
|
||||
return this.findAll({
|
||||
where: {
|
||||
learningObjectHruid: loId.hruid,
|
||||
learningObjectLanguage: loId.language,
|
||||
learningObjectVersion: loId.version,
|
||||
inGroup,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
|
||||
import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
|
||||
import { Class } from '../classes/class.entity.js';
|
||||
import { Group } from './group.entity.js';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
|
@ -35,5 +35,5 @@ export class Assignment {
|
|||
entity: () => Group,
|
||||
mappedBy: 'assignment',
|
||||
})
|
||||
groups!: Group[];
|
||||
groups!: Collection<Group>;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Entity, ManyToMany, ManyToOne, PrimaryKey } from '@mikro-orm/core';
|
||||
import { Collection, Entity, ManyToMany, ManyToOne, PrimaryKey } from '@mikro-orm/core';
|
||||
import { Assignment } from './assignment.entity.js';
|
||||
import { Student } from '../users/student.entity.js';
|
||||
import { GroupRepository } from '../../data/assignments/group-repository.js';
|
||||
|
@ -19,5 +19,5 @@ export class Group {
|
|||
@ManyToMany({
|
||||
entity: () => Student,
|
||||
})
|
||||
members!: Student[];
|
||||
members!: Collection<Student>;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,11 @@ export class Submission {
|
|||
@PrimaryKey({ type: 'integer', autoincrement: true })
|
||||
submissionNumber?: number;
|
||||
|
||||
@ManyToOne({
|
||||
entity: () => Group,
|
||||
})
|
||||
onBehalfOf!: Group;
|
||||
|
||||
@ManyToOne({
|
||||
entity: () => Student,
|
||||
})
|
||||
|
@ -29,12 +34,6 @@ export class Submission {
|
|||
@Property({ type: 'datetime' })
|
||||
submissionTime!: Date;
|
||||
|
||||
@ManyToOne({
|
||||
entity: () => Group,
|
||||
nullable: true,
|
||||
})
|
||||
onBehalfOf?: Group;
|
||||
|
||||
@Property({ type: 'json' })
|
||||
content!: string;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ import { Entity, Enum, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core';
|
|||
import { Student } from '../users/student.entity.js';
|
||||
import { QuestionRepository } from '../../data/questions/question-repository.js';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
import { Group } from '../assignments/group.entity';
|
||||
|
||||
@Entity({ repository: () => QuestionRepository })
|
||||
export class Question {
|
||||
|
@ -20,6 +21,9 @@ export class Question {
|
|||
@PrimaryKey({ type: 'integer', autoincrement: true })
|
||||
sequenceNumber?: number;
|
||||
|
||||
@ManyToOne({ entity: () => Group })
|
||||
inGroup!: Group;
|
||||
|
||||
@ManyToOne({
|
||||
entity: () => Student,
|
||||
})
|
||||
|
|
|
@ -1,7 +1,21 @@
|
|||
import { Group } from '../entities/assignments/group.entity.js';
|
||||
import { mapToAssignmentDTO } from './assignment.js';
|
||||
import { mapToStudentDTO } from './student.js';
|
||||
import { mapToAssignment, mapToAssignmentDTO, mapToAssignmentDTOId } from './assignment.js';
|
||||
import { mapToStudent, mapToStudentDTO } from './student.js';
|
||||
import { GroupDTO } from '@dwengo-1/common/interfaces/group';
|
||||
import { getGroupRepository } from '../data/repositories';
|
||||
import { AssignmentDTO } from '@dwengo-1/common/interfaces/assignment';
|
||||
import { Class } from '../entities/classes/class.entity';
|
||||
import { StudentDTO } from '@dwengo-1/common/interfaces/student';
|
||||
|
||||
export function mapToGroup(groupDto: GroupDTO, clazz: Class): Group {
|
||||
const assignmentDto = groupDto.assignment as AssignmentDTO;
|
||||
|
||||
return getGroupRepository().create({
|
||||
groupNumber: groupDto.groupNumber,
|
||||
assignment: mapToAssignment(assignmentDto, clazz),
|
||||
members: groupDto.members!.map((studentDto) => mapToStudent(studentDto as StudentDTO)),
|
||||
});
|
||||
}
|
||||
|
||||
export function mapToGroupDTO(group: Group): GroupDTO {
|
||||
return {
|
||||
|
@ -12,6 +26,16 @@ export function mapToGroupDTO(group: Group): GroupDTO {
|
|||
}
|
||||
|
||||
export function mapToGroupDTOId(group: Group): GroupDTO {
|
||||
return {
|
||||
assignment: mapToAssignmentDTOId(group.assignment),
|
||||
groupNumber: group.groupNumber!,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Map to group DTO where other objects are only referenced by their id.
|
||||
*/
|
||||
export function mapToShallowGroupDTO(group: Group): GroupDTO {
|
||||
return {
|
||||
assignment: group.assignment.id!,
|
||||
groupNumber: group.groupNumber!,
|
||||
|
|
|
@ -2,6 +2,7 @@ import { Question } from '../entities/questions/question.entity.js';
|
|||
import { mapToStudentDTO } from './student.js';
|
||||
import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question';
|
||||
import { LearningObjectIdentifier } from '@dwengo-1/common/interfaces/learning-content';
|
||||
import { mapToGroupDTOId } from './group';
|
||||
|
||||
function getLearningObjectIdentifier(question: Question): LearningObjectIdentifier {
|
||||
return {
|
||||
|
@ -21,6 +22,7 @@ export function mapToQuestionDTO(question: Question): QuestionDTO {
|
|||
learningObjectIdentifier,
|
||||
sequenceNumber: question.sequenceNumber!,
|
||||
author: mapToStudentDTO(question.author),
|
||||
inGroup: mapToGroupDTOId(question.inGroup),
|
||||
timestamp: question.timestamp.toISOString(),
|
||||
content: question.content,
|
||||
};
|
||||
|
|
|
@ -14,7 +14,7 @@ export function mapToSubmissionDTO(submission: Submission): SubmissionDTO {
|
|||
submissionNumber: submission.submissionNumber,
|
||||
submitter: mapToStudentDTO(submission.submitter),
|
||||
time: submission.submissionTime,
|
||||
group: submission.onBehalfOf ? mapToGroupDTO(submission.onBehalfOf) : undefined,
|
||||
group: mapToGroupDTO(submission.onBehalfOf),
|
||||
content: submission.content,
|
||||
};
|
||||
}
|
||||
|
@ -38,7 +38,6 @@ export function mapToSubmission(submissionDTO: SubmissionDTO): Submission {
|
|||
submission.submitter = mapToStudent(submissionDTO.submitter);
|
||||
// Submission.submissionTime = submissionDTO.time;
|
||||
// Submission.onBehalfOf = submissionDTO.group!;
|
||||
// TODO fix group
|
||||
submission.content = submissionDTO.content;
|
||||
|
||||
return submission;
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
import express from 'express';
|
||||
import { createSubmissionHandler, deleteSubmissionHandler, getSubmissionHandler } from '../controllers/submissions.js';
|
||||
import { createSubmissionHandler, deleteSubmissionHandler, getSubmissionHandler, getSubmissionsHandler } from '../controllers/submissions.js';
|
||||
const router = express.Router({ mergeParams: true });
|
||||
|
||||
// Root endpoint used to search objects
|
||||
router.get('/', (_req, res) => {
|
||||
res.json({
|
||||
submissions: ['0', '1'],
|
||||
});
|
||||
});
|
||||
router.get('/', getSubmissionsHandler);
|
||||
|
||||
router.post('/:id', createSubmissionHandler);
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
getSubmissionRepository,
|
||||
} from '../data/repositories.js';
|
||||
import { Group } from '../entities/assignments/group.entity.js';
|
||||
import { mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js';
|
||||
import { mapToGroupDTO, mapToShallowGroupDTO } from '../interfaces/group.js';
|
||||
import { mapToSubmissionDTO, mapToSubmissionDTOId } from '../interfaces/submission.js';
|
||||
import { GroupDTO } from '@dwengo-1/common/interfaces/group';
|
||||
import { SubmissionDTO, SubmissionDTOId } from '@dwengo-1/common/interfaces/submission';
|
||||
|
@ -38,7 +38,7 @@ export async function getGroup(classId: string, assignmentNumber: number, groupN
|
|||
return mapToGroupDTO(group);
|
||||
}
|
||||
|
||||
return mapToGroupDTOId(group);
|
||||
return mapToShallowGroupDTO(group);
|
||||
}
|
||||
|
||||
export async function createGroup(groupData: GroupDTO, classid: string, assignmentNumber: number): Promise<Group | null> {
|
||||
|
@ -103,7 +103,7 @@ export async function getAllGroups(classId: string, assignmentNumber: number, fu
|
|||
return groups.map(mapToGroupDTO);
|
||||
}
|
||||
|
||||
return groups.map(mapToGroupDTOId);
|
||||
return groups.map(mapToShallowGroupDTO);
|
||||
}
|
||||
|
||||
export async function getGroupSubmissions(
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { getAnswerRepository, getQuestionRepository } from '../data/repositories.js';
|
||||
import { getAnswerRepository, getAssignmentRepository, getClassRepository, getGroupRepository, getQuestionRepository } from '../data/repositories.js';
|
||||
import { mapToQuestionDTO, mapToQuestionDTOId } from '../interfaces/question.js';
|
||||
import { Question } from '../entities/questions/question.entity.js';
|
||||
import { Answer } from '../entities/questions/answer.entity.js';
|
||||
|
@ -8,6 +8,25 @@ import { LearningObjectIdentifier } from '../entities/content/learning-object-id
|
|||
import { mapToStudent } from '../interfaces/student.js';
|
||||
import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question';
|
||||
import { AnswerDTO, AnswerId } from '@dwengo-1/common/interfaces/answer';
|
||||
import { AssignmentDTO } from '@dwengo-1/common/interfaces/assignment';
|
||||
import { mapToAssignment } from '../interfaces/assignment';
|
||||
|
||||
export async function getQuestionsAboutLearningObjectInAssignment(
|
||||
loId: LearningObjectIdentifier,
|
||||
classId: string,
|
||||
assignmentId: number,
|
||||
full: boolean,
|
||||
studentUsername?: string
|
||||
): Promise<QuestionDTO[] | QuestionId[]> {
|
||||
const assignment = await getAssignmentRepository().findByClassIdAndAssignmentId(classId, assignmentId);
|
||||
|
||||
const questions = await getQuestionRepository().findAllQuestionsAboutLearningObjectInAssignment(loId, assignment!, studentUsername);
|
||||
|
||||
if (full) {
|
||||
return questions.map((q) => mapToQuestionDTO(q));
|
||||
}
|
||||
return questions.map((q) => mapToQuestionDTOId(q));
|
||||
}
|
||||
|
||||
export async function getAllQuestions(id: LearningObjectIdentifier, full: boolean): Promise<QuestionDTO[] | QuestionId[]> {
|
||||
const questionRepository: QuestionRepository = getQuestionRepository();
|
||||
|
@ -76,10 +95,15 @@ export async function createQuestion(questionDTO: QuestionDTO): Promise<Question
|
|||
version: questionDTO.learningObjectIdentifier.version ?? 1,
|
||||
};
|
||||
|
||||
const clazz = await getClassRepository().findById((questionDTO.inGroup.assignment as AssignmentDTO).class);
|
||||
const assignment = mapToAssignment(questionDTO.inGroup.assignment as AssignmentDTO, clazz!);
|
||||
const inGroup = await getGroupRepository().findByAssignmentAndGroupNumber(assignment, questionDTO.inGroup.groupNumber);
|
||||
|
||||
try {
|
||||
await questionRepository.createQuestion({
|
||||
loId,
|
||||
author,
|
||||
inGroup: inGroup!,
|
||||
content: questionDTO.content,
|
||||
});
|
||||
} catch (_) {
|
||||
|
|
|
@ -7,7 +7,7 @@ import {
|
|||
getSubmissionRepository,
|
||||
} from '../data/repositories.js';
|
||||
import { mapToClassDTO } from '../interfaces/class.js';
|
||||
import { mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js';
|
||||
import { mapToGroupDTO, mapToShallowGroupDTO } from '../interfaces/group.js';
|
||||
import { mapToStudent, mapToStudentDTO } from '../interfaces/student.js';
|
||||
import { mapToSubmissionDTO, mapToSubmissionDTOId } from '../interfaces/submission.js';
|
||||
import { getAllAssignments } from './assignments.js';
|
||||
|
@ -23,6 +23,7 @@ import { GroupDTO } from '@dwengo-1/common/interfaces/group';
|
|||
import { SubmissionDTO, SubmissionDTOId } from '@dwengo-1/common/interfaces/submission';
|
||||
import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question';
|
||||
import { ClassJoinRequestDTO } from '@dwengo-1/common/interfaces/class-join-request';
|
||||
import { Submission } from '../entities/assignments/submission.entity';
|
||||
|
||||
export async function getAllStudents(full: boolean): Promise<StudentDTO[] | string[]> {
|
||||
const studentRepository = getStudentRepository();
|
||||
|
@ -100,14 +101,15 @@ export async function getStudentGroups(username: string, full: boolean): Promise
|
|||
return groups.map(mapToGroupDTO);
|
||||
}
|
||||
|
||||
return groups.map(mapToGroupDTOId);
|
||||
return groups.map(mapToShallowGroupDTO);
|
||||
}
|
||||
|
||||
export async function getStudentSubmissions(username: string, full: boolean): Promise<SubmissionDTO[] | SubmissionDTOId[]> {
|
||||
const student = await fetchStudent(username);
|
||||
|
||||
const submissionRepository = getSubmissionRepository();
|
||||
const submissions = await submissionRepository.findAllSubmissionsForStudent(student);
|
||||
|
||||
const submissions: Submission[] = await submissionRepository.findAllSubmissionsForStudent(student);
|
||||
|
||||
if (full) {
|
||||
return submissions.map(mapToSubmissionDTO);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { getSubmissionRepository } from '../data/repositories.js';
|
||||
import { getAssignmentRepository, getSubmissionRepository } from '../data/repositories.js';
|
||||
import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js';
|
||||
import { mapToSubmission, mapToSubmissionDTO } from '../interfaces/submission.js';
|
||||
import { SubmissionDTO } from '@dwengo-1/common/interfaces/submission';
|
||||
|
@ -55,3 +55,22 @@ export async function deleteSubmission(
|
|||
|
||||
return submission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the submissions made by on behalf of any group the given student is in.
|
||||
*/
|
||||
export async function getSubmissionsForLearningObjectAndAssignment(
|
||||
learningObjectHruid: string,
|
||||
language: Language,
|
||||
version: number,
|
||||
classId: string,
|
||||
assignmentId: number,
|
||||
studentUsername?: string
|
||||
): Promise<SubmissionDTO[]> {
|
||||
const loId = new LearningObjectIdentifier(learningObjectHruid, language, version);
|
||||
const assignment = await getAssignmentRepository().findByClassIdAndAssignmentId(classId, assignmentId);
|
||||
|
||||
const submissions = await getSubmissionRepository().findAllSubmissionsForLearningObjectAndAssignment(loId, assignment!, studentUsername);
|
||||
|
||||
return submissions.map((s) => mapToSubmissionDTO(s));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue