# Conflicts:
#	backend/src/controllers/questions.ts
#	backend/src/controllers/submissions.ts
#	backend/src/data/questions/question-repository.ts
#	backend/src/interfaces/group.ts
#	backend/src/interfaces/question.ts
#	backend/src/interfaces/submission.ts
#	backend/src/routes/submissions.ts
#	backend/src/services/groups.ts
#	backend/src/services/questions.ts
#	backend/src/services/students.ts
#	backend/src/services/submissions.ts
#	common/src/interfaces/question.ts
This commit is contained in:
Gerald Schmittinger 2025-04-09 20:25:30 +02:00
commit d6dd7fb3bf
90 changed files with 2934 additions and 792 deletions

View file

@ -18,6 +18,14 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> {
});
}
public async findByLearningObject(loId: LearningObjectIdentifier): Promise<Submission[]> {
return this.find({
learningObjectHruid: loId.hruid,
learningObjectLanguage: loId.language,
learningObjectVersion: loId.version,
});
}
public async findMostRecentSubmissionForStudent(loId: LearningObjectIdentifier, submitter: Student): Promise<Submission | null> {
return this.findOne(
{

View file

@ -2,6 +2,7 @@ import { DwengoEntityRepository } from '../dwengo-entity-repository.js';
import { Answer } from '../../entities/questions/answer.entity.js';
import { Question } from '../../entities/questions/question.entity.js';
import { Teacher } from '../../entities/users/teacher.entity.js';
import { Loaded } from '@mikro-orm/core';
export class AnswerRepository extends DwengoEntityRepository<Answer> {
public async createAnswer(answer: { toQuestion: Question; author: Teacher; content: string }): Promise<Answer> {
@ -19,10 +20,21 @@ export class AnswerRepository extends DwengoEntityRepository<Answer> {
orderBy: { sequenceNumber: 'ASC' },
});
}
public async findAnswer(question: Question, sequenceNumber: number): Promise<Loaded<Answer> | null> {
return this.findOne({
toQuestion: question,
sequenceNumber,
});
}
public async removeAnswerByQuestionAndSequenceNumber(question: Question, sequenceNumber: number): Promise<void> {
return this.deleteWhere({
toQuestion: question,
sequenceNumber: sequenceNumber,
});
}
public async updateContent(answer: Answer, newContent: string): Promise<Answer> {
answer.content = newContent;
await this.save(answer);
return answer;
}
}

View file

@ -3,8 +3,9 @@ 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 { Assignment } from '../../entities/assignments/assignment.entity.js';
import { Loaded } from '@mikro-orm/core';
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; inGroup: Group; content: string }): Promise<Question> {
@ -59,6 +60,14 @@ export class QuestionRepository extends DwengoEntityRepository<Question> {
});
}
public async findAllByAssignment(assignment: Assignment): Promise<Question[]> {
return this.find({
author: assignment.groups.flatMap((group) => group.members),
learningObjectHruid: assignment.learningPathHruid,
learningObjectLanguage: assignment.learningPathLanguage,
});
}
public async findAllByAuthor(author: Student): Promise<Question[]> {
return this.findAll({
where: { author },
@ -97,4 +106,19 @@ export class QuestionRepository extends DwengoEntityRepository<Question> {
},
});
}
public async findByLearningObjectAndSequenceNumber(loId: LearningObjectIdentifier, sequenceNumber: number): Promise<Loaded<Question> | null> {
return this.findOne({
learningObjectHruid: loId.hruid,
learningObjectLanguage: loId.language,
learningObjectVersion: loId.version,
sequenceNumber,
});
}
public async updateContent(question: Question, newContent: string): Promise<Question> {
question.content = newContent;
await this.save(question);
return question;
}
}