merge: merged into feat/error-flow-backend
This commit is contained in:
commit
effaeb0277
249 changed files with 6832 additions and 3679 deletions
|
@ -3,13 +3,13 @@ import { Assignment } from '../../entities/assignments/assignment.entity.js';
|
|||
import { Class } from '../../entities/classes/class.entity.js';
|
||||
|
||||
export class AssignmentRepository extends DwengoEntityRepository<Assignment> {
|
||||
public findByClassAndId(within: Class, id: number): Promise<Assignment | null> {
|
||||
public async findByClassAndId(within: Class, id: number): Promise<Assignment | null> {
|
||||
return this.findOne({ within: within, id: id });
|
||||
}
|
||||
public findAllAssignmentsInClass(within: Class): Promise<Assignment[]> {
|
||||
public async findAllAssignmentsInClass(within: Class): Promise<Assignment[]> {
|
||||
return this.findAll({ where: { within: within } });
|
||||
}
|
||||
public deleteByClassAndId(within: Class, id: number): Promise<void> {
|
||||
public async deleteByClassAndId(within: Class, id: number): Promise<void> {
|
||||
return this.deleteWhere({ within: within, id: id });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import { Assignment } from '../../entities/assignments/assignment.entity.js';
|
|||
import { Student } from '../../entities/users/student.entity.js';
|
||||
|
||||
export class GroupRepository extends DwengoEntityRepository<Group> {
|
||||
public findByAssignmentAndGroupNumber(assignment: Assignment, groupNumber: number): Promise<Group | null> {
|
||||
public async findByAssignmentAndGroupNumber(assignment: Assignment, groupNumber: number): Promise<Group | null> {
|
||||
return this.findOne(
|
||||
{
|
||||
assignment: assignment,
|
||||
|
@ -13,16 +13,16 @@ export class GroupRepository extends DwengoEntityRepository<Group> {
|
|||
{ populate: ['members'] }
|
||||
);
|
||||
}
|
||||
public findAllGroupsForAssignment(assignment: Assignment): Promise<Group[]> {
|
||||
public async findAllGroupsForAssignment(assignment: Assignment): Promise<Group[]> {
|
||||
return this.findAll({
|
||||
where: { assignment: assignment },
|
||||
populate: ['members'],
|
||||
});
|
||||
}
|
||||
public findAllGroupsWithStudent(student: Student): Promise<Group[]> {
|
||||
public async findAllGroupsWithStudent(student: Student): Promise<Group[]> {
|
||||
return this.find({ members: student }, { populate: ['members'] });
|
||||
}
|
||||
public deleteByAssignmentAndGroupNumber(assignment: Assignment, groupNumber: number) {
|
||||
public async deleteByAssignmentAndGroupNumber(assignment: Assignment, groupNumber: number): Promise<void> {
|
||||
return this.deleteWhere({
|
||||
assignment: assignment,
|
||||
groupNumber: groupNumber,
|
||||
|
|
|
@ -5,7 +5,10 @@ import { LearningObjectIdentifier } from '../../entities/content/learning-object
|
|||
import { Student } from '../../entities/users/student.entity.js';
|
||||
|
||||
export class SubmissionRepository extends DwengoEntityRepository<Submission> {
|
||||
public findSubmissionByLearningObjectAndSubmissionNumber(loId: LearningObjectIdentifier, submissionNumber: number): Promise<Submission | null> {
|
||||
public async findSubmissionByLearningObjectAndSubmissionNumber(
|
||||
loId: LearningObjectIdentifier,
|
||||
submissionNumber: number
|
||||
): Promise<Submission | null> {
|
||||
return this.findOne({
|
||||
learningObjectHruid: loId.hruid,
|
||||
learningObjectLanguage: loId.language,
|
||||
|
@ -14,6 +17,7 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> {
|
|||
});
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
public findByLearningObject(loId: LearningObjectIdentifier): Promise<Submission[]> {
|
||||
return this.find({
|
||||
learningObjectHruid: loId.hruid,
|
||||
|
@ -23,6 +27,9 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> {
|
|||
}
|
||||
|
||||
public findMostRecentSubmissionForStudent(loId: LearningObjectIdentifier, submitter: Student): Promise<Submission | null> {
|
||||
=======
|
||||
public async findMostRecentSubmissionForStudent(loId: LearningObjectIdentifier, submitter: Student): Promise<Submission | null> {
|
||||
>>>>>>> 6c3dbc99bb1afb79fa867505e52656c49bada1b6
|
||||
return this.findOne(
|
||||
{
|
||||
learningObjectHruid: loId.hruid,
|
||||
|
@ -34,7 +41,7 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> {
|
|||
);
|
||||
}
|
||||
|
||||
public findMostRecentSubmissionForGroup(loId: LearningObjectIdentifier, group: Group): Promise<Submission | null> {
|
||||
public async findMostRecentSubmissionForGroup(loId: LearningObjectIdentifier, group: Group): Promise<Submission | null> {
|
||||
return this.findOne(
|
||||
{
|
||||
learningObjectHruid: loId.hruid,
|
||||
|
@ -46,15 +53,15 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> {
|
|||
);
|
||||
}
|
||||
|
||||
public findAllSubmissionsForGroup(group: Group): Promise<Submission[]> {
|
||||
public async findAllSubmissionsForGroup(group: Group): Promise<Submission[]> {
|
||||
return this.find({ onBehalfOf: group });
|
||||
}
|
||||
|
||||
public findAllSubmissionsForStudent(student: Student): Promise<Submission[]> {
|
||||
public async findAllSubmissionsForStudent(student: Student): Promise<Submission[]> {
|
||||
return this.find({ submitter: student });
|
||||
}
|
||||
|
||||
public deleteSubmissionByLearningObjectAndSubmissionNumber(loId: LearningObjectIdentifier, submissionNumber: number): Promise<void> {
|
||||
public async deleteSubmissionByLearningObjectAndSubmissionNumber(loId: LearningObjectIdentifier, submissionNumber: number): Promise<void> {
|
||||
return this.deleteWhere({
|
||||
learningObjectHruid: loId.hruid,
|
||||
learningObjectLanguage: loId.language,
|
||||
|
|
|
@ -2,15 +2,19 @@ import { DwengoEntityRepository } from '../dwengo-entity-repository.js';
|
|||
import { Class } from '../../entities/classes/class.entity.js';
|
||||
import { ClassJoinRequest } from '../../entities/classes/class-join-request.entity.js';
|
||||
import { Student } from '../../entities/users/student.entity.js';
|
||||
import { ClassJoinRequestStatus } from '@dwengo-1/common/util/class-join-request';
|
||||
|
||||
export class ClassJoinRequestRepository extends DwengoEntityRepository<ClassJoinRequest> {
|
||||
public findAllRequestsBy(requester: Student): Promise<ClassJoinRequest[]> {
|
||||
public async findAllRequestsBy(requester: Student): Promise<ClassJoinRequest[]> {
|
||||
return this.findAll({ where: { requester: requester } });
|
||||
}
|
||||
public findAllOpenRequestsTo(clazz: Class): Promise<ClassJoinRequest[]> {
|
||||
return this.findAll({ where: { class: clazz } });
|
||||
public async findAllOpenRequestsTo(clazz: Class): Promise<ClassJoinRequest[]> {
|
||||
return this.findAll({ where: { class: clazz, status: ClassJoinRequestStatus.Open } }); // TODO check if works like this
|
||||
}
|
||||
public deleteBy(requester: Student, clazz: Class): Promise<void> {
|
||||
public async findByStudentAndClass(requester: Student, clazz: Class): Promise<ClassJoinRequest | null> {
|
||||
return this.findOne({ requester, class: clazz });
|
||||
}
|
||||
public async deleteBy(requester: Student, clazz: Class): Promise<void> {
|
||||
return this.deleteWhere({ requester: requester, class: clazz });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,20 +4,20 @@ import { Student } from '../../entities/users/student.entity.js';
|
|||
import { Teacher } from '../../entities/users/teacher.entity';
|
||||
|
||||
export class ClassRepository extends DwengoEntityRepository<Class> {
|
||||
public findById(id: string): Promise<Class | null> {
|
||||
public async findById(id: string): Promise<Class | null> {
|
||||
return this.findOne({ classId: id }, { populate: ['students', 'teachers'] });
|
||||
}
|
||||
public deleteById(id: string): Promise<void> {
|
||||
public async deleteById(id: string): Promise<void> {
|
||||
return this.deleteWhere({ classId: id });
|
||||
}
|
||||
public findByStudent(student: Student): Promise<Class[]> {
|
||||
public async findByStudent(student: Student): Promise<Class[]> {
|
||||
return this.find(
|
||||
{ students: student },
|
||||
{ populate: ['students', 'teachers'] } // Voegt student en teacher objecten toe
|
||||
);
|
||||
}
|
||||
|
||||
public findByTeacher(teacher: Teacher): Promise<Class[]> {
|
||||
public async findByTeacher(teacher: Teacher): Promise<Class[]> {
|
||||
return this.find({ teachers: teacher }, { populate: ['students', 'teachers'] });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,16 +4,16 @@ import { TeacherInvitation } from '../../entities/classes/teacher-invitation.ent
|
|||
import { Teacher } from '../../entities/users/teacher.entity.js';
|
||||
|
||||
export class TeacherInvitationRepository extends DwengoEntityRepository<TeacherInvitation> {
|
||||
public findAllInvitationsForClass(clazz: Class): Promise<TeacherInvitation[]> {
|
||||
public async findAllInvitationsForClass(clazz: Class): Promise<TeacherInvitation[]> {
|
||||
return this.findAll({ where: { class: clazz } });
|
||||
}
|
||||
public findAllInvitationsBy(sender: Teacher): Promise<TeacherInvitation[]> {
|
||||
public async findAllInvitationsBy(sender: Teacher): Promise<TeacherInvitation[]> {
|
||||
return this.findAll({ where: { sender: sender } });
|
||||
}
|
||||
public findAllInvitationsFor(receiver: Teacher): Promise<TeacherInvitation[]> {
|
||||
public async findAllInvitationsFor(receiver: Teacher): Promise<TeacherInvitation[]> {
|
||||
return this.findAll({ where: { receiver: receiver } });
|
||||
}
|
||||
public deleteBy(clazz: Class, sender: Teacher, receiver: Teacher): Promise<void> {
|
||||
public async deleteBy(clazz: Class, sender: Teacher, receiver: Teacher): Promise<void> {
|
||||
return this.deleteWhere({
|
||||
sender: sender,
|
||||
receiver: receiver,
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { DwengoEntityRepository } from '../dwengo-entity-repository.js';
|
||||
import { Attachment } from '../../entities/content/attachment.entity.js';
|
||||
import { Language } from '../../entities/content/language';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier';
|
||||
|
||||
export class AttachmentRepository extends DwengoEntityRepository<Attachment> {
|
||||
public findByLearningObjectIdAndName(learningObjectId: LearningObjectIdentifier, name: string): Promise<Attachment | null> {
|
||||
public async findByLearningObjectIdAndName(learningObjectId: LearningObjectIdentifier, name: string): Promise<Attachment | null> {
|
||||
return this.findOne({
|
||||
learningObject: {
|
||||
hruid: learningObjectId.hruid,
|
||||
|
@ -15,7 +15,11 @@ export class AttachmentRepository extends DwengoEntityRepository<Attachment> {
|
|||
});
|
||||
}
|
||||
|
||||
public findByMostRecentVersionOfLearningObjectAndName(hruid: string, language: Language, attachmentName: string): Promise<Attachment | null> {
|
||||
public async findByMostRecentVersionOfLearningObjectAndName(
|
||||
hruid: string,
|
||||
language: Language,
|
||||
attachmentName: string
|
||||
): Promise<Attachment | null> {
|
||||
return this.findOne(
|
||||
{
|
||||
learningObject: {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { DwengoEntityRepository } from '../dwengo-entity-repository.js';
|
||||
import { LearningObject } from '../../entities/content/learning-object.entity.js';
|
||||
import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier.js';
|
||||
import { Language } from '../../entities/content/language.js';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
import { Teacher } from '../../entities/users/teacher.entity.js';
|
||||
|
||||
export class LearningObjectRepository extends DwengoEntityRepository<LearningObject> {
|
||||
public findByIdentifier(identifier: LearningObjectIdentifier): Promise<LearningObject | null> {
|
||||
public async findByIdentifier(identifier: LearningObjectIdentifier): Promise<LearningObject | null> {
|
||||
return this.findOne(
|
||||
{
|
||||
hruid: identifier.hruid,
|
||||
|
@ -18,7 +18,7 @@ export class LearningObjectRepository extends DwengoEntityRepository<LearningObj
|
|||
);
|
||||
}
|
||||
|
||||
public findLatestByHruidAndLanguage(hruid: string, language: Language) {
|
||||
public async findLatestByHruidAndLanguage(hruid: string, language: Language): Promise<LearningObject | null> {
|
||||
return this.findOne(
|
||||
{
|
||||
hruid: hruid,
|
||||
|
@ -33,7 +33,7 @@ export class LearningObjectRepository extends DwengoEntityRepository<LearningObj
|
|||
);
|
||||
}
|
||||
|
||||
public findAllByTeacher(teacher: Teacher): Promise<LearningObject[]> {
|
||||
public async findAllByTeacher(teacher: Teacher): Promise<LearningObject[]> {
|
||||
return this.find(
|
||||
{ admins: teacher },
|
||||
{ populate: ['admins'] } // Make sure to load admin relations
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { DwengoEntityRepository } from '../dwengo-entity-repository.js';
|
||||
import { LearningPath } from '../../entities/content/learning-path.entity.js';
|
||||
import { Language } from '../../entities/content/language.js';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
|
||||
export class LearningPathRepository extends DwengoEntityRepository<LearningPath> {
|
||||
public findByHruidAndLanguage(hruid: string, language: Language): Promise<LearningPath | null> {
|
||||
public async findByHruidAndLanguage(hruid: string, language: Language): Promise<LearningPath | null> {
|
||||
return this.findOne({ hruid: hruid, language: language }, { populate: ['nodes', 'nodes.transitions'] });
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ export abstract class DwengoEntityRepository<T extends object> extends EntityRep
|
|||
}
|
||||
await this.getEntityManager().persistAndFlush(entity);
|
||||
}
|
||||
public async deleteWhere(query: FilterQuery<T>) {
|
||||
public async deleteWhere(query: FilterQuery<T>): Promise<void> {
|
||||
const toDelete = await this.findOne(query);
|
||||
const em = this.getEntityManager();
|
||||
if (toDelete) {
|
||||
|
|
|
@ -4,7 +4,7 @@ import { Question } from '../../entities/questions/question.entity.js';
|
|||
import { Teacher } from '../../entities/users/teacher.entity.js';
|
||||
|
||||
export class AnswerRepository extends DwengoEntityRepository<Answer> {
|
||||
public createAnswer(answer: { toQuestion: Question; author: Teacher; content: string }): Promise<Answer> {
|
||||
public async createAnswer(answer: { toQuestion: Question; author: Teacher; content: string }): Promise<Answer> {
|
||||
const answerEntity = this.create({
|
||||
toQuestion: answer.toQuestion,
|
||||
author: answer.author,
|
||||
|
@ -13,13 +13,13 @@ export class AnswerRepository extends DwengoEntityRepository<Answer> {
|
|||
});
|
||||
return this.insert(answerEntity);
|
||||
}
|
||||
public findAllAnswersToQuestion(question: Question): Promise<Answer[]> {
|
||||
public async findAllAnswersToQuestion(question: Question): Promise<Answer[]> {
|
||||
return this.findAll({
|
||||
where: { toQuestion: question },
|
||||
orderBy: { sequenceNumber: 'ASC' },
|
||||
});
|
||||
}
|
||||
public removeAnswerByQuestionAndSequenceNumber(question: Question, sequenceNumber: number): Promise<void> {
|
||||
public async removeAnswerByQuestionAndSequenceNumber(question: Question, sequenceNumber: number): Promise<void> {
|
||||
return this.deleteWhere({
|
||||
toQuestion: question,
|
||||
sequenceNumber: sequenceNumber,
|
||||
|
|
|
@ -6,7 +6,7 @@ import { LearningObject } from '../../entities/content/learning-object.entity.js
|
|||
import { Assignment } from '../../entities/assignments/assignment.entity.js';
|
||||
|
||||
export class QuestionRepository extends DwengoEntityRepository<Question> {
|
||||
public createQuestion(question: { loId: LearningObjectIdentifier; author: Student; content: string }): Promise<Question> {
|
||||
public async createQuestion(question: { loId: LearningObjectIdentifier; author: Student; content: string }): Promise<Question> {
|
||||
const questionEntity = this.create({
|
||||
learningObjectHruid: question.loId.hruid,
|
||||
learningObjectLanguage: question.loId.language,
|
||||
|
@ -22,7 +22,7 @@ export class QuestionRepository extends DwengoEntityRepository<Question> {
|
|||
questionEntity.content = question.content;
|
||||
return this.insert(questionEntity);
|
||||
}
|
||||
public findAllQuestionsAboutLearningObject(loId: LearningObjectIdentifier): Promise<Question[]> {
|
||||
public async findAllQuestionsAboutLearningObject(loId: LearningObjectIdentifier): Promise<Question[]> {
|
||||
return this.findAll({
|
||||
where: {
|
||||
learningObjectHruid: loId.hruid,
|
||||
|
@ -34,7 +34,7 @@ export class QuestionRepository extends DwengoEntityRepository<Question> {
|
|||
},
|
||||
});
|
||||
}
|
||||
public removeQuestionByLearningObjectAndSequenceNumber(loId: LearningObjectIdentifier, sequenceNumber: number): Promise<void> {
|
||||
public async removeQuestionByLearningObjectAndSequenceNumber(loId: LearningObjectIdentifier, sequenceNumber: number): Promise<void> {
|
||||
return this.deleteWhere({
|
||||
learningObjectHruid: loId.hruid,
|
||||
learningObjectLanguage: loId.language,
|
||||
|
@ -56,11 +56,18 @@ export class QuestionRepository extends DwengoEntityRepository<Question> {
|
|||
});
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
public 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 },
|
||||
orderBy: { timestamp: 'DESC' }, // New to old
|
||||
>>>>>>> 6c3dbc99bb1afb79fa867505e52656c49bada1b6
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,8 +34,8 @@ let entityManager: EntityManager | undefined;
|
|||
/**
|
||||
* Execute all the database operations within the function f in a single transaction.
|
||||
*/
|
||||
export function transactional<T>(f: () => Promise<T>) {
|
||||
entityManager?.transactional(f);
|
||||
export async function transactional<T>(f: () => Promise<T>): Promise<void> {
|
||||
await entityManager?.transactional(f);
|
||||
}
|
||||
|
||||
function repositoryGetter<T extends AnyEntity, R extends EntityRepository<T>>(entity: EntityName<T>): () => R {
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
export interface Theme {
|
||||
title: string;
|
||||
hruids: string[];
|
||||
}
|
||||
import { Theme } from '@dwengo-1/common/interfaces/theme';
|
||||
|
||||
export const themes: Theme[] = [
|
||||
{
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
import { Student } from '../../entities/users/student.entity.js';
|
||||
import { DwengoEntityRepository } from '../dwengo-entity-repository.js';
|
||||
// Import { UserRepository } from './user-repository.js';
|
||||
|
||||
// Export class StudentRepository extends UserRepository<Student> {}
|
||||
|
||||
export class StudentRepository extends DwengoEntityRepository<Student> {
|
||||
public findByUsername(username: string): Promise<Student | null> {
|
||||
public async findByUsername(username: string): Promise<Student | null> {
|
||||
return this.findOne({ username: username });
|
||||
}
|
||||
public deleteByUsername(username: string): Promise<void> {
|
||||
public async deleteByUsername(username: string): Promise<void> {
|
||||
return this.deleteWhere({ username: username });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,10 @@ import { Teacher } from '../../entities/users/teacher.entity.js';
|
|||
import { DwengoEntityRepository } from '../dwengo-entity-repository.js';
|
||||
|
||||
export class TeacherRepository extends DwengoEntityRepository<Teacher> {
|
||||
public findByUsername(username: string): Promise<Teacher | null> {
|
||||
public async findByUsername(username: string): Promise<Teacher | null> {
|
||||
return this.findOne({ username: username });
|
||||
}
|
||||
public deleteByUsername(username: string): Promise<void> {
|
||||
public async deleteByUsername(username: string): Promise<void> {
|
||||
return this.deleteWhere({ username: username });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,10 @@ import { DwengoEntityRepository } from '../dwengo-entity-repository.js';
|
|||
import { User } from '../../entities/users/user.entity.js';
|
||||
|
||||
export class UserRepository<T extends User> extends DwengoEntityRepository<T> {
|
||||
public findByUsername(username: string): Promise<T | null> {
|
||||
public async findByUsername(username: string): Promise<T | null> {
|
||||
return this.findOne({ username } as Partial<T>);
|
||||
}
|
||||
public deleteByUsername(username: string): Promise<void> {
|
||||
public async deleteByUsername(username: string): Promise<void> {
|
||||
return this.deleteWhere({ username } as Partial<T>);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue