merge: merge fix/183-post-assignment into dev
This commit is contained in:
		
						commit
						5a593cb88f
					
				
					 67 changed files with 2205 additions and 2129 deletions
				
			
		
							
								
								
									
										21
									
								
								backend/.env-old
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								backend/.env-old
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,21 @@ | |||
| PORT=3000 | ||||
| DWENGO_DB_HOST=db | ||||
| DWENGO_DB_PORT=5432 | ||||
| DWENGO_DB_USERNAME=postgres | ||||
| DWENGO_DB_PASSWORD=postgres | ||||
| DWENGO_DB_UPDATE=false | ||||
| 
 | ||||
| DWENGO_AUTH_STUDENT_URL=http://localhost/idp/realms/student | ||||
| DWENGO_AUTH_STUDENT_CLIENT_ID=dwengo | ||||
| DWENGO_AUTH_STUDENT_JWKS_ENDPOINT=http://idp:7080/idp/realms/student/protocol/openid-connect/certs | ||||
| DWENGO_AUTH_TEACHER_URL=http://localhost/idp/realms/teacher | ||||
| DWENGO_AUTH_TEACHER_CLIENT_ID=dwengo | ||||
| DWENGO_AUTH_TEACHER_JWKS_ENDPOINT=http://idp:7080/idp/realms/teacher/protocol/openid-connect/certs | ||||
| 
 | ||||
| # Allow Vite dev-server to access the backend (for testing purposes). Don't forget to remove this in production! | ||||
| #DWENGO_CORS_ALLOWED_ORIGINS=http://localhost/,127.0.0.1:80,http://127.0.0.1,http://localhost:80,http://127.0.0.1:80,localhost | ||||
| DWENGO_CORS_ALLOWED_ORIGINS=http://localhost/*,http://idp:7080,https://idp:7080 | ||||
| 
 | ||||
| # Logging and monitoring | ||||
| 
 | ||||
| LOKI_HOST=http://logging:3102 | ||||
|  | @ -6,8 +6,9 @@ WORKDIR /app/dwengo | |||
| 
 | ||||
| COPY package*.json ./ | ||||
| COPY backend/package.json ./backend/ | ||||
| # Backend depends on common | ||||
| # Backend depends on common and docs | ||||
| COPY common/package.json ./common/ | ||||
| COPY docs/package.json ./docs/ | ||||
| 
 | ||||
| RUN npm install --silent | ||||
| 
 | ||||
|  | @ -34,6 +35,7 @@ COPY ./backend/i18n ./i18n | |||
| 
 | ||||
| COPY --from=build-stage /app/dwengo/common/dist ./common/dist | ||||
| COPY --from=build-stage /app/dwengo/backend/dist ./backend/dist | ||||
| COPY --from=build-stage /app/dwengo/docs/api/swagger.json ./docs/api/swagger.json | ||||
| 
 | ||||
| COPY package*.json ./ | ||||
| COPY backend/package.json ./backend/ | ||||
|  | @ -42,7 +44,6 @@ COPY common/package.json ./common/ | |||
| 
 | ||||
| RUN npm install --silent --only=production | ||||
| 
 | ||||
| COPY ./docs ./docs | ||||
| COPY ./backend/i18n ./backend/i18n | ||||
| 
 | ||||
| EXPOSE 3000 | ||||
|  |  | |||
|  | @ -12,7 +12,7 @@ | |||
|         "format": "prettier --write src/", | ||||
|         "format-check": "prettier --check src/", | ||||
|         "lint": "eslint . --fix", | ||||
|         "pretest:unit": "npm run build", | ||||
|         "pretest:unit": "tsx ../docs/api/generate.ts && npm run build", | ||||
|         "test:unit": "vitest --run" | ||||
|     }, | ||||
|     "dependencies": { | ||||
|  |  | |||
|  | @ -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 }); | ||||
| } | ||||
|  | @ -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 }, { populate: [ "groups", "groups.members" ]}); | ||||
|     } | ||||
|     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 }, populate: [ "groups", "groups.members" ] }); | ||||
|     } | ||||
|  |  | |||
|  | @ -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( | ||||
|  | @ -50,11 +51,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> { | ||||
|  |  | |||
|  | @ -2,14 +2,14 @@ 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'; | ||||
| import { ClassStatus } from '@dwengo-1/common/util/class-join-request'; | ||||
| 
 | ||||
| export class ClassJoinRequestRepository extends DwengoEntityRepository<ClassJoinRequest> { | ||||
|     public async findAllRequestsBy(requester: Student): Promise<ClassJoinRequest[]> { | ||||
|         return this.findAll({ where: { requester: requester } }); | ||||
|     } | ||||
|     public async findAllOpenRequestsTo(clazz: Class): Promise<ClassJoinRequest[]> { | ||||
|         return this.findAll({ where: { class: clazz, status: ClassJoinRequestStatus.Open } }); // TODO check if works like this
 | ||||
|         return this.findAll({ where: { class: clazz, status: ClassStatus.Open } }); // TODO check if works like this
 | ||||
|     } | ||||
|     public async findByStudentAndClass(requester: Student, clazz: Class): Promise<ClassJoinRequest | null> { | ||||
|         return this.findOne({ requester, class: clazz }); | ||||
|  |  | |||
|  | @ -2,6 +2,7 @@ import { DwengoEntityRepository } from '../dwengo-entity-repository.js'; | |||
| import { Class } from '../../entities/classes/class.entity.js'; | ||||
| import { TeacherInvitation } from '../../entities/classes/teacher-invitation.entity.js'; | ||||
| import { Teacher } from '../../entities/users/teacher.entity.js'; | ||||
| import { ClassStatus } from '@dwengo-1/common/util/class-join-request'; | ||||
| 
 | ||||
| export class TeacherInvitationRepository extends DwengoEntityRepository<TeacherInvitation> { | ||||
|     public async findAllInvitationsForClass(clazz: Class): Promise<TeacherInvitation[]> { | ||||
|  | @ -11,7 +12,7 @@ export class TeacherInvitationRepository extends DwengoEntityRepository<TeacherI | |||
|         return this.findAll({ where: { sender: sender } }); | ||||
|     } | ||||
|     public async findAllInvitationsFor(receiver: Teacher): Promise<TeacherInvitation[]> { | ||||
|         return this.findAll({ where: { receiver: receiver } }); | ||||
|         return this.findAll({ where: { receiver: receiver, status: ClassStatus.Open } }); | ||||
|     } | ||||
|     public async deleteBy(clazz: Class, sender: Teacher, receiver: Teacher): Promise<void> { | ||||
|         return this.deleteWhere({ | ||||
|  | @ -20,4 +21,11 @@ export class TeacherInvitationRepository extends DwengoEntityRepository<TeacherI | |||
|             class: clazz, | ||||
|         }); | ||||
|     } | ||||
|     public async findBy(clazz: Class, sender: Teacher, receiver: Teacher): Promise<TeacherInvitation | null> { | ||||
|         return this.findOne({ | ||||
|             sender: sender, | ||||
|             receiver: receiver, | ||||
|             class: clazz, | ||||
|         }); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -5,15 +5,16 @@ 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 { Group } from '../../entities/assignments/group.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(), | ||||
|         }); | ||||
|  | @ -21,6 +22,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); | ||||
|     } | ||||
|  | @ -60,7 +62,9 @@ export class QuestionRepository extends DwengoEntityRepository<Question> { | |||
| 
 | ||||
|     public async findAllByAssignment(assignment: Assignment): Promise<Question[]> { | ||||
|         return this.find({ | ||||
|             author: assignment.groups.toArray<Group>().flatMap((group) => group.members), | ||||
|             inGroup: { | ||||
|                 $contained: assignment.groups, | ||||
|             }, | ||||
|             learningObjectHruid: assignment.learningPathHruid, | ||||
|             learningObjectLanguage: assignment.learningPathLanguage, | ||||
|         }); | ||||
|  | @ -73,6 +77,38 @@ export class QuestionRepository extends DwengoEntityRepository<Question> { | |||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 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, | ||||
|             }, | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     public async findByLearningObjectAndSequenceNumber(loId: LearningObjectIdentifier, sequenceNumber: number): Promise<Loaded<Question> | null> { | ||||
|         return this.findOne({ | ||||
|             learningObjectHruid: loId.hruid, | ||||
|  |  | |||
|  | @ -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,7 +2,7 @@ import { Entity, Enum, ManyToOne } from '@mikro-orm/core'; | |||
| import { Student } from '../users/student.entity.js'; | ||||
| import { Class } from './class.entity.js'; | ||||
| import { ClassJoinRequestRepository } from '../../data/classes/class-join-request-repository.js'; | ||||
| import { ClassJoinRequestStatus } from '@dwengo-1/common/util/class-join-request'; | ||||
| import { ClassStatus } from '@dwengo-1/common/util/class-join-request'; | ||||
| 
 | ||||
| @Entity({ | ||||
|     repository: () => ClassJoinRequestRepository, | ||||
|  | @ -20,6 +20,6 @@ export class ClassJoinRequest { | |||
|     }) | ||||
|     class!: Class; | ||||
| 
 | ||||
|     @Enum(() => ClassJoinRequestStatus) | ||||
|     status!: ClassJoinRequestStatus; | ||||
|     @Enum(() => ClassStatus) | ||||
|     status!: ClassStatus; | ||||
| } | ||||
|  |  | |||
|  | @ -1,7 +1,8 @@ | |||
| import { Entity, ManyToOne } from '@mikro-orm/core'; | ||||
| import { Entity, Enum, ManyToOne } from '@mikro-orm/core'; | ||||
| import { Teacher } from '../users/teacher.entity.js'; | ||||
| import { Class } from './class.entity.js'; | ||||
| import { TeacherInvitationRepository } from '../../data/classes/teacher-invitation-repository.js'; | ||||
| import { ClassStatus } from '@dwengo-1/common/util/class-join-request'; | ||||
| 
 | ||||
| /** | ||||
|  * Invitation of a teacher into a class (in order to teach it). | ||||
|  | @ -25,4 +26,7 @@ export class TeacherInvitation { | |||
|         primary: true, | ||||
|     }) | ||||
|     class!: Class; | ||||
| 
 | ||||
|     @Enum(() => ClassStatus) | ||||
|     status!: ClassStatus; | ||||
| } | ||||
|  |  | |||
|  | @ -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.js'; | ||||
| 
 | ||||
| @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,17 +1,31 @@ | |||
| import { Group } from '../entities/assignments/group.entity.js'; | ||||
| import { Class } from '../entities/classes/class.entity.js'; | ||||
| import { mapToAssignment } from './assignment.js'; | ||||
| import { mapToStudent } from './student.js'; | ||||
| import { mapToAssignmentDTO } from './assignment.js'; | ||||
| import { mapToStudentDTO } from './student.js'; | ||||
| import { GroupDTO, GroupDTOId } from '@dwengo-1/common/interfaces/group'; | ||||
| import { getGroupRepository } from '../data/repositories.js'; | ||||
| import { AssignmentDTO } from '@dwengo-1/common/interfaces/assignment'; | ||||
| import { Class } from '../entities/classes/class.entity.js'; | ||||
| import { StudentDTO } from '@dwengo-1/common/interfaces/student'; | ||||
| import { mapToClassDTO } from './class.js'; | ||||
| 
 | ||||
| export function mapToGroupDTO(group: Group, cls: Class, options?: { expandStudents: boolean }): GroupDTO { | ||||
| 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, cls: Class): GroupDTO { | ||||
|     return { | ||||
|         class: cls.classId!, | ||||
|         assignment: group.assignment.id!, | ||||
|         groupNumber: group.groupNumber!, | ||||
|         members:  | ||||
|             options?.expandStudents  | ||||
|             ? group.members.map(mapToStudentDTO) | ||||
|             : group.members.map((student) => student.username) | ||||
|         members: group.members.map(mapToStudentDTO) | ||||
| 
 | ||||
|     }; | ||||
| } | ||||
|  | @ -23,3 +37,15 @@ export function mapToGroupDTOId(group: Group, cls: Class): GroupDTOId { | |||
|         groupNumber: group.groupNumber!, | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * Map to group DTO where other objects are only referenced by their id. | ||||
|  */ | ||||
| export function mapToShallowGroupDTO(group: Group): GroupDTO { | ||||
|     return { | ||||
|         class: group.assignment.within.classId!, | ||||
|         assignment: group.assignment.id!, | ||||
|         groupNumber: group.groupNumber!, | ||||
|         members: group.members.map((member) => member.username), | ||||
|     }; | ||||
| } | ||||
|  |  | |||
|  | @ -3,6 +3,7 @@ import { mapToStudentDTO } from './student.js'; | |||
| import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | ||||
| import { LearningObjectIdentifierDTO } from '@dwengo-1/common/interfaces/learning-content'; | ||||
| import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; | ||||
| import { mapToGroupDTOId } from './group.js'; | ||||
| 
 | ||||
| function getLearningObjectIdentifier(question: Question): LearningObjectIdentifierDTO { | ||||
|     return { | ||||
|  | @ -30,6 +31,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, | ||||
|     }; | ||||
|  |  | |||
|  | @ -4,7 +4,7 @@ import { getClassJoinRequestRepository } from '../data/repositories.js'; | |||
| import { Student } from '../entities/users/student.entity.js'; | ||||
| import { Class } from '../entities/classes/class.entity.js'; | ||||
| import { ClassJoinRequestDTO } from '@dwengo-1/common/interfaces/class-join-request'; | ||||
| import { ClassJoinRequestStatus } from '@dwengo-1/common/util/class-join-request'; | ||||
| import { ClassStatus } from '@dwengo-1/common/util/class-join-request'; | ||||
| 
 | ||||
| export function mapToStudentRequestDTO(request: ClassJoinRequest): ClassJoinRequestDTO { | ||||
|     return { | ||||
|  | @ -18,6 +18,6 @@ export function mapToStudentRequest(student: Student, cls: Class): ClassJoinRequ | |||
|     return getClassJoinRequestRepository().create({ | ||||
|         requester: student, | ||||
|         class: cls, | ||||
|         status: ClassJoinRequestStatus.Open, | ||||
|         status: ClassStatus.Open, | ||||
|     }); | ||||
| } | ||||
|  |  | |||
|  | @ -1,10 +1,10 @@ | |||
| import { getSubmissionRepository } from '../data/repositories.js'; | ||||
| import { Group } from '../entities/assignments/group.entity.js'; | ||||
| import { Submission } from '../entities/assignments/submission.entity.js'; | ||||
| import { Student } from '../entities/users/student.entity.js'; | ||||
| import { mapToGroupDTO } from './group.js'; | ||||
| import { mapToStudentDTO } from './student.js'; | ||||
| import { SubmissionDTO, SubmissionDTOId } from '@dwengo-1/common/interfaces/submission'; | ||||
| import { getSubmissionRepository } from '../data/repositories.js'; | ||||
| import { Student } from '../entities/users/student.entity.js'; | ||||
| import { Group } from '../entities/assignments/group.entity.js'; | ||||
| 
 | ||||
| export function mapToSubmissionDTO(submission: Submission): SubmissionDTO { | ||||
|     return { | ||||
|  | @ -32,7 +32,7 @@ export function mapToSubmissionDTOId(submission: Submission): SubmissionDTOId { | |||
|     }; | ||||
| } | ||||
| 
 | ||||
| export function mapToSubmission(submissionDTO: SubmissionDTO, submitter: Student, onBehalfOf: Group | undefined): Submission { | ||||
| export function mapToSubmission(submissionDTO: SubmissionDTO, submitter: Student, onBehalfOf: Group): Submission { | ||||
|     return getSubmissionRepository().create({ | ||||
|         learningObjectHruid: submissionDTO.learningObjectIdentifier.hruid, | ||||
|         learningObjectLanguage: submissionDTO.learningObjectIdentifier.language, | ||||
|  |  | |||
|  | @ -1,13 +1,17 @@ | |||
| import { TeacherInvitation } from '../entities/classes/teacher-invitation.entity.js'; | ||||
| import { mapToClassDTO } from './class.js'; | ||||
| import { mapToUserDTO } from './user.js'; | ||||
| import { TeacherInvitationDTO } from '@dwengo-1/common/interfaces/teacher-invitation'; | ||||
| import { getTeacherInvitationRepository } from '../data/repositories.js'; | ||||
| import { Teacher } from '../entities/users/teacher.entity.js'; | ||||
| import { Class } from '../entities/classes/class.entity.js'; | ||||
| import { ClassStatus } from '@dwengo-1/common/util/class-join-request'; | ||||
| 
 | ||||
| export function mapToTeacherInvitationDTO(invitation: TeacherInvitation): TeacherInvitationDTO { | ||||
|     return { | ||||
|         sender: mapToUserDTO(invitation.sender), | ||||
|         receiver: mapToUserDTO(invitation.receiver), | ||||
|         class: mapToClassDTO(invitation.class), | ||||
|         classId: invitation.class.classId!, | ||||
|         status: invitation.status, | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
|  | @ -15,6 +19,16 @@ export function mapToTeacherInvitationDTOIds(invitation: TeacherInvitation): Tea | |||
|     return { | ||||
|         sender: invitation.sender.username, | ||||
|         receiver: invitation.receiver.username, | ||||
|         class: invitation.class.classId!, | ||||
|         classId: invitation.class.classId!, | ||||
|         status: invitation.status, | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| export function mapToInvitation(sender: Teacher, receiver: Teacher, cls: Class): TeacherInvitation { | ||||
|     return getTeacherInvitationRepository().create({ | ||||
|         sender, | ||||
|         receiver, | ||||
|         class: cls, | ||||
|         status: ClassStatus.Open, | ||||
|     }); | ||||
| } | ||||
|  |  | |||
|  | @ -1,9 +1,9 @@ | |||
| import express from 'express'; | ||||
| import { createSubmissionHandler, deleteSubmissionHandler, getAllSubmissionsHandler, 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('/', getAllSubmissionsHandler); | ||||
| router.get('/', getSubmissionsHandler); | ||||
| 
 | ||||
| router.post('/:id', createSubmissionHandler); | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										22
									
								
								backend/src/routes/teacher-invitations.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								backend/src/routes/teacher-invitations.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,22 @@ | |||
| import express from 'express'; | ||||
| import { | ||||
|     createInvitationHandler, | ||||
|     deleteInvitationHandler, | ||||
|     getAllInvitationsHandler, | ||||
|     getInvitationHandler, | ||||
|     updateInvitationHandler, | ||||
| } from '../controllers/teacher-invitations.js'; | ||||
| 
 | ||||
| const router = express.Router({ mergeParams: true }); | ||||
| 
 | ||||
| router.get('/:username', getAllInvitationsHandler); | ||||
| 
 | ||||
| router.get('/:sender/:receiver/:classId', getInvitationHandler); | ||||
| 
 | ||||
| router.post('/', createInvitationHandler); | ||||
| 
 | ||||
| router.put('/', updateInvitationHandler); | ||||
| 
 | ||||
| router.delete('/:sender/:receiver/:classId', deleteInvitationHandler); | ||||
| 
 | ||||
| export default router; | ||||
|  | @ -10,6 +10,8 @@ import { | |||
|     getTeacherStudentHandler, | ||||
|     updateStudentJoinRequestHandler, | ||||
| } from '../controllers/teachers.js'; | ||||
| import invitationRouter from './teacher-invitations.js'; | ||||
| 
 | ||||
| const router = express.Router(); | ||||
| 
 | ||||
| // Root endpoint used to search objects
 | ||||
|  | @ -32,10 +34,6 @@ router.get('/:username/joinRequests/:classId', getStudentJoinRequestHandler); | |||
| router.put('/:username/joinRequests/:classId/:studentUsername', updateStudentJoinRequestHandler); | ||||
| 
 | ||||
| // Invitations to other classes a teacher received
 | ||||
| router.get('/:id/invitations', (_req, res) => { | ||||
|     res.json({ | ||||
|         invitations: ['0'], | ||||
|     }); | ||||
| }); | ||||
| router.get('/invitations', invitationRouter); | ||||
| 
 | ||||
| export default router; | ||||
|  |  | |||
|  | @ -1,7 +1,7 @@ | |||
| import { EntityDTO } from '@mikro-orm/core'; | ||||
| import { getGroupRepository, getSubmissionRepository } from '../data/repositories.js'; | ||||
| import { Group } from '../entities/assignments/group.entity.js'; | ||||
| import { mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js'; | ||||
| import { mapToGroupDTO, mapToGroupDTOId, mapToShallowGroupDTO } from '../interfaces/group.js'; | ||||
| import { mapToSubmissionDTO, mapToSubmissionDTOId } from '../interfaces/submission.js'; | ||||
| import { GroupDTO, GroupDTOId } from '@dwengo-1/common/interfaces/group'; | ||||
| import { SubmissionDTO, SubmissionDTOId } from '@dwengo-1/common/interfaces/submission'; | ||||
|  |  | |||
|  | @ -1,12 +1,34 @@ | |||
| import { getQuestionRepository } from '../data/repositories.js'; | ||||
| import { getAnswerRepository, getAssignmentRepository, getClassRepository, getGroupRepository, getQuestionRepository } from '../data/repositories.js'; | ||||
| import { mapToLearningObjectID, mapToQuestionDTO, mapToQuestionDTOId } from '../interfaces/question.js'; | ||||
| import { Question } from '../entities/questions/question.entity.js'; | ||||
| import { Answer } from '../entities/questions/answer.entity.js'; | ||||
| import { mapToAnswerDTO, mapToAnswerDTOId } from '../interfaces/answer.js'; | ||||
| import { QuestionRepository } from '../data/questions/question-repository.js'; | ||||
| import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; | ||||
| import { QuestionData, QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | ||||
| import { AnswerDTO, AnswerId } from '@dwengo-1/common/interfaces/answer'; | ||||
| import { mapToAssignment } from '../interfaces/assignment.js'; | ||||
| import { AssignmentDTO } from '@dwengo-1/common/interfaces/assignment'; | ||||
| import { fetchStudent } from './students.js'; | ||||
| import { NotFoundException } from '../exceptions/not-found-exception.js'; | ||||
| import { FALLBACK_VERSION_NUM } from '../config.js'; | ||||
| import { fetchStudent } from './students.js'; | ||||
| 
 | ||||
| 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(); | ||||
|  | @ -38,14 +60,40 @@ export async function getQuestion(questionId: QuestionId): Promise<QuestionDTO> | |||
|     return mapToQuestionDTO(question); | ||||
| } | ||||
| 
 | ||||
| export async function getAnswersByQuestion(questionId: QuestionId, full: boolean): Promise<AnswerDTO[] | AnswerId[]> { | ||||
|     const answerRepository = getAnswerRepository(); | ||||
|     const question = await fetchQuestion(questionId); | ||||
| 
 | ||||
|     if (!question) { | ||||
|         return []; | ||||
|     } | ||||
| 
 | ||||
|     const answers: Answer[] = await answerRepository.findAllAnswersToQuestion(question); | ||||
| 
 | ||||
|     if (!answers) { | ||||
|         return []; | ||||
|     } | ||||
| 
 | ||||
|     if (full) { | ||||
|         return answers.map(mapToAnswerDTO); | ||||
|     } | ||||
| 
 | ||||
|     return answers.map(mapToAnswerDTOId); | ||||
| } | ||||
| 
 | ||||
| export async function createQuestion(loId: LearningObjectIdentifier, questionData: QuestionData): Promise<QuestionDTO> { | ||||
|     const questionRepository = getQuestionRepository(); | ||||
|     const author = await fetchStudent(questionData.author!); | ||||
|     const content = questionData.content; | ||||
| 
 | ||||
|     const clazz = await getClassRepository().findById((questionData.inGroup.assignment as AssignmentDTO).within); | ||||
|     const assignment = mapToAssignment(questionData.inGroup.assignment as AssignmentDTO, clazz!); | ||||
|     const inGroup = await getGroupRepository().findByAssignmentAndGroupNumber(assignment, questionData.inGroup.groupNumber); | ||||
| 
 | ||||
|     const question = await questionRepository.createQuestion({ | ||||
|         loId, | ||||
|         author, | ||||
|         inGroup: inGroup!, | ||||
|         content, | ||||
|     }); | ||||
| 
 | ||||
|  |  | |||
|  | @ -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, mapToGroupDTOId, mapToShallowGroupDTO } from '../interfaces/group.js'; | ||||
| import { mapToStudent, mapToStudentDTO } from '../interfaces/student.js'; | ||||
| import { mapToSubmissionDTO, mapToSubmissionDTOId } from '../interfaces/submission.js'; | ||||
| import { getAllAssignments } from './assignments.js'; | ||||
|  | @ -24,6 +24,7 @@ import { SubmissionDTO, SubmissionDTOId } from '@dwengo-1/common/interfaces/subm | |||
| import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | ||||
| import { ClassJoinRequestDTO } from '@dwengo-1/common/interfaces/class-join-request'; | ||||
| import { ConflictException } from '../exceptions/conflict-exception.js'; | ||||
| import { Submission } from '../entities/assignments/submission.entity'; | ||||
| 
 | ||||
| export async function getAllStudents(full: boolean): Promise<StudentDTO[] | string[]> { | ||||
|     const studentRepository = getStudentRepository(); | ||||
|  | @ -113,7 +114,8 @@ export async function getStudentSubmissions(username: string, full: boolean): Pr | |||
|     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 { NotFoundException } from '../exceptions/not-found-exception.js'; | ||||
| import { mapToSubmission, mapToSubmissionDTO } from '../interfaces/submission.js'; | ||||
|  | @ -6,6 +6,7 @@ import { SubmissionDTO } from '@dwengo-1/common/interfaces/submission'; | |||
| import { fetchStudent } from './students.js'; | ||||
| import { getExistingGroupFromGroupDTO } from './groups.js'; | ||||
| import { Submission } from '../entities/assignments/submission.entity.js'; | ||||
| import { Language } from '@dwengo-1/common/util/language'; | ||||
| 
 | ||||
| export async function fetchSubmission(loId: LearningObjectIdentifier, submissionNumber: number): Promise<Submission> { | ||||
|     const submissionRepository = getSubmissionRepository(); | ||||
|  | @ -32,9 +33,7 @@ export async function getAllSubmissions(loId: LearningObjectIdentifier): Promise | |||
| 
 | ||||
| export async function createSubmission(submissionDTO: SubmissionDTO): Promise<SubmissionDTO> { | ||||
|     const submitter = await fetchStudent(submissionDTO.submitter.username); | ||||
|     // TODO: fix
 | ||||
|     // const group = submissionDTO.group ? await getExistingGroupFromGroupDTO(submissionDTO.group) : undefined;
 | ||||
|     const group = undefined; | ||||
|     const group = await getExistingGroupFromGroupDTO(submissionDTO.group!); | ||||
| 
 | ||||
|     const submissionRepository = getSubmissionRepository(); | ||||
|     const submission = mapToSubmission(submissionDTO, submitter, group); | ||||
|  | @ -51,3 +50,22 @@ export async function deleteSubmission(loId: LearningObjectIdentifier, submissio | |||
| 
 | ||||
|     return mapToSubmissionDTO(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)); | ||||
| } | ||||
|  |  | |||
							
								
								
									
										87
									
								
								backend/src/services/teacher-invitations.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								backend/src/services/teacher-invitations.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,87 @@ | |||
| import { fetchTeacher } from './teachers.js'; | ||||
| import { getTeacherInvitationRepository } from '../data/repositories.js'; | ||||
| import { mapToInvitation, mapToTeacherInvitationDTO } from '../interfaces/teacher-invitation.js'; | ||||
| import { addClassTeacher, fetchClass } from './classes.js'; | ||||
| import { TeacherInvitationData, TeacherInvitationDTO } from '@dwengo-1/common/interfaces/teacher-invitation'; | ||||
| import { ConflictException } from '../exceptions/conflict-exception.js'; | ||||
| import { NotFoundException } from '../exceptions/not-found-exception.js'; | ||||
| import { TeacherInvitation } from '../entities/classes/teacher-invitation.entity.js'; | ||||
| import { ClassStatus } from '@dwengo-1/common/util/class-join-request'; | ||||
| 
 | ||||
| export async function getAllInvitations(username: string, sent: boolean): Promise<TeacherInvitationDTO[]> { | ||||
|     const teacher = await fetchTeacher(username); | ||||
|     const teacherInvitationRepository = getTeacherInvitationRepository(); | ||||
| 
 | ||||
|     let invitations; | ||||
|     if (sent) { | ||||
|         invitations = await teacherInvitationRepository.findAllInvitationsBy(teacher); | ||||
|     } else { | ||||
|         invitations = await teacherInvitationRepository.findAllInvitationsFor(teacher); | ||||
|     } | ||||
|     return invitations.map(mapToTeacherInvitationDTO); | ||||
| } | ||||
| 
 | ||||
| export async function createInvitation(data: TeacherInvitationData): Promise<TeacherInvitationDTO> { | ||||
|     const teacherInvitationRepository = getTeacherInvitationRepository(); | ||||
|     const sender = await fetchTeacher(data.sender); | ||||
|     const receiver = await fetchTeacher(data.receiver); | ||||
| 
 | ||||
|     const cls = await fetchClass(data.class); | ||||
| 
 | ||||
|     if (!cls.teachers.contains(sender)) { | ||||
|         throw new ConflictException('The teacher sending the invite is not part of the class'); | ||||
|     } | ||||
| 
 | ||||
|     const newInvitation = mapToInvitation(sender, receiver, cls); | ||||
|     await teacherInvitationRepository.save(newInvitation, { preventOverwrite: true }); | ||||
| 
 | ||||
|     return mapToTeacherInvitationDTO(newInvitation); | ||||
| } | ||||
| 
 | ||||
| async function fetchInvitation(usernameSender: string, usernameReceiver: string, classId: string): Promise<TeacherInvitation> { | ||||
|     const sender = await fetchTeacher(usernameSender); | ||||
|     const receiver = await fetchTeacher(usernameReceiver); | ||||
|     const cls = await fetchClass(classId); | ||||
| 
 | ||||
|     const teacherInvitationRepository = getTeacherInvitationRepository(); | ||||
|     const invite = await teacherInvitationRepository.findBy(cls, sender, receiver); | ||||
| 
 | ||||
|     if (!invite) { | ||||
|         throw new NotFoundException('Teacher invite not found'); | ||||
|     } | ||||
| 
 | ||||
|     return invite; | ||||
| } | ||||
| 
 | ||||
| export async function getInvitation(sender: string, receiver: string, classId: string): Promise<TeacherInvitationDTO> { | ||||
|     const invitation = await fetchInvitation(sender, receiver, classId); | ||||
|     return mapToTeacherInvitationDTO(invitation); | ||||
| } | ||||
| 
 | ||||
| export async function updateInvitation(data: TeacherInvitationData): Promise<TeacherInvitationDTO> { | ||||
|     const invitation = await fetchInvitation(data.sender, data.receiver, data.class); | ||||
|     invitation.status = ClassStatus.Declined; | ||||
| 
 | ||||
|     if (data.accepted) { | ||||
|         invitation.status = ClassStatus.Accepted; | ||||
|         await addClassTeacher(data.class, data.receiver); | ||||
|     } | ||||
| 
 | ||||
|     const teacherInvitationRepository = getTeacherInvitationRepository(); | ||||
|     await teacherInvitationRepository.save(invitation); | ||||
| 
 | ||||
|     return mapToTeacherInvitationDTO(invitation); | ||||
| } | ||||
| 
 | ||||
| export async function deleteInvitation(data: TeacherInvitationData): Promise<TeacherInvitationDTO> { | ||||
|     const invitation = await fetchInvitation(data.sender, data.receiver, data.class); | ||||
| 
 | ||||
|     const sender = await fetchTeacher(data.sender); | ||||
|     const receiver = await fetchTeacher(data.receiver); | ||||
|     const cls = await fetchClass(data.class); | ||||
| 
 | ||||
|     const teacherInvitationRepository = getTeacherInvitationRepository(); | ||||
|     await teacherInvitationRepository.deleteBy(cls, sender, receiver); | ||||
| 
 | ||||
|     return mapToTeacherInvitationDTO(invitation); | ||||
| } | ||||
|  | @ -28,7 +28,7 @@ import { ClassDTO } from '@dwengo-1/common/interfaces/class'; | |||
| import { StudentDTO } from '@dwengo-1/common/interfaces/student'; | ||||
| import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | ||||
| import { ClassJoinRequestDTO } from '@dwengo-1/common/interfaces/class-join-request'; | ||||
| import { ClassJoinRequestStatus } from '@dwengo-1/common/util/class-join-request'; | ||||
| import { ClassStatus } from '@dwengo-1/common/util/class-join-request'; | ||||
| import { ConflictException } from '../exceptions/conflict-exception.js'; | ||||
| 
 | ||||
| export async function getAllTeachers(full: boolean): Promise<TeacherDTO[] | string[]> { | ||||
|  | @ -160,10 +160,10 @@ export async function updateClassJoinRequestStatus(studentUsername: string, clas | |||
|         throw new NotFoundException('Join request not found'); | ||||
|     } | ||||
| 
 | ||||
|     request.status = ClassJoinRequestStatus.Declined; | ||||
|     request.status = ClassStatus.Declined; | ||||
| 
 | ||||
|     if (accepted) { | ||||
|         request.status = ClassJoinRequestStatus.Accepted; | ||||
|         request.status = ClassStatus.Accepted; | ||||
|         await addClassStudent(classId, studentUsername); | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										123
									
								
								backend/tests/controllers/teacher-invitations.test.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										123
									
								
								backend/tests/controllers/teacher-invitations.test.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,123 @@ | |||
| import { beforeAll, beforeEach, describe, expect, it, Mock, vi } from 'vitest'; | ||||
| import { Request, Response } from 'express'; | ||||
| import { setupTestApp } from '../setup-tests.js'; | ||||
| import { | ||||
|     createInvitationHandler, | ||||
|     deleteInvitationHandler, | ||||
|     getAllInvitationsHandler, | ||||
|     getInvitationHandler, | ||||
|     updateInvitationHandler, | ||||
| } from '../../src/controllers/teacher-invitations'; | ||||
| import { TeacherInvitationData } from '@dwengo-1/common/interfaces/teacher-invitation'; | ||||
| import { getClassHandler } from '../../src/controllers/classes'; | ||||
| import { BadRequestException } from '../../src/exceptions/bad-request-exception'; | ||||
| import { ClassStatus } from '@dwengo-1/common/util/class-join-request'; | ||||
| 
 | ||||
| describe('Teacher controllers', () => { | ||||
|     let req: Partial<Request>; | ||||
|     let res: Partial<Response>; | ||||
| 
 | ||||
|     let jsonMock: Mock; | ||||
| 
 | ||||
|     beforeAll(async () => { | ||||
|         await setupTestApp(); | ||||
|     }); | ||||
| 
 | ||||
|     beforeEach(() => { | ||||
|         jsonMock = vi.fn(); | ||||
|         res = { | ||||
|             json: jsonMock, | ||||
|         }; | ||||
|     }); | ||||
| 
 | ||||
|     it('Get teacher invitations by', async () => { | ||||
|         req = { params: { username: 'LimpBizkit' }, query: { sent: 'true' } }; | ||||
| 
 | ||||
|         await getAllInvitationsHandler(req as Request, res as Response); | ||||
| 
 | ||||
|         expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ invitations: expect.anything() })); | ||||
| 
 | ||||
|         const result = jsonMock.mock.lastCall?.[0]; | ||||
|         // Console.log(result.invitations);
 | ||||
|         expect(result.invitations).to.have.length.greaterThan(0); | ||||
|     }); | ||||
| 
 | ||||
|     it('Get teacher invitations for', async () => { | ||||
|         req = { params: { username: 'FooFighters' }, query: { by: 'false' } }; | ||||
| 
 | ||||
|         await getAllInvitationsHandler(req as Request, res as Response); | ||||
| 
 | ||||
|         expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ invitations: expect.anything() })); | ||||
| 
 | ||||
|         const result = jsonMock.mock.lastCall?.[0]; | ||||
|         expect(result.invitations).to.have.length.greaterThan(0); | ||||
|     }); | ||||
| 
 | ||||
|     it('Create and delete invitation', async () => { | ||||
|         const body = { | ||||
|             sender: 'LimpBizkit', | ||||
|             receiver: 'testleerkracht1', | ||||
|             class: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89', | ||||
|         } as TeacherInvitationData; | ||||
|         req = { body }; | ||||
| 
 | ||||
|         await createInvitationHandler(req as Request, res as Response); | ||||
| 
 | ||||
|         req = { | ||||
|             params: { | ||||
|                 sender: 'LimpBizkit', | ||||
|                 receiver: 'testleerkracht1', | ||||
|                 classId: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89', | ||||
|             }, | ||||
|             body: { accepted: 'false' }, | ||||
|         }; | ||||
| 
 | ||||
|         await deleteInvitationHandler(req as Request, res as Response); | ||||
|     }); | ||||
| 
 | ||||
|     it('Get invitation', async () => { | ||||
|         req = { | ||||
|             params: { | ||||
|                 sender: 'LimpBizkit', | ||||
|                 receiver: 'FooFighters', | ||||
|                 classId: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89', | ||||
|             }, | ||||
|         }; | ||||
|         await getInvitationHandler(req as Request, res as Response); | ||||
| 
 | ||||
|         expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ invitation: expect.anything() })); | ||||
|     }); | ||||
| 
 | ||||
|     it('Get invitation error', async () => { | ||||
|         req = { | ||||
|             params: { no: 'no params' }, | ||||
|         }; | ||||
| 
 | ||||
|         await expect(async () => getInvitationHandler(req as Request, res as Response)).rejects.toThrowError(BadRequestException); | ||||
|     }); | ||||
| 
 | ||||
|     it('Accept invitation', async () => { | ||||
|         const body = { | ||||
|             sender: 'LimpBizkit', | ||||
|             receiver: 'FooFighters', | ||||
|             class: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89', | ||||
|         } as TeacherInvitationData; | ||||
|         req = { body }; | ||||
| 
 | ||||
|         await updateInvitationHandler(req as Request, res as Response); | ||||
| 
 | ||||
|         const result1 = jsonMock.mock.lastCall?.[0]; | ||||
|         expect(result1.invitation.status).toEqual(ClassStatus.Accepted); | ||||
| 
 | ||||
|         req = { | ||||
|             params: { | ||||
|                 id: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89', | ||||
|             }, | ||||
|         }; | ||||
| 
 | ||||
|         await getClassHandler(req as Request, res as Response); | ||||
| 
 | ||||
|         const result = jsonMock.mock.lastCall?.[0]; | ||||
|         expect(result.class.teachers).toContain('FooFighters'); | ||||
|     }); | ||||
| }); | ||||
|  | @ -31,6 +31,13 @@ describe('AssignmentRepository', () => { | |||
|         expect(assignments[0].title).toBe('tool'); | ||||
|     }); | ||||
| 
 | ||||
|     it('should find all by username of the responsible teacher', async () => { | ||||
|         const result = await assignmentRepository.findAllByResponsibleTeacher('testleerkracht1'); | ||||
|         const resultIds = result.map((it) => it.id).sort((a, b) => (a ?? 0) - (b ?? 0)); | ||||
| 
 | ||||
|         expect(resultIds).toEqual([1, 3, 4]); | ||||
|     }); | ||||
| 
 | ||||
|     it('should not find removed assignment', async () => { | ||||
|         const class_ = await classRepository.findById('id01'); | ||||
|         await assignmentRepository.deleteByClassAndId(class_!, 3); | ||||
|  |  | |||
|  | @ -14,6 +14,9 @@ import { StudentRepository } from '../../../src/data/users/student-repository'; | |||
| import { GroupRepository } from '../../../src/data/assignments/group-repository'; | ||||
| import { AssignmentRepository } from '../../../src/data/assignments/assignment-repository'; | ||||
| import { ClassRepository } from '../../../src/data/classes/class-repository'; | ||||
| import { Submission } from '../../../src/entities/assignments/submission.entity'; | ||||
| import { Class } from '../../../src/entities/classes/class.entity'; | ||||
| import { Assignment } from '../../../src/entities/assignments/assignment.entity'; | ||||
| 
 | ||||
| describe('SubmissionRepository', () => { | ||||
|     let submissionRepository: SubmissionRepository; | ||||
|  | @ -59,6 +62,49 @@ describe('SubmissionRepository', () => { | |||
|         expect(submission?.submissionTime.getDate()).toBe(25); | ||||
|     }); | ||||
| 
 | ||||
|     let clazz: Class | null; | ||||
|     let assignment: Assignment | null; | ||||
|     let loId: LearningObjectIdentifier; | ||||
|     it('should find all submissions for a certain learning object and assignment', async () => { | ||||
|         clazz = await classRepository.findById('8764b861-90a6-42e5-9732-c0d9eb2f55f9'); | ||||
|         assignment = await assignmentRepository.findByClassAndId(clazz!, 1); | ||||
|         loId = { | ||||
|             hruid: 'id02', | ||||
|             language: Language.English, | ||||
|             version: 1, | ||||
|         }; | ||||
|         const result = await submissionRepository.findAllSubmissionsForLearningObjectAndAssignment(loId, assignment!); | ||||
|         sortSubmissions(result); | ||||
| 
 | ||||
|         expect(result).toHaveLength(3); | ||||
| 
 | ||||
|         // Submission3 should be found (for learning object 'id02' by group #1 for Assignment #1 in class 'id01')
 | ||||
|         expect(result[0].learningObjectHruid).toBe(loId.hruid); | ||||
|         expect(result[0].submissionNumber).toBe(1); | ||||
| 
 | ||||
|         // Submission4 should be found (for learning object 'id02' by group #1 for Assignment #1 in class 'id01')
 | ||||
|         expect(result[1].learningObjectHruid).toBe(loId.hruid); | ||||
|         expect(result[1].submissionNumber).toBe(2); | ||||
| 
 | ||||
|         // Submission8 should be found (for learning object 'id02' by group #2 for Assignment #1 in class 'id01')
 | ||||
|         expect(result[2].learningObjectHruid).toBe(loId.hruid); | ||||
|         expect(result[2].submissionNumber).toBe(3); | ||||
|     }); | ||||
| 
 | ||||
|     it("should find only the submissions for a certain learning object and assignment made for the user's group", async () => { | ||||
|         const result = await submissionRepository.findAllSubmissionsForLearningObjectAndAssignment(loId, assignment!, 'Tool'); | ||||
|         // (student Tool is in group #2)
 | ||||
| 
 | ||||
|         expect(result).toHaveLength(1); | ||||
| 
 | ||||
|         // Submission8 should be found (for learning object 'id02' by group #2 for Assignment #1 in class 'id01')
 | ||||
|         expect(result[0].learningObjectHruid).toBe(loId.hruid); | ||||
|         expect(result[0].submissionNumber).toBe(3); | ||||
| 
 | ||||
|         // The other submissions found in the previous test case should not be found anymore as they were made on
 | ||||
|         // Behalf of group #1 which Tool is no member of.
 | ||||
|     }); | ||||
| 
 | ||||
|     it('should not find a deleted submission', async () => { | ||||
|         const id = new LearningObjectIdentifier('id01', Language.English, 1); | ||||
|         await submissionRepository.deleteSubmissionByLearningObjectAndSubmissionNumber(id, 1); | ||||
|  | @ -68,3 +114,15 @@ describe('SubmissionRepository', () => { | |||
|         expect(submission).toBeNull(); | ||||
|     }); | ||||
| }); | ||||
| 
 | ||||
| function sortSubmissions(submissions: Submission[]): void { | ||||
|     submissions.sort((a, b) => { | ||||
|         if (a.learningObjectHruid < b.learningObjectHruid) { | ||||
|             return -1; | ||||
|         } | ||||
|         if (a.learningObjectHruid > b.learningObjectHruid) { | ||||
|             return 1; | ||||
|         } | ||||
|         return a.submissionNumber! - b.submissionNumber!; | ||||
|     }); | ||||
| } | ||||
|  |  | |||
|  | @ -1,10 +1,19 @@ | |||
| import { beforeAll, describe, expect, it } from 'vitest'; | ||||
| import { setupTestApp } from '../../setup-tests'; | ||||
| import { QuestionRepository } from '../../../src/data/questions/question-repository'; | ||||
| import { getQuestionRepository, getStudentRepository } from '../../../src/data/repositories'; | ||||
| import { | ||||
|     getAssignmentRepository, | ||||
|     getClassRepository, | ||||
|     getGroupRepository, | ||||
|     getQuestionRepository, | ||||
|     getStudentRepository, | ||||
| } from '../../../src/data/repositories'; | ||||
| import { StudentRepository } from '../../../src/data/users/student-repository'; | ||||
| import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier'; | ||||
| import { Language } from '@dwengo-1/common/util/language'; | ||||
| import { Question } from '../../../src/entities/questions/question.entity'; | ||||
| import { Class } from '../../../src/entities/classes/class.entity'; | ||||
| import { Assignment } from '../../../src/entities/assignments/assignment.entity'; | ||||
| 
 | ||||
| describe('QuestionRepository', () => { | ||||
|     let questionRepository: QuestionRepository; | ||||
|  | @ -21,14 +30,19 @@ describe('QuestionRepository', () => { | |||
|         const questions = await questionRepository.findAllQuestionsAboutLearningObject(id); | ||||
| 
 | ||||
|         expect(questions).toBeTruthy(); | ||||
|         expect(questions).toHaveLength(2); | ||||
|         expect(questions).toHaveLength(4); | ||||
|     }); | ||||
| 
 | ||||
|     it('should create new question', async () => { | ||||
|         const id = new LearningObjectIdentifier('id03', Language.English, 1); | ||||
|         const student = await studentRepository.findByUsername('Noordkaap'); | ||||
| 
 | ||||
|         const clazz = await getClassRepository().findById('8764b861-90a6-42e5-9732-c0d9eb2f55f9'); | ||||
|         const assignment = await getAssignmentRepository().findByClassAndId(clazz!, 1); | ||||
|         const group = await getGroupRepository().findByAssignmentAndGroupNumber(assignment!, 1); | ||||
|         await questionRepository.createQuestion({ | ||||
|             loId: id, | ||||
|             inGroup: group!, | ||||
|             author: student!, | ||||
|             content: 'question?', | ||||
|         }); | ||||
|  | @ -38,6 +52,52 @@ describe('QuestionRepository', () => { | |||
|         expect(question).toHaveLength(1); | ||||
|     }); | ||||
| 
 | ||||
|     let clazz: Class | null; | ||||
|     let assignment: Assignment | null; | ||||
|     let loId: LearningObjectIdentifier; | ||||
|     it('should find all questions for a certain learning object and assignment', async () => { | ||||
|         clazz = await getClassRepository().findById('8764b861-90a6-42e5-9732-c0d9eb2f55f9'); | ||||
|         assignment = await getAssignmentRepository().findByClassAndId(clazz!, 1); | ||||
|         loId = { | ||||
|             hruid: 'id05', | ||||
|             language: Language.English, | ||||
|             version: 1, | ||||
|         }; | ||||
|         const result = await questionRepository.findAllQuestionsAboutLearningObjectInAssignment(loId, assignment!); | ||||
|         sortQuestions(result); | ||||
| 
 | ||||
|         expect(result).toHaveLength(3); | ||||
| 
 | ||||
|         // Question01: About learning object 'id05', in group #1 for Assignment #1 in class 'id01'
 | ||||
|         expect(result[0].learningObjectHruid).toEqual(loId.hruid); | ||||
|         expect(result[0].sequenceNumber).toEqual(1); | ||||
| 
 | ||||
|         // Question02: About learning object 'id05', in group #1 for Assignment #1 in class 'id01'
 | ||||
|         expect(result[1].learningObjectHruid).toEqual(loId.hruid); | ||||
|         expect(result[1].sequenceNumber).toEqual(2); | ||||
| 
 | ||||
|         // Question05: About learning object 'id05', in group #2 for Assignment #1 in class 'id01'
 | ||||
|         expect(result[2].learningObjectHruid).toEqual(loId.hruid); | ||||
|         expect(result[2].sequenceNumber).toEqual(3); | ||||
| 
 | ||||
|         // Question06: About learning object 'id05', but for Assignment #2 in class 'id01' => not expected.
 | ||||
|     }); | ||||
| 
 | ||||
|     it("should find only the questions for a certain learning object and assignment asked by the user's group", async () => { | ||||
|         const result = await questionRepository.findAllQuestionsAboutLearningObjectInAssignment(loId, assignment!, 'Tool'); | ||||
|         // (student Tool is in group #2)
 | ||||
| 
 | ||||
|         expect(result).toHaveLength(1); | ||||
| 
 | ||||
|         // Question01 and question02 are in group #1 => not displayed.
 | ||||
| 
 | ||||
|         // Question05: About learning object 'id05', in group #2 for Assignment #1 in class 'id01'
 | ||||
|         expect(result[0].learningObjectHruid).toEqual(loId.hruid); | ||||
|         expect(result[0].sequenceNumber).toEqual(3); | ||||
| 
 | ||||
|         // Question06: About learning object 'id05', but for Assignment #2 in class 'id01' => not expected.
 | ||||
|     }); | ||||
| 
 | ||||
|     it('should not find removed question', async () => { | ||||
|         const id = new LearningObjectIdentifier('id04', Language.English, 1); | ||||
|         await questionRepository.removeQuestionByLearningObjectAndSequenceNumber(id, 1); | ||||
|  | @ -47,3 +107,14 @@ describe('QuestionRepository', () => { | |||
|         expect(question).toHaveLength(0); | ||||
|     }); | ||||
| }); | ||||
| 
 | ||||
| function sortQuestions(questions: Question[]): void { | ||||
|     questions.sort((a, b) => { | ||||
|         if (a.learningObjectHruid < b.learningObjectHruid) { | ||||
|             return -1; | ||||
|         } else if (a.learningObjectHruid > b.learningObjectHruid) { | ||||
|             return 1; | ||||
|         } | ||||
|         return a.sequenceNumber! - b.sequenceNumber!; | ||||
|     }); | ||||
| } | ||||
|  |  | |||
|  | @ -3,6 +3,9 @@ import { LearningObject } from '../../../src/entities/content/learning-object.en | |||
| import { setupTestApp } from '../../setup-tests.js'; | ||||
| import { LearningPath } from '../../../src/entities/content/learning-path.entity.js'; | ||||
| import { | ||||
|     getAssignmentRepository, | ||||
|     getClassRepository, | ||||
|     getGroupRepository, | ||||
|     getLearningObjectRepository, | ||||
|     getLearningPathRepository, | ||||
|     getStudentRepository, | ||||
|  | @ -22,6 +25,10 @@ import { Student } from '../../../src/entities/users/student.entity.js'; | |||
| 
 | ||||
| import { LearningObjectNode, LearningPathResponse } from '@dwengo-1/common/interfaces/learning-content'; | ||||
| 
 | ||||
| const STUDENT_A_USERNAME = 'student_a'; | ||||
| const STUDENT_B_USERNAME = 'student_b'; | ||||
| const CLASS_NAME = 'test_class'; | ||||
| 
 | ||||
| async function initExampleData(): Promise<{ learningObject: LearningObject; learningPath: LearningPath }> { | ||||
|     const learningObjectRepo = getLearningObjectRepository(); | ||||
|     const learningPathRepo = getLearningPathRepository(); | ||||
|  | @ -38,6 +45,9 @@ async function initPersonalizationTestData(): Promise<{ | |||
|     studentB: Student; | ||||
| }> { | ||||
|     const studentRepo = getStudentRepository(); | ||||
|     const classRepo = getClassRepository(); | ||||
|     const assignmentRepo = getAssignmentRepository(); | ||||
|     const groupRepo = getGroupRepository(); | ||||
|     const submissionRepo = getSubmissionRepository(); | ||||
|     const learningPathRepo = getLearningPathRepository(); | ||||
|     const learningObjectRepo = getLearningObjectRepository(); | ||||
|  | @ -47,32 +57,69 @@ async function initPersonalizationTestData(): Promise<{ | |||
|     await learningObjectRepo.save(learningContent.extraExerciseObject); | ||||
|     await learningPathRepo.save(learningContent.learningPath); | ||||
| 
 | ||||
|     // Create students
 | ||||
|     const studentA = studentRepo.create({ | ||||
|         username: 'student_a', | ||||
|         username: STUDENT_A_USERNAME, | ||||
|         firstName: 'Aron', | ||||
|         lastName: 'Student', | ||||
|     }); | ||||
|     await studentRepo.save(studentA); | ||||
| 
 | ||||
|     const studentB = studentRepo.create({ | ||||
|         username: STUDENT_B_USERNAME, | ||||
|         firstName: 'Bill', | ||||
|         lastName: 'Student', | ||||
|     }); | ||||
|     await studentRepo.save(studentB); | ||||
| 
 | ||||
|     // Create class for students
 | ||||
|     const testClass = classRepo.create({ | ||||
|         classId: CLASS_NAME, | ||||
|         displayName: 'Test class', | ||||
|     }); | ||||
|     await classRepo.save(testClass); | ||||
| 
 | ||||
|     // Create assignment for students and assign them to different groups
 | ||||
|     const assignment = assignmentRepo.create({ | ||||
|         id: 0, | ||||
|         title: 'Test assignment', | ||||
|         description: 'Test description', | ||||
|         learningPathHruid: learningContent.learningPath.hruid, | ||||
|         learningPathLanguage: learningContent.learningPath.language, | ||||
|         within: testClass, | ||||
|     }); | ||||
| 
 | ||||
|     const groupA = groupRepo.create({ | ||||
|         groupNumber: 0, | ||||
|         members: [studentA], | ||||
|         assignment, | ||||
|     }); | ||||
|     await groupRepo.save(groupA); | ||||
| 
 | ||||
|     const groupB = groupRepo.create({ | ||||
|         groupNumber: 1, | ||||
|         members: [studentB], | ||||
|         assignment, | ||||
|     }); | ||||
|     await groupRepo.save(groupB); | ||||
| 
 | ||||
|     // Let each of the students make a submission in his own group.
 | ||||
|     const submissionA = submissionRepo.create({ | ||||
|         learningObjectHruid: learningContent.branchingObject.hruid, | ||||
|         learningObjectLanguage: learningContent.branchingObject.language, | ||||
|         learningObjectVersion: learningContent.branchingObject.version, | ||||
|         onBehalfOf: groupA, | ||||
|         submitter: studentA, | ||||
|         submissionTime: new Date(), | ||||
|         content: '[0]', | ||||
|     }); | ||||
|     await submissionRepo.save(submissionA); | ||||
| 
 | ||||
|     const studentB = studentRepo.create({ | ||||
|         username: 'student_b', | ||||
|         firstName: 'Bill', | ||||
|         lastName: 'Student', | ||||
|     }); | ||||
|     await studentRepo.save(studentB); | ||||
|     const submissionB = submissionRepo.create({ | ||||
|         learningObjectHruid: learningContent.branchingObject.hruid, | ||||
|         learningObjectLanguage: learningContent.branchingObject.language, | ||||
|         learningObjectVersion: learningContent.branchingObject.version, | ||||
|         onBehalfOf: groupA, | ||||
|         submitter: studentB, | ||||
|         submissionTime: new Date(), | ||||
|         content: '[1]', | ||||
|  |  | |||
|  | @ -13,6 +13,7 @@ import { makeTestAttachments } from './test_assets/content/attachments.testdata. | |||
| import { makeTestQuestions } from './test_assets/questions/questions.testdata.js'; | ||||
| import { makeTestAnswers } from './test_assets/questions/answers.testdata.js'; | ||||
| import { makeTestSubmissions } from './test_assets/assignments/submission.testdata.js'; | ||||
| import { Collection } from '@mikro-orm/core'; | ||||
| 
 | ||||
| export async function setupTestApp(): Promise<void> { | ||||
|     dotenv.config({ path: '.env.test' }); | ||||
|  | @ -28,8 +29,8 @@ export async function setupTestApp(): Promise<void> { | |||
|     const assignments = makeTestAssignemnts(em, classes); | ||||
|     const groups = makeTestGroups(em, students, assignments); | ||||
| 
 | ||||
|     assignments[0].groups = groups.slice(0, 3); | ||||
|     assignments[1].groups = groups.slice(3, 4); | ||||
|     assignments[0].groups = new Collection(groups.slice(0, 3)); | ||||
|     assignments[1].groups = new Collection(groups.slice(3, 4)); | ||||
| 
 | ||||
|     const teacherInvitations = makeTestTeacherInvitations(em, teachers, classes); | ||||
|     const classJoinRequests = makeTestClassJoinRequests(em, students, classes); | ||||
|  | @ -37,7 +38,7 @@ export async function setupTestApp(): Promise<void> { | |||
| 
 | ||||
|     learningObjects[1].attachments = attachments; | ||||
| 
 | ||||
|     const questions = makeTestQuestions(em, students); | ||||
|     const questions = makeTestQuestions(em, students, groups); | ||||
|     const answers = makeTestAnswers(em, teachers, questions); | ||||
|     const submissions = makeTestSubmissions(em, students, groups); | ||||
| 
 | ||||
|  |  | |||
|  | @ -34,5 +34,15 @@ export function makeTestAssignemnts(em: EntityManager, classes: Class[]): Assign | |||
|         groups: [], | ||||
|     }); | ||||
| 
 | ||||
|     return [assignment01, assignment02, assignment03]; | ||||
|     const assignment04 = em.create(Assignment, { | ||||
|         within: classes[0], | ||||
|         id: 4, | ||||
|         title: 'another assignment', | ||||
|         description: 'with a description', | ||||
|         learningPathHruid: 'id01', | ||||
|         learningPathLanguage: Language.English, | ||||
|         groups: [], | ||||
|     }); | ||||
| 
 | ||||
|     return [assignment01, assignment02, assignment03, assignment04]; | ||||
| } | ||||
|  |  | |||
|  | @ -4,29 +4,55 @@ import { Assignment } from '../../../src/entities/assignments/assignment.entity' | |||
| import { Student } from '../../../src/entities/users/student.entity'; | ||||
| 
 | ||||
| export function makeTestGroups(em: EntityManager, students: Student[], assignments: Assignment[]): Group[] { | ||||
|     /* | ||||
|      * Group #1 for Assignment #1 in class 'id01' | ||||
|      * => Assigned to do learning path 'id02' | ||||
|      */ | ||||
|     const group01 = em.create(Group, { | ||||
|         assignment: assignments[0], | ||||
|         groupNumber: 1, | ||||
|         members: students.slice(0, 2), | ||||
|     }); | ||||
| 
 | ||||
|     /* | ||||
|      * Group #2 for Assignment #1 in class 'id01' | ||||
|      * => Assigned to do learning path 'id02' | ||||
|      */ | ||||
|     const group02 = em.create(Group, { | ||||
|         assignment: assignments[0], | ||||
|         groupNumber: 2, | ||||
|         members: students.slice(2, 4), | ||||
|     }); | ||||
| 
 | ||||
|     /* | ||||
|      * Group #3 for Assignment #1 in class 'id01' | ||||
|      * => Assigned to do learning path 'id02' | ||||
|      */ | ||||
|     const group03 = em.create(Group, { | ||||
|         assignment: assignments[0], | ||||
|         groupNumber: 3, | ||||
|         members: students.slice(4, 6), | ||||
|     }); | ||||
| 
 | ||||
|     /* | ||||
|      * Group #4 for Assignment #2 in class 'id02' | ||||
|      * => Assigned to do learning path 'id01' | ||||
|      */ | ||||
|     const group04 = em.create(Group, { | ||||
|         assignment: assignments[1], | ||||
|         groupNumber: 4, | ||||
|         members: students.slice(3, 4), | ||||
|     }); | ||||
| 
 | ||||
|     return [group01, group02, group03, group04]; | ||||
|     /* | ||||
|      * Group #5 for Assignment #4 in class 'id01' | ||||
|      * => Assigned to do learning path 'id01' | ||||
|      */ | ||||
|     const group05 = em.create(Group, { | ||||
|         assignment: assignments[3], | ||||
|         groupNumber: 1, | ||||
|         members: students.slice(0, 2), | ||||
|     }); | ||||
| 
 | ||||
|     return [group01, group02, group03, group04, group05]; | ||||
| } | ||||
|  |  | |||
|  | @ -12,7 +12,7 @@ export function makeTestSubmissions(em: EntityManager, students: Student[], grou | |||
|         submissionNumber: 1, | ||||
|         submitter: students[0], | ||||
|         submissionTime: new Date(2025, 2, 20), | ||||
|         onBehalfOf: groups[0], | ||||
|         onBehalfOf: groups[0], // Group #1 for Assignment #1 in class 'id01'
 | ||||
|         content: 'sub1', | ||||
|     }); | ||||
| 
 | ||||
|  | @ -23,7 +23,7 @@ export function makeTestSubmissions(em: EntityManager, students: Student[], grou | |||
|         submissionNumber: 2, | ||||
|         submitter: students[0], | ||||
|         submissionTime: new Date(2025, 2, 25), | ||||
|         onBehalfOf: groups[0], | ||||
|         onBehalfOf: groups[0], // Group #1 for Assignment #1 in class 'id01'
 | ||||
|         content: '', | ||||
|     }); | ||||
| 
 | ||||
|  | @ -34,6 +34,7 @@ export function makeTestSubmissions(em: EntityManager, students: Student[], grou | |||
|         submissionNumber: 1, | ||||
|         submitter: students[0], | ||||
|         submissionTime: new Date(2025, 2, 20), | ||||
|         onBehalfOf: groups[0], // Group #1 for Assignment #1 in class 'id01'
 | ||||
|         content: '', | ||||
|     }); | ||||
| 
 | ||||
|  | @ -44,6 +45,7 @@ export function makeTestSubmissions(em: EntityManager, students: Student[], grou | |||
|         submissionNumber: 2, | ||||
|         submitter: students[0], | ||||
|         submissionTime: new Date(2025, 2, 25), | ||||
|         onBehalfOf: groups[0], // Group #1 for Assignment #1 in class 'id01'
 | ||||
|         content: '', | ||||
|     }); | ||||
| 
 | ||||
|  | @ -54,8 +56,42 @@ export function makeTestSubmissions(em: EntityManager, students: Student[], grou | |||
|         submissionNumber: 1, | ||||
|         submitter: students[1], | ||||
|         submissionTime: new Date(2025, 2, 20), | ||||
|         onBehalfOf: groups[1], // Group #2 for Assignment #1 in class 'id01'
 | ||||
|         content: '', | ||||
|     }); | ||||
| 
 | ||||
|     return [submission01, submission02, submission03, submission04, submission05]; | ||||
|     const submission06 = em.create(Submission, { | ||||
|         learningObjectHruid: 'id01', | ||||
|         learningObjectLanguage: Language.English, | ||||
|         learningObjectVersion: 1, | ||||
|         submissionNumber: 2, | ||||
|         submitter: students[1], | ||||
|         submissionTime: new Date(2025, 2, 25), | ||||
|         onBehalfOf: groups[4], // Group #5 for Assignment #4 in class 'id01'
 | ||||
|         content: '', | ||||
|     }); | ||||
| 
 | ||||
|     const submission07 = em.create(Submission, { | ||||
|         learningObjectHruid: 'id01', | ||||
|         learningObjectLanguage: Language.English, | ||||
|         learningObjectVersion: 1, | ||||
|         submissionNumber: 3, | ||||
|         submitter: students[3], | ||||
|         submissionTime: new Date(2025, 3, 25), | ||||
|         onBehalfOf: groups[3], // Group #4 for Assignment #2 in class 'id02'
 | ||||
|         content: '', | ||||
|     }); | ||||
| 
 | ||||
|     const submission08 = em.create(Submission, { | ||||
|         learningObjectHruid: 'id02', | ||||
|         learningObjectLanguage: Language.English, | ||||
|         learningObjectVersion: 1, | ||||
|         submissionNumber: 3, | ||||
|         submitter: students[1], | ||||
|         submissionTime: new Date(2025, 4, 7), | ||||
|         onBehalfOf: groups[1], // Group #2 for Assignment #1 in class 'id01'
 | ||||
|         content: '', | ||||
|     }); | ||||
| 
 | ||||
|     return [submission01, submission02, submission03, submission04, submission05, submission06, submission07, submission08]; | ||||
| } | ||||
|  |  | |||
|  | @ -2,31 +2,31 @@ import { EntityManager } from '@mikro-orm/core'; | |||
| import { ClassJoinRequest } from '../../../src/entities/classes/class-join-request.entity'; | ||||
| import { Student } from '../../../src/entities/users/student.entity'; | ||||
| import { Class } from '../../../src/entities/classes/class.entity'; | ||||
| import { ClassJoinRequestStatus } from '@dwengo-1/common/util/class-join-request'; | ||||
| import { ClassStatus } from '@dwengo-1/common/util/class-join-request'; | ||||
| 
 | ||||
| export function makeTestClassJoinRequests(em: EntityManager, students: Student[], classes: Class[]): ClassJoinRequest[] { | ||||
|     const classJoinRequest01 = em.create(ClassJoinRequest, { | ||||
|         requester: students[4], | ||||
|         class: classes[1], | ||||
|         status: ClassJoinRequestStatus.Open, | ||||
|         status: ClassStatus.Open, | ||||
|     }); | ||||
| 
 | ||||
|     const classJoinRequest02 = em.create(ClassJoinRequest, { | ||||
|         requester: students[2], | ||||
|         class: classes[1], | ||||
|         status: ClassJoinRequestStatus.Open, | ||||
|         status: ClassStatus.Open, | ||||
|     }); | ||||
| 
 | ||||
|     const classJoinRequest03 = em.create(ClassJoinRequest, { | ||||
|         requester: students[4], | ||||
|         class: classes[2], | ||||
|         status: ClassJoinRequestStatus.Open, | ||||
|         status: ClassStatus.Open, | ||||
|     }); | ||||
| 
 | ||||
|     const classJoinRequest04 = em.create(ClassJoinRequest, { | ||||
|         requester: students[3], | ||||
|         class: classes[2], | ||||
|         status: ClassJoinRequestStatus.Open, | ||||
|         status: ClassStatus.Open, | ||||
|     }); | ||||
| 
 | ||||
|     return [classJoinRequest01, classJoinRequest02, classJoinRequest03, classJoinRequest04]; | ||||
|  |  | |||
|  | @ -2,30 +2,35 @@ import { EntityManager } from '@mikro-orm/core'; | |||
| import { TeacherInvitation } from '../../../src/entities/classes/teacher-invitation.entity'; | ||||
| import { Teacher } from '../../../src/entities/users/teacher.entity'; | ||||
| import { Class } from '../../../src/entities/classes/class.entity'; | ||||
| import { ClassStatus } from '@dwengo-1/common/util/class-join-request'; | ||||
| 
 | ||||
| export function makeTestTeacherInvitations(em: EntityManager, teachers: Teacher[], classes: Class[]): TeacherInvitation[] { | ||||
|     const teacherInvitation01 = em.create(TeacherInvitation, { | ||||
|         sender: teachers[1], | ||||
|         receiver: teachers[0], | ||||
|         class: classes[1], | ||||
|         status: ClassStatus.Open, | ||||
|     }); | ||||
| 
 | ||||
|     const teacherInvitation02 = em.create(TeacherInvitation, { | ||||
|         sender: teachers[1], | ||||
|         receiver: teachers[2], | ||||
|         class: classes[1], | ||||
|         status: ClassStatus.Open, | ||||
|     }); | ||||
| 
 | ||||
|     const teacherInvitation03 = em.create(TeacherInvitation, { | ||||
|         sender: teachers[2], | ||||
|         receiver: teachers[0], | ||||
|         class: classes[2], | ||||
|         status: ClassStatus.Open, | ||||
|     }); | ||||
| 
 | ||||
|     const teacherInvitation04 = em.create(TeacherInvitation, { | ||||
|         sender: teachers[0], | ||||
|         receiver: teachers[1], | ||||
|         class: classes[0], | ||||
|         status: ClassStatus.Open, | ||||
|     }); | ||||
| 
 | ||||
|     return [teacherInvitation01, teacherInvitation02, teacherInvitation03, teacherInvitation04]; | ||||
|  |  | |||
|  | @ -2,12 +2,14 @@ import { EntityManager } from '@mikro-orm/core'; | |||
| import { Question } from '../../../src/entities/questions/question.entity'; | ||||
| import { Language } from '@dwengo-1/common/util/language'; | ||||
| import { Student } from '../../../src/entities/users/student.entity'; | ||||
| import { Group } from '../../../src/entities/assignments/group.entity'; | ||||
| 
 | ||||
| export function makeTestQuestions(em: EntityManager, students: Student[]): Question[] { | ||||
| export function makeTestQuestions(em: EntityManager, students: Student[], groups: Group[]): Question[] { | ||||
|     const question01 = em.create(Question, { | ||||
|         learningObjectLanguage: Language.English, | ||||
|         learningObjectVersion: 1, | ||||
|         learningObjectHruid: 'id05', | ||||
|         inGroup: groups[0], // Group #1 for Assignment #1 in class 'id01'
 | ||||
|         sequenceNumber: 1, | ||||
|         author: students[0], | ||||
|         timestamp: new Date(), | ||||
|  | @ -18,6 +20,7 @@ export function makeTestQuestions(em: EntityManager, students: Student[]): Quest | |||
|         learningObjectLanguage: Language.English, | ||||
|         learningObjectVersion: 1, | ||||
|         learningObjectHruid: 'id05', | ||||
|         inGroup: groups[0], // Group #1 for Assignment #1 in class 'id01'
 | ||||
|         sequenceNumber: 2, | ||||
|         author: students[2], | ||||
|         timestamp: new Date(), | ||||
|  | @ -30,6 +33,7 @@ export function makeTestQuestions(em: EntityManager, students: Student[]): Quest | |||
|         learningObjectHruid: 'id04', | ||||
|         sequenceNumber: 1, | ||||
|         author: students[0], | ||||
|         inGroup: groups[0], // Group #1 for Assignment #1 in class 'id01'
 | ||||
|         timestamp: new Date(), | ||||
|         content: 'question', | ||||
|     }); | ||||
|  | @ -40,9 +44,32 @@ export function makeTestQuestions(em: EntityManager, students: Student[]): Quest | |||
|         learningObjectHruid: 'id01', | ||||
|         sequenceNumber: 1, | ||||
|         author: students[1], | ||||
|         inGroup: groups[1], // Group #2 for Assignment #1 in class 'id01'
 | ||||
|         timestamp: new Date(), | ||||
|         content: 'question', | ||||
|     }); | ||||
| 
 | ||||
|     return [question01, question02, question03, question04]; | ||||
|     const question05 = em.create(Question, { | ||||
|         learningObjectLanguage: Language.English, | ||||
|         learningObjectVersion: 1, | ||||
|         learningObjectHruid: 'id05', | ||||
|         sequenceNumber: 3, | ||||
|         author: students[1], | ||||
|         inGroup: groups[1], // Group #2 for Assignment #1 in class 'id01'
 | ||||
|         timestamp: new Date(), | ||||
|         content: 'question', | ||||
|     }); | ||||
| 
 | ||||
|     const question06 = em.create(Question, { | ||||
|         learningObjectLanguage: Language.English, | ||||
|         learningObjectVersion: 1, | ||||
|         learningObjectHruid: 'id05', | ||||
|         sequenceNumber: 4, | ||||
|         author: students[2], | ||||
|         inGroup: groups[3], // Group #4 for Assignment #2 in class 'id02'
 | ||||
|         timestamp: new Date(), | ||||
|         content: 'question', | ||||
|     }); | ||||
| 
 | ||||
|     return [question01, question02, question03, question04, question05, question06]; | ||||
| } | ||||
|  |  | |||
|  | @ -14,6 +14,8 @@ import { makeTestQuestions } from '../tests/test_assets/questions/questions.test | |||
| import { makeTestStudents } from '../tests/test_assets/users/students.testdata.js'; | ||||
| import { makeTestTeachers } from '../tests/test_assets/users/teachers.testdata.js'; | ||||
| import { getLogger, Logger } from '../src/logging/initalize.js'; | ||||
| import { Collection } from '@mikro-orm/core'; | ||||
| import { Group } from '../dist/entities/assignments/group.entity.js'; | ||||
| 
 | ||||
| const logger: Logger = getLogger(); | ||||
| 
 | ||||
|  | @ -34,8 +36,8 @@ export async function seedDatabase(): Promise<void> { | |||
|     const assignments = makeTestAssignemnts(em, classes); | ||||
|     const groups = makeTestGroups(em, students, assignments); | ||||
| 
 | ||||
|     assignments[0].groups = groups.slice(0, 3); | ||||
|     assignments[1].groups = groups.slice(3, 4); | ||||
|     assignments[0].groups = new Collection<Group>(groups.slice(0, 3)); | ||||
|     assignments[1].groups = new Collection<Group>(groups.slice(3, 4)); | ||||
| 
 | ||||
|     const teacherInvitations = makeTestTeacherInvitations(em, teachers, classes); | ||||
|     const classJoinRequests = makeTestClassJoinRequests(em, students, classes); | ||||
|  | @ -43,7 +45,7 @@ export async function seedDatabase(): Promise<void> { | |||
| 
 | ||||
|     learningObjects[1].attachments = attachments; | ||||
| 
 | ||||
|     const questions = makeTestQuestions(em, students); | ||||
|     const questions = makeTestQuestions(em, students, groups); | ||||
|     const answers = makeTestAnswers(em, teachers, questions); | ||||
|     const submissions = makeTestSubmissions(em, students, groups); | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,8 +1,8 @@ | |||
| import { StudentDTO } from './student'; | ||||
| import { ClassJoinRequestStatus } from '../util/class-join-request'; | ||||
| import { ClassStatus } from '../util/class-join-request'; | ||||
| 
 | ||||
| export interface ClassJoinRequestDTO { | ||||
|     requester: StudentDTO; | ||||
|     class: string; | ||||
|     status: ClassJoinRequestStatus; | ||||
|     status: ClassStatus; | ||||
| } | ||||
|  |  | |||
|  | @ -6,7 +6,7 @@ export interface GroupDTO { | |||
|     class: string | ClassDTO; | ||||
|     assignment: number | AssignmentDTO; | ||||
|     groupNumber: number; | ||||
|     members: string[] | StudentDTO[]; | ||||
|     members?: string[] | StudentDTO[]; | ||||
| } | ||||
| 
 | ||||
| export interface GroupDTOId { | ||||
|  |  | |||
|  | @ -1,10 +1,12 @@ | |||
| import { LearningObjectIdentifierDTO } from './learning-content'; | ||||
| import { StudentDTO } from './student'; | ||||
| import { GroupDTO } from './group'; | ||||
| 
 | ||||
| export interface QuestionDTO { | ||||
|     learningObjectIdentifier: LearningObjectIdentifierDTO; | ||||
|     sequenceNumber?: number; | ||||
|     author: StudentDTO; | ||||
|     inGroup: GroupDTO; | ||||
|     timestamp: string; | ||||
|     content: string; | ||||
| } | ||||
|  | @ -12,6 +14,7 @@ export interface QuestionDTO { | |||
| export interface QuestionData { | ||||
|     author?: string; | ||||
|     content: string; | ||||
|     inGroup: GroupDTO; | ||||
| } | ||||
| 
 | ||||
| export interface QuestionId { | ||||
|  |  | |||
|  | @ -1,8 +1,16 @@ | |||
| import { UserDTO } from './user'; | ||||
| import { ClassDTO } from './class'; | ||||
| import { ClassStatus } from '../util/class-join-request'; | ||||
| 
 | ||||
| export interface TeacherInvitationDTO { | ||||
|     sender: string | UserDTO; | ||||
|     receiver: string | UserDTO; | ||||
|     class: string | ClassDTO; | ||||
|     classId: string; | ||||
|     status: ClassStatus; | ||||
| } | ||||
| 
 | ||||
| export interface TeacherInvitationData { | ||||
|     sender: string; | ||||
|     receiver: string; | ||||
|     class: string; | ||||
|     accepted?: boolean; // Use for put requests, else skip
 | ||||
| } | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| export enum ClassJoinRequestStatus { | ||||
| export enum ClassStatus { | ||||
|     Open = 'open', | ||||
|     Accepted = 'accepted', | ||||
|     Declined = 'declined', | ||||
|  |  | |||
							
								
								
									
										1
									
								
								docs/.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								docs/.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1 @@ | |||
| api/swagger.json | ||||
|  | @ -15,6 +15,10 @@ const doc = { | |||
|             url: 'http://localhost:3000/', | ||||
|             description: 'Development server', | ||||
|         }, | ||||
|         { | ||||
|             url: 'http://localhost/', | ||||
|             description: 'Staging server', | ||||
|         }, | ||||
|         { | ||||
|             url: 'https://sel2-1.ugent.be/', | ||||
|             description: 'Production server', | ||||
|  | @ -55,4 +59,4 @@ const doc = { | |||
| const outputFile = './swagger.json'; | ||||
| const routes = ['../../backend/src/app.ts']; | ||||
| 
 | ||||
| await swaggerAutogen({ openapi: '3.1.0' })(outputFile, routes, doc); | ||||
| void swaggerAutogen({ openapi: '3.1.0' })(outputFile, routes, doc); | ||||
|  |  | |||
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							|  | @ -44,16 +44,16 @@ export default [ | |||
|             // All @typescript-eslint configuration options are listed.
 | ||||
|             // If the rules are commented, they are configured by the inherited configurations.
 | ||||
| 
 | ||||
|             '@typescript-eslint/adjacent-overload-signatures': 'warn', | ||||
|             '@typescript-eslint/array-type': 'warn', | ||||
|             '@typescript-eslint/adjacent-overload-signatures': 'error', | ||||
|             '@typescript-eslint/array-type': 'error', | ||||
|             '@typescript-eslint/await-thenable': 'error', | ||||
|             '@typescript-eslint/ban-ts-comment': ['error', { minimumDescriptionLength: 10 }], | ||||
|             '@typescript-eslint/ban-tslint-comment': 'error', | ||||
|             camelcase: 'off', | ||||
|             '@typescript-eslint/class-literal-property-style': 'warn', | ||||
|             '@typescript-eslint/class-literal-property-style': 'error', | ||||
|             'class-methods-use-this': 'off', | ||||
|             '@typescript-eslint/class-methods-use-this': ['error', { ignoreOverrideMethods: true }], | ||||
|             '@typescript-eslint/consistent-generic-constructors': 'warn', | ||||
|             '@typescript-eslint/consistent-generic-constructors': 'error', | ||||
|             '@typescript-eslint/consistent-indexed-object-style': 'error', | ||||
|             'consistent-return': 'off', | ||||
|             '@typescript-eslint/consistent-return': 'off', | ||||
|  | @ -64,18 +64,18 @@ export default [ | |||
|             'default-param-last': 'off', | ||||
|             '@typescript-eslint/default-param-last': 'error', | ||||
|             'dot-notation': 'off', | ||||
|             '@typescript-eslint/dot-notation': 'warn', | ||||
|             '@typescript-eslint/explicit-function-return-type': 'warn', | ||||
|             '@typescript-eslint/dot-notation': 'error', | ||||
|             '@typescript-eslint/explicit-function-return-type': 'error', | ||||
|             '@typescript-eslint/explicit-member-accessibility': 'off', | ||||
|             '@typescript-eslint/explicit-module-boundary-types': 'warn', | ||||
|             '@typescript-eslint/explicit-module-boundary-types': 'error', | ||||
|             'init-declarations': 'off', | ||||
|             '@typescript-eslint/init-declarations': 'off', | ||||
|             'max-params': 'off', | ||||
|             '@typescript-eslint/max-params': ['error', { max: 6 }], | ||||
|             '@typescript-eslint/member-ordering': 'warn', | ||||
|             '@typescript-eslint/member-ordering': 'error', | ||||
|             '@typescript-eslint/method-signature-style': 'off', // Don't care about TypeScript strict mode.
 | ||||
|             '@typescript-eslint/naming-convention': [ | ||||
|                 'warn', | ||||
|                 'error', | ||||
|                 { | ||||
|                     // Enforce that all variables, functions and properties are camelCase
 | ||||
|                     selector: 'variableLike', | ||||
|  | @ -113,7 +113,7 @@ export default [ | |||
|             '@typescript-eslint/no-empty-function': 'error', | ||||
|             '@typescript-eslint/no-empty-interface': 'off', | ||||
|             '@typescript-eslint/no-empty-object-type': 'error', | ||||
|             '@typescript-eslint/no-explicit-any': 'warn', // Once in production, this should be an error.
 | ||||
|             '@typescript-eslint/no-explicit-any': 'error', // Once in production, this should be an error.
 | ||||
|             '@typescript-eslint/no-extra-non-null-assertion': 'error', | ||||
|             '@typescript-eslint/no-extraneous-class': 'error', | ||||
|             '@typescript-eslint/no-floating-promises': 'error', | ||||
|  | @ -121,7 +121,7 @@ export default [ | |||
|             'no-implied-eval': 'off', | ||||
|             '@typescript-eslint/no-implied-eval': 'error', | ||||
|             '@typescript-eslint/no-import-type-side-effects': 'error', | ||||
|             '@typescript-eslint/no-inferrable-types': 'warn', | ||||
|             '@typescript-eslint/no-inferrable-types': 'error', | ||||
|             'no-invalid-this': 'off', | ||||
|             '@typescript-eslint/no-invalid-this': 'off', | ||||
|             '@typescript-eslint/no-invalid-void-type': 'error', | ||||
|  | @ -146,10 +146,10 @@ export default [ | |||
|             '@typescript-eslint/no-unsafe-function-type': 'error', | ||||
| 
 | ||||
|             'no-unused-expressions': 'off', | ||||
|             '@typescript-eslint/no-unused-expressions': 'warn', | ||||
|             '@typescript-eslint/no-unused-expressions': 'error', | ||||
|             'no-unused-vars': 'off', | ||||
|             '@typescript-eslint/no-unused-vars': [ | ||||
|                 'warn', | ||||
|                 'error', | ||||
|                 { | ||||
|                     args: 'all', | ||||
|                     argsIgnorePattern: '^_', | ||||
|  | @ -164,53 +164,53 @@ export default [ | |||
| 
 | ||||
|             '@typescript-eslint/parameter-properties': 'off', | ||||
| 
 | ||||
|             '@typescript-eslint/prefer-find': 'warn', | ||||
|             '@typescript-eslint/prefer-find': 'error', | ||||
| 
 | ||||
|             '@typescript-eslint/prefer-function-type': 'error', | ||||
| 
 | ||||
|             '@typescript-eslint/prefer-readonly-parameter-types': 'off', | ||||
|             '@typescript-eslint/prefer-reduce-type-parameter': 'error', | ||||
| 
 | ||||
|             '@typescript-eslint/promise-function-async': 'warn', | ||||
|             '@typescript-eslint/promise-function-async': 'error', | ||||
| 
 | ||||
|             '@typescript-eslint/require-array-sort-compare': 'warn', | ||||
|             '@typescript-eslint/require-array-sort-compare': 'error', | ||||
| 
 | ||||
|             'no-await-in-loop': 'warn', | ||||
|             'no-await-in-loop': 'error', | ||||
|             'no-constructor-return': 'error', | ||||
|             'no-inner-declarations': 'error', | ||||
|             'no-self-compare': 'error', | ||||
|             'no-template-curly-in-string': 'error', | ||||
|             'no-unmodified-loop-condition': 'warn', | ||||
|             'no-unreachable-loop': 'warn', | ||||
|             'no-unmodified-loop-condition': 'error', | ||||
|             'no-unreachable-loop': 'error', | ||||
|             'no-useless-assignment': 'error', | ||||
| 
 | ||||
|             'arrow-body-style': ['warn', 'as-needed'], | ||||
|             'block-scoped-var': 'warn', | ||||
|             'capitalized-comments': 'warn', | ||||
|             'arrow-body-style': ['error', 'as-needed'], | ||||
|             'block-scoped-var': 'error', | ||||
|             'capitalized-comments': 'error', | ||||
|             'consistent-this': 'error', | ||||
|             curly: 'error', | ||||
|             'default-case': 'error', | ||||
|             'default-case-last': 'error', | ||||
|             eqeqeq: 'error', | ||||
|             'func-names': 'warn', | ||||
|             'func-style': ['warn', 'declaration'], | ||||
|             'grouped-accessor-pairs': ['warn', 'getBeforeSet'], | ||||
|             'guard-for-in': 'warn', | ||||
|             'logical-assignment-operators': 'warn', | ||||
|             'max-classes-per-file': 'warn', | ||||
|             'func-names': 'error', | ||||
|             'func-style': ['error', 'declaration'], | ||||
|             'grouped-accessor-pairs': ['error', 'getBeforeSet'], | ||||
|             'guard-for-in': 'error', | ||||
|             'logical-assignment-operators': 'error', | ||||
|             'max-classes-per-file': 'error', | ||||
|             'no-alert': 'error', | ||||
|             'no-bitwise': 'warn', | ||||
|             'no-console': 'warn', | ||||
|             'no-continue': 'warn', | ||||
|             'no-else-return': 'warn', | ||||
|             'no-bitwise': 'error', | ||||
|             'no-console': 'error', | ||||
|             'no-continue': 'error', | ||||
|             'no-else-return': 'error', | ||||
|             'no-eq-null': 'error', | ||||
|             'no-eval': 'error', | ||||
|             'no-extend-native': 'error', | ||||
|             'no-extra-label': 'error', | ||||
|             'no-implicit-coercion': 'warn', | ||||
|             'no-implicit-coercion': 'error', | ||||
|             'no-iterator': 'error', | ||||
|             'no-label-var': 'warn', | ||||
|             'no-labels': 'warn', | ||||
|             'no-label-var': 'error', | ||||
|             'no-labels': 'error', | ||||
|             'no-multi-assign': 'error', | ||||
|             'no-nested-ternary': 'error', | ||||
|             'no-object-constructor': 'error', | ||||
|  |  | |||
|  | @ -21,7 +21,14 @@ const vueConfig = defineConfigWithVueTs( | |||
| 
 | ||||
|     { | ||||
|         name: "app/files-to-ignore", | ||||
|         ignores: ["**/dist/**", "**/dist-ssr/**", "**/coverage/**", "prettier.config.js"], | ||||
|         ignores: [ | ||||
|             "**/dist/**", | ||||
|             "**/dist-ssr/**", | ||||
|             "**/coverage/**", | ||||
|             "prettier.config.js", | ||||
|             "**/test-results/**", | ||||
|             "**/playwright-report/**", | ||||
|         ], | ||||
|     }, | ||||
| 
 | ||||
|     pluginVue.configs["flat/essential"], | ||||
|  |  | |||
|  | @ -20,6 +20,7 @@ | |||
|         "@tanstack/vue-query": "^5.69.0", | ||||
|         "axios": "^1.8.2", | ||||
|         "oidc-client-ts": "^3.1.0", | ||||
|         "uuid": "^11.1.0", | ||||
|         "vue": "^3.5.13", | ||||
|         "vue-i18n": "^11.1.2", | ||||
|         "vue-router": "^4.5.0", | ||||
|  |  | |||
|  | @ -80,13 +80,14 @@ | |||
|             > | ||||
|                 {{ t("classes") }} | ||||
|             </v-btn> | ||||
|             <v-btn | ||||
|                 class="menu_item" | ||||
|                 variant="text" | ||||
|                 to="/user/discussion" | ||||
|             > | ||||
|                 {{ t("discussions") }} | ||||
|             </v-btn> | ||||
|             <!-- TODO Re-enable this button when the discussion page is ready --> | ||||
|             <!--            <v-btn--> | ||||
|             <!--                class="menu_item"--> | ||||
|             <!--                variant="text"--> | ||||
|             <!--                to="/user/discussion"--> | ||||
|             <!--            >--> | ||||
|             <!--                {{ t("discussions") }}--> | ||||
|             <!--            </v-btn>--> | ||||
|             <v-menu open-on-hover> | ||||
|                 <template v-slot:activator="{ props }"> | ||||
|                     <v-btn | ||||
|  |  | |||
|  | @ -2,8 +2,8 @@ import { BaseController } from "./base-controller"; | |||
| import type { ClassDTO } from "@dwengo-1/common/interfaces/class"; | ||||
| import type { StudentsResponse } from "./students"; | ||||
| import type { AssignmentsResponse } from "./assignments"; | ||||
| import type { TeacherInvitationDTO } from "@dwengo-1/common/interfaces/teacher-invitation"; | ||||
| import type { TeachersResponse } from "@/controllers/teachers.ts"; | ||||
| import type { TeacherInvitationsResponse } from "@/controllers/teacher-invitations.ts"; | ||||
| 
 | ||||
| export interface ClassesResponse { | ||||
|     classes: ClassDTO[] | string[]; | ||||
|  | @ -13,14 +13,6 @@ export interface ClassResponse { | |||
|     class: ClassDTO; | ||||
| } | ||||
| 
 | ||||
| export interface TeacherInvitationsResponse { | ||||
|     invites: TeacherInvitationDTO[]; | ||||
| } | ||||
| 
 | ||||
| export interface TeacherInvitationResponse { | ||||
|     invite: TeacherInvitationDTO; | ||||
| } | ||||
| 
 | ||||
| export class ClassController extends BaseController { | ||||
|     constructor() { | ||||
|         super("class"); | ||||
|  |  | |||
|  | @ -36,11 +36,11 @@ export class GroupController extends BaseController { | |||
|         return this.put<GroupResponse>(`/${num}`, data); | ||||
|     } | ||||
| 
 | ||||
|     async getSubmissions(groupNumber: number, full = true): Promise<SubmissionsResponse> { | ||||
|         return this.get<SubmissionsResponse>(`/${groupNumber}/submissions`, { full }); | ||||
|     async getSubmissions(num: number, full = true): Promise<SubmissionsResponse> { | ||||
|         return this.get<SubmissionsResponse>(`/${num}/submissions`, { full }); | ||||
|     } | ||||
| 
 | ||||
|     async getQuestions(groupNumber: number, full = true): Promise<QuestionsResponse> { | ||||
|         return this.get<QuestionsResponse>(`/${groupNumber}/questions`, { full }); | ||||
|     async getQuestions(num: number, full = true): Promise<QuestionsResponse> { | ||||
|         return this.get<QuestionsResponse>(`/${num}/questions`, { full }); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -11,7 +11,7 @@ export interface SubmissionResponse { | |||
| 
 | ||||
| export class SubmissionController extends BaseController { | ||||
|     constructor(classid: string, assignmentNumber: number, groupNumber: number) { | ||||
|         super(`class/${classid}/assignments/${assignmentNumber}/groups/${groupNumber}`); | ||||
|         super(`class/${classid}/assignments/${assignmentNumber}/groups/${groupNumber}/submissions`); | ||||
|     } | ||||
| 
 | ||||
|     async getAll(full = true): Promise<SubmissionsResponse> { | ||||
|  | @ -22,7 +22,7 @@ export class SubmissionController extends BaseController { | |||
|         return this.get<SubmissionResponse>(`/${submissionNumber}`); | ||||
|     } | ||||
| 
 | ||||
|     async createSubmission(data: unknown): Promise<SubmissionResponse> { | ||||
|     async createSubmission(data: SubmissionDTO): Promise<SubmissionResponse> { | ||||
|         return this.post<SubmissionResponse>(`/`, data); | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										36
									
								
								frontend/src/controllers/teacher-invitations.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								frontend/src/controllers/teacher-invitations.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,36 @@ | |||
| import { BaseController } from "@/controllers/base-controller.ts"; | ||||
| import type { TeacherInvitationData, TeacherInvitationDTO } from "@dwengo-1/common/interfaces/teacher-invitation"; | ||||
| 
 | ||||
| export interface TeacherInvitationsResponse { | ||||
|     invitations: TeacherInvitationDTO[]; | ||||
| } | ||||
| 
 | ||||
| export interface TeacherInvitationResponse { | ||||
|     invitation: TeacherInvitationDTO; | ||||
| } | ||||
| 
 | ||||
| export class TeacherInvitationController extends BaseController { | ||||
|     constructor() { | ||||
|         super("teachers/invitations"); | ||||
|     } | ||||
| 
 | ||||
|     async getAll(username: string, sent: boolean): Promise<TeacherInvitationsResponse> { | ||||
|         return this.get<TeacherInvitationsResponse>(`/${username}`, { sent }); | ||||
|     } | ||||
| 
 | ||||
|     async getBy(data: TeacherInvitationData): Promise<TeacherInvitationResponse> { | ||||
|         return this.get<TeacherInvitationResponse>(`/${data.sender}/${data.receiver}/${data.class}`); | ||||
|     } | ||||
| 
 | ||||
|     async create(data: TeacherInvitationData): Promise<TeacherInvitationResponse> { | ||||
|         return this.post<TeacherInvitationResponse>("/", data); | ||||
|     } | ||||
| 
 | ||||
|     async remove(data: TeacherInvitationData): Promise<TeacherInvitationResponse> { | ||||
|         return this.delete<TeacherInvitationResponse>(`/${data.sender}/${data.receiver}/${data.class}`); | ||||
|     } | ||||
| 
 | ||||
|     async respond(data: TeacherInvitationData): Promise<TeacherInvitationResponse> { | ||||
|         return this.put<TeacherInvitationResponse>("/", data); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										217
									
								
								frontend/src/queries/assignments.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										217
									
								
								frontend/src/queries/assignments.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,217 @@ | |||
| import { AssignmentController, type AssignmentResponse, type AssignmentsResponse } from "@/controllers/assignments"; | ||||
| import type { QuestionsResponse } from "@/controllers/questions"; | ||||
| import type { SubmissionsResponse } from "@/controllers/submissions"; | ||||
| import { | ||||
|     useMutation, | ||||
|     useQuery, | ||||
|     useQueryClient, | ||||
|     type UseMutationReturnType, | ||||
|     type UseQueryReturnType, | ||||
| } from "@tanstack/vue-query"; | ||||
| import { computed, toValue, type MaybeRefOrGetter } from "vue"; | ||||
| import { groupsQueryKey, invalidateAllGroupKeys } from "./groups"; | ||||
| import type { GroupsResponse } from "@/controllers/groups"; | ||||
| import type { AssignmentDTO } from "@dwengo-1/common/interfaces/assignment"; | ||||
| import type { QueryClient } from "@tanstack/react-query"; | ||||
| import { invalidateAllSubmissionKeys } from "./submissions"; | ||||
| 
 | ||||
| type AssignmentsQueryKey = ["assignments", string, boolean]; | ||||
| 
 | ||||
| function assignmentsQueryKey(classid: string, full: boolean): AssignmentsQueryKey { | ||||
|     return ["assignments", classid, full]; | ||||
| } | ||||
| 
 | ||||
| type AssignmentQueryKey = ["assignment", string, number]; | ||||
| 
 | ||||
| function assignmentQueryKey(classid: string, assignmentNumber: number): AssignmentQueryKey { | ||||
|     return ["assignment", classid, assignmentNumber]; | ||||
| } | ||||
| 
 | ||||
| type AssignmentSubmissionsQueryKey = ["assignment-submissions", string, number, boolean]; | ||||
| 
 | ||||
| function assignmentSubmissionsQueryKey( | ||||
|     classid: string, | ||||
|     assignmentNumber: number, | ||||
|     full: boolean, | ||||
| ): AssignmentSubmissionsQueryKey { | ||||
|     return ["assignment-submissions", classid, assignmentNumber, full]; | ||||
| } | ||||
| 
 | ||||
| type AssignmentQuestionsQueryKey = ["assignment-questions", string, number, boolean]; | ||||
| 
 | ||||
| function assignmentQuestionsQueryKey( | ||||
|     classid: string, | ||||
|     assignmentNumber: number, | ||||
|     full: boolean, | ||||
| ): AssignmentQuestionsQueryKey { | ||||
|     return ["assignment-questions", classid, assignmentNumber, full]; | ||||
| } | ||||
| 
 | ||||
| export async function invalidateAllAssignmentKeys( | ||||
|     queryClient: QueryClient, | ||||
|     classid?: string, | ||||
|     assignmentNumber?: number, | ||||
| ): Promise<void> { | ||||
|     const keys = ["assignment", "assignment-submissions", "assignment-questions"]; | ||||
| 
 | ||||
|     await Promise.all( | ||||
|         keys.map(async (key) => { | ||||
|             const queryKey = [key, classid, assignmentNumber].filter((arg) => arg !== undefined); | ||||
|             return queryClient.invalidateQueries({ queryKey: queryKey }); | ||||
|         }), | ||||
|     ); | ||||
| 
 | ||||
|     await queryClient.invalidateQueries({ queryKey: ["assignments", classid].filter((arg) => arg !== undefined) }); | ||||
| } | ||||
| 
 | ||||
| function checkEnabled( | ||||
|     classid: string | undefined, | ||||
|     assignmentNumber: number | undefined, | ||||
|     groupNumber: number | undefined, | ||||
| ): boolean { | ||||
|     return Boolean(classid) && !isNaN(Number(groupNumber)) && !isNaN(Number(assignmentNumber)); | ||||
| } | ||||
| 
 | ||||
| interface Values { | ||||
|     cid: string | undefined; | ||||
|     an: number | undefined; | ||||
|     gn: number | undefined; | ||||
|     f: boolean; | ||||
| } | ||||
| 
 | ||||
| function toValues( | ||||
|     classid: MaybeRefOrGetter<string | undefined>, | ||||
|     assignmentNumber: MaybeRefOrGetter<number | undefined>, | ||||
|     groupNumber: MaybeRefOrGetter<number | undefined>, | ||||
|     full: MaybeRefOrGetter<boolean>, | ||||
| ): Values { | ||||
|     return { cid: toValue(classid), an: toValue(assignmentNumber), gn: toValue(groupNumber), f: toValue(full) }; | ||||
| } | ||||
| 
 | ||||
| export function useAssignmentsQuery( | ||||
|     classid: MaybeRefOrGetter<string | undefined>, | ||||
|     full: MaybeRefOrGetter<boolean> = true, | ||||
| ): UseQueryReturnType<AssignmentsResponse, Error> { | ||||
|     const { cid, f } = toValues(classid, 1, 1, full); | ||||
| 
 | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => assignmentsQueryKey(cid!, f)), | ||||
|         queryFn: async () => new AssignmentController(cid!).getAll(f), | ||||
|         enabled: () => checkEnabled(cid, 1, 1), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useAssignmentQuery( | ||||
|     classid: MaybeRefOrGetter<string | undefined>, | ||||
|     assignmentNumber: MaybeRefOrGetter<number | undefined>, | ||||
| ): UseQueryReturnType<AssignmentsResponse, Error> { | ||||
|     const { cid, an } = toValues(classid, assignmentNumber, 1, true); | ||||
| 
 | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => assignmentQueryKey(cid!, an!)), | ||||
|         queryFn: async () => new AssignmentController(cid!).getByNumber(an!), | ||||
|         enabled: () => checkEnabled(cid, an, 1), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useCreateAssignmentMutation(): UseMutationReturnType< | ||||
|     AssignmentResponse, | ||||
|     Error, | ||||
|     { cid: string; data: AssignmentDTO }, | ||||
|     unknown | ||||
| > { | ||||
|     const queryClient = useQueryClient(); | ||||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: async ({ cid, data }) => new AssignmentController(cid).createAssignment(data), | ||||
|         onSuccess: async (_) => { | ||||
|             await queryClient.invalidateQueries({ queryKey: ["assignments"] }); | ||||
|         }, | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useDeleteAssignmentMutation(): UseMutationReturnType< | ||||
|     AssignmentResponse, | ||||
|     Error, | ||||
|     { cid: string; an: number }, | ||||
|     unknown | ||||
| > { | ||||
|     const queryClient = useQueryClient(); | ||||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: async ({ cid, an }) => new AssignmentController(cid).deleteAssignment(an), | ||||
|         onSuccess: async (response) => { | ||||
|             const cid = response.assignment.within; | ||||
|             const an = response.assignment.id; | ||||
| 
 | ||||
|             await invalidateAllAssignmentKeys(queryClient, cid, an); | ||||
|             await invalidateAllGroupKeys(queryClient, cid, an); | ||||
|             await invalidateAllSubmissionKeys(queryClient, cid, an); | ||||
|         }, | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useUpdateAssignmentMutation(): UseMutationReturnType< | ||||
|     AssignmentResponse, | ||||
|     Error, | ||||
|     { cid: string; an: number; data: Partial<AssignmentDTO> }, | ||||
|     unknown | ||||
| > { | ||||
|     const queryClient = useQueryClient(); | ||||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: async ({ cid, an, data }) => new AssignmentController(cid).updateAssignment(an, data), | ||||
|         onSuccess: async (response) => { | ||||
|             const cid = response.assignment.within; | ||||
|             const an = response.assignment.id; | ||||
| 
 | ||||
|             await invalidateAllGroupKeys(queryClient, cid, an); | ||||
|             await queryClient.invalidateQueries({ queryKey: ["assignments"] }); | ||||
|         }, | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useAssignmentSubmissionsQuery( | ||||
|     classid: MaybeRefOrGetter<string | undefined>, | ||||
|     assignmentNumber: MaybeRefOrGetter<number | undefined>, | ||||
|     groupNumber: MaybeRefOrGetter<number | undefined>, | ||||
|     full: MaybeRefOrGetter<boolean> = true, | ||||
| ): UseQueryReturnType<SubmissionsResponse, Error> { | ||||
|     const { cid, an, gn, f } = toValues(classid, assignmentNumber, groupNumber, full); | ||||
| 
 | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => assignmentSubmissionsQueryKey(cid!, an!, f)), | ||||
|         queryFn: async () => new AssignmentController(cid!).getSubmissions(gn!, f), | ||||
|         enabled: () => checkEnabled(cid, an, gn), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useAssignmentQuestionsQuery( | ||||
|     classid: MaybeRefOrGetter<string | undefined>, | ||||
|     assignmentNumber: MaybeRefOrGetter<number | undefined>, | ||||
|     groupNumber: MaybeRefOrGetter<number | undefined>, | ||||
|     full: MaybeRefOrGetter<boolean> = true, | ||||
| ): UseQueryReturnType<QuestionsResponse, Error> { | ||||
|     const { cid, an, gn, f } = toValues(classid, assignmentNumber, groupNumber, full); | ||||
| 
 | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => assignmentQuestionsQueryKey(cid!, an!, f)), | ||||
|         queryFn: async () => new AssignmentController(cid!).getQuestions(gn!, f), | ||||
|         enabled: () => checkEnabled(cid, an, gn), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useAssignmentGroupsQuery( | ||||
|     classid: MaybeRefOrGetter<string | undefined>, | ||||
|     assignmentNumber: MaybeRefOrGetter<number | undefined>, | ||||
|     groupNumber: MaybeRefOrGetter<number | undefined>, | ||||
|     full: MaybeRefOrGetter<boolean> = true, | ||||
| ): UseQueryReturnType<GroupsResponse, Error> { | ||||
|     const { cid, an, gn, f } = toValues(classid, assignmentNumber, groupNumber, full); | ||||
| 
 | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => groupsQueryKey(cid!, an!, f)), | ||||
|         queryFn: async () => new AssignmentController(cid!).getQuestions(gn!, f), | ||||
|         enabled: () => checkEnabled(cid, an, gn), | ||||
|     }); | ||||
| } | ||||
							
								
								
									
										243
									
								
								frontend/src/queries/classes.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										243
									
								
								frontend/src/queries/classes.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,243 @@ | |||
| import { ClassController, type ClassesResponse, type ClassResponse } from "@/controllers/classes"; | ||||
| import type { StudentsResponse } from "@/controllers/students"; | ||||
| import type { ClassDTO } from "@dwengo-1/common/interfaces/class"; | ||||
| import { | ||||
|     QueryClient, | ||||
|     useMutation, | ||||
|     useQuery, | ||||
|     useQueryClient, | ||||
|     type UseMutationReturnType, | ||||
|     type UseQueryReturnType, | ||||
| } from "@tanstack/vue-query"; | ||||
| import { computed, toValue, type MaybeRefOrGetter } from "vue"; | ||||
| import { invalidateAllAssignmentKeys } from "./assignments"; | ||||
| import { invalidateAllGroupKeys } from "./groups"; | ||||
| import { invalidateAllSubmissionKeys } from "./submissions"; | ||||
| 
 | ||||
| const classController = new ClassController(); | ||||
| 
 | ||||
| /* Query cache keys */ | ||||
| type ClassesQueryKey = ["classes", boolean]; | ||||
| 
 | ||||
| function classesQueryKey(full: boolean): ClassesQueryKey { | ||||
|     return ["classes", full]; | ||||
| } | ||||
| 
 | ||||
| type ClassQueryKey = ["class", string]; | ||||
| 
 | ||||
| function classQueryKey(classid: string): ClassQueryKey { | ||||
|     return ["class", classid]; | ||||
| } | ||||
| 
 | ||||
| type ClassStudentsKey = ["class-students", string, boolean]; | ||||
| 
 | ||||
| function classStudentsKey(classid: string, full: boolean): ClassStudentsKey { | ||||
|     return ["class-students", classid, full]; | ||||
| } | ||||
| 
 | ||||
| type ClassTeachersKey = ["class-teachers", string, boolean]; | ||||
| 
 | ||||
| function classTeachersKey(classid: string, full: boolean): ClassTeachersKey { | ||||
|     return ["class-teachers", classid, full]; | ||||
| } | ||||
| 
 | ||||
| type ClassTeacherInvitationsKey = ["class-teacher-invitations", string, boolean]; | ||||
| 
 | ||||
| function classTeacherInvitationsKey(classid: string, full: boolean): ClassTeacherInvitationsKey { | ||||
|     return ["class-teacher-invitations", classid, full]; | ||||
| } | ||||
| 
 | ||||
| type ClassAssignmentsKey = ["class-assignments", string, boolean]; | ||||
| 
 | ||||
| function classAssignmentsKey(classid: string, full: boolean): ClassAssignmentsKey { | ||||
|     return ["class-assignments", classid, full]; | ||||
| } | ||||
| 
 | ||||
| export async function invalidateAllClassKeys(queryClient: QueryClient, classid?: string): Promise<void> { | ||||
|     const keys = ["class", "class-students", "class-teachers", "class-teacher-invitations", "class-assignments"]; | ||||
| 
 | ||||
|     await Promise.all( | ||||
|         keys.map(async (key) => { | ||||
|             const queryKey = [key, classid].filter((arg) => arg !== undefined); | ||||
|             return queryClient.invalidateQueries({ queryKey: queryKey }); | ||||
|         }), | ||||
|     ); | ||||
| 
 | ||||
|     await queryClient.invalidateQueries({ queryKey: ["classes"] }); | ||||
| } | ||||
| 
 | ||||
| /* Queries */ | ||||
| export function useClassesQuery(full: MaybeRefOrGetter<boolean> = true): UseQueryReturnType<ClassesResponse, Error> { | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => classesQueryKey(toValue(full))), | ||||
|         queryFn: async () => classController.getAll(toValue(full)), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useClassQuery(id: MaybeRefOrGetter<string | undefined>): UseQueryReturnType<ClassResponse, Error> { | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => classQueryKey(toValue(id)!)), | ||||
|         queryFn: async () => classController.getById(toValue(id)!), | ||||
|         enabled: () => Boolean(toValue(id)), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useCreateClassMutation(): UseMutationReturnType<ClassResponse, Error, ClassDTO, unknown> { | ||||
|     const queryClient = useQueryClient(); | ||||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: async (data) => classController.createClass(data), | ||||
|         onSuccess: async () => { | ||||
|             await queryClient.invalidateQueries({ queryKey: ["classes"] }); | ||||
|         }, | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useDeleteClassMutation(): UseMutationReturnType<ClassResponse, Error, string, unknown> { | ||||
|     const queryClient = useQueryClient(); | ||||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: async (id) => classController.deleteClass(id), | ||||
|         onSuccess: async (data) => { | ||||
|             await invalidateAllClassKeys(queryClient, data.class.id); | ||||
|             await invalidateAllAssignmentKeys(queryClient, data.class.id); | ||||
|             await invalidateAllGroupKeys(queryClient, data.class.id); | ||||
|             await invalidateAllSubmissionKeys(queryClient, data.class.id); | ||||
|         }, | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useUpdateClassMutation(): UseMutationReturnType< | ||||
|     ClassResponse, | ||||
|     Error, | ||||
|     { cid: string; data: Partial<ClassDTO> }, | ||||
|     unknown | ||||
| > { | ||||
|     const queryClient = useQueryClient(); | ||||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: async ({ cid, data }) => classController.updateClass(cid, data), | ||||
|         onSuccess: async (data) => { | ||||
|             await invalidateAllClassKeys(queryClient, data.class.id); | ||||
|             await invalidateAllAssignmentKeys(queryClient, data.class.id); | ||||
|             await invalidateAllGroupKeys(queryClient, data.class.id); | ||||
|             await invalidateAllSubmissionKeys(queryClient, data.class.id); | ||||
|         }, | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useClassStudentsQuery( | ||||
|     id: MaybeRefOrGetter<string | undefined>, | ||||
|     full: MaybeRefOrGetter<boolean> = true, | ||||
| ): UseQueryReturnType<StudentsResponse, Error> { | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => classStudentsKey(toValue(id)!, toValue(full))), | ||||
|         queryFn: async () => classController.getStudents(toValue(id)!, toValue(full)), | ||||
|         enabled: () => Boolean(toValue(id)), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useClassAddStudentMutation(): UseMutationReturnType< | ||||
|     ClassResponse, | ||||
|     Error, | ||||
|     { id: string; username: string }, | ||||
|     unknown | ||||
| > { | ||||
|     const queryClient = useQueryClient(); | ||||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: async ({ id, username }) => classController.addStudent(id, username), | ||||
|         onSuccess: async (data) => { | ||||
|             await queryClient.invalidateQueries({ queryKey: classQueryKey(data.class.id) }); | ||||
|             await queryClient.invalidateQueries({ queryKey: classStudentsKey(data.class.id, true) }); | ||||
|             await queryClient.invalidateQueries({ queryKey: classStudentsKey(data.class.id, false) }); | ||||
|         }, | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useClassDeleteStudentMutation(): UseMutationReturnType< | ||||
|     ClassResponse, | ||||
|     Error, | ||||
|     { id: string; username: string }, | ||||
|     unknown | ||||
| > { | ||||
|     const queryClient = useQueryClient(); | ||||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: async ({ id, username }) => classController.deleteStudent(id, username), | ||||
|         onSuccess: async (data) => { | ||||
|             await queryClient.invalidateQueries({ queryKey: classQueryKey(data.class.id) }); | ||||
|             await queryClient.invalidateQueries({ queryKey: classStudentsKey(data.class.id, true) }); | ||||
|             await queryClient.invalidateQueries({ queryKey: classStudentsKey(data.class.id, false) }); | ||||
|         }, | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useClassTeachersQuery( | ||||
|     id: MaybeRefOrGetter<string | undefined>, | ||||
|     full: MaybeRefOrGetter<boolean> = true, | ||||
| ): UseQueryReturnType<StudentsResponse, Error> { | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => classTeachersKey(toValue(id)!, toValue(full))), | ||||
|         queryFn: async () => classController.getTeachers(toValue(id)!, toValue(full)), | ||||
|         enabled: () => Boolean(toValue(id)), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useClassAddTeacherMutation(): UseMutationReturnType< | ||||
|     ClassResponse, | ||||
|     Error, | ||||
|     { id: string; username: string }, | ||||
|     unknown | ||||
| > { | ||||
|     const queryClient = useQueryClient(); | ||||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: async ({ id, username }) => classController.addTeacher(id, username), | ||||
|         onSuccess: async (data) => { | ||||
|             await queryClient.invalidateQueries({ queryKey: classQueryKey(data.class.id) }); | ||||
|             await queryClient.invalidateQueries({ queryKey: classTeachersKey(data.class.id, true) }); | ||||
|             await queryClient.invalidateQueries({ queryKey: classTeachersKey(data.class.id, false) }); | ||||
|         }, | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useClassDeleteTeacherMutation(): UseMutationReturnType< | ||||
|     ClassResponse, | ||||
|     Error, | ||||
|     { id: string; username: string }, | ||||
|     unknown | ||||
| > { | ||||
|     const queryClient = useQueryClient(); | ||||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: async ({ id, username }) => classController.deleteTeacher(id, username), | ||||
|         onSuccess: async (data) => { | ||||
|             await queryClient.invalidateQueries({ queryKey: classQueryKey(data.class.id) }); | ||||
|             await queryClient.invalidateQueries({ queryKey: classTeachersKey(data.class.id, true) }); | ||||
|             await queryClient.invalidateQueries({ queryKey: classTeachersKey(data.class.id, false) }); | ||||
|         }, | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useClassTeacherInvitationsQuery( | ||||
|     id: MaybeRefOrGetter<string | undefined>, | ||||
|     full: MaybeRefOrGetter<boolean> = true, | ||||
| ): UseQueryReturnType<StudentsResponse, Error> { | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => classTeacherInvitationsKey(toValue(id)!, toValue(full))), | ||||
|         queryFn: async () => classController.getTeacherInvitations(toValue(id)!, toValue(full)), | ||||
|         enabled: () => Boolean(toValue(id)), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useClassAssignmentsQuery( | ||||
|     id: MaybeRefOrGetter<string | undefined>, | ||||
|     full: MaybeRefOrGetter<boolean> = true, | ||||
| ): UseQueryReturnType<StudentsResponse, Error> { | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => classAssignmentsKey(toValue(id)!, toValue(full))), | ||||
|         queryFn: async () => classController.getAssignments(toValue(id)!, toValue(full)), | ||||
|         enabled: () => Boolean(toValue(id)), | ||||
|     }); | ||||
| } | ||||
							
								
								
									
										219
									
								
								frontend/src/queries/groups.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										219
									
								
								frontend/src/queries/groups.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,219 @@ | |||
| import { GroupController, type GroupResponse, type GroupsResponse } from "@/controllers/groups"; | ||||
| import type { QuestionsResponse } from "@/controllers/questions"; | ||||
| import type { SubmissionsResponse } from "@/controllers/submissions"; | ||||
| import type { GroupDTO } from "@dwengo-1/common/interfaces/group"; | ||||
| import { | ||||
|     QueryClient, | ||||
|     useMutation, | ||||
|     type UseMutationReturnType, | ||||
|     useQuery, | ||||
|     useQueryClient, | ||||
|     type UseQueryReturnType, | ||||
| } from "@tanstack/vue-query"; | ||||
| import { computed, type MaybeRefOrGetter, toValue } from "vue"; | ||||
| import { invalidateAllSubmissionKeys } from "./submissions"; | ||||
| 
 | ||||
| type GroupsQueryKey = ["groups", string, number, boolean]; | ||||
| 
 | ||||
| export function groupsQueryKey(classid: string, assignmentNumber: number, full: boolean): GroupsQueryKey { | ||||
|     return ["groups", classid, assignmentNumber, full]; | ||||
| } | ||||
| 
 | ||||
| type GroupQueryKey = ["group", string, number, number]; | ||||
| 
 | ||||
| function groupQueryKey(classid: string, assignmentNumber: number, groupNumber: number): GroupQueryKey { | ||||
|     return ["group", classid, assignmentNumber, groupNumber]; | ||||
| } | ||||
| 
 | ||||
| type GroupSubmissionsQueryKey = ["group-submissions", string, number, number, boolean]; | ||||
| 
 | ||||
| function groupSubmissionsQueryKey( | ||||
|     classid: string, | ||||
|     assignmentNumber: number, | ||||
|     groupNumber: number, | ||||
|     full: boolean, | ||||
| ): GroupSubmissionsQueryKey { | ||||
|     return ["group-submissions", classid, assignmentNumber, groupNumber, full]; | ||||
| } | ||||
| 
 | ||||
| type GroupQuestionsQueryKey = ["group-questions", string, number, number, boolean]; | ||||
| 
 | ||||
| function groupQuestionsQueryKey( | ||||
|     classid: string, | ||||
|     assignmentNumber: number, | ||||
|     groupNumber: number, | ||||
|     full: boolean, | ||||
| ): GroupQuestionsQueryKey { | ||||
|     return ["group-questions", classid, assignmentNumber, groupNumber, full]; | ||||
| } | ||||
| 
 | ||||
| export async function invalidateAllGroupKeys( | ||||
|     queryClient: QueryClient, | ||||
|     classid?: string, | ||||
|     assignmentNumber?: number, | ||||
|     groupNumber?: number, | ||||
| ): Promise<void> { | ||||
|     const keys = ["group", "group-submissions", "group-questions"]; | ||||
|     await Promise.all( | ||||
|         keys.map(async (key) => { | ||||
|             const queryKey = [key, classid, assignmentNumber, groupNumber].filter((arg) => arg !== undefined); | ||||
|             return queryClient.invalidateQueries({ queryKey: queryKey }); | ||||
|         }), | ||||
|     ); | ||||
| 
 | ||||
|     await queryClient.invalidateQueries({ | ||||
|         queryKey: ["groups", classid, assignmentNumber].filter((arg) => arg !== undefined), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| function checkEnabled( | ||||
|     classid: string | undefined, | ||||
|     assignmentNumber: number | undefined, | ||||
|     groupNumber: number | undefined, | ||||
| ): boolean { | ||||
|     return Boolean(classid) && !isNaN(Number(groupNumber)) && !isNaN(Number(assignmentNumber)); | ||||
| } | ||||
| 
 | ||||
| interface Values { | ||||
|     cid: string | undefined; | ||||
|     an: number | undefined; | ||||
|     gn: number | undefined; | ||||
|     f: boolean; | ||||
| } | ||||
| 
 | ||||
| function toValues( | ||||
|     classid: MaybeRefOrGetter<string | undefined>, | ||||
|     assignmentNumber: MaybeRefOrGetter<number | undefined>, | ||||
|     groupNumber: MaybeRefOrGetter<number | undefined>, | ||||
|     full: MaybeRefOrGetter<boolean>, | ||||
| ): Values { | ||||
|     return { cid: toValue(classid), an: toValue(assignmentNumber), gn: toValue(groupNumber), f: toValue(full) }; | ||||
| } | ||||
| 
 | ||||
| export function useGroupsQuery( | ||||
|     classid: MaybeRefOrGetter<string | undefined>, | ||||
|     assignmentNumber: MaybeRefOrGetter<number | undefined>, | ||||
|     full: MaybeRefOrGetter<boolean> = true, | ||||
| ): UseQueryReturnType<GroupsResponse, Error> { | ||||
|     const { cid, an, f } = toValues(classid, assignmentNumber, 1, full); | ||||
| 
 | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => groupsQueryKey(cid!, an!, f)), | ||||
|         queryFn: async () => new GroupController(cid!, an!).getAll(f), | ||||
|         enabled: () => checkEnabled(cid, an, 1), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useGroupQuery( | ||||
|     classid: MaybeRefOrGetter<string | undefined>, | ||||
|     assignmentNumber: MaybeRefOrGetter<number | undefined>, | ||||
|     groupNumber: MaybeRefOrGetter<number | undefined>, | ||||
| ): UseQueryReturnType<GroupResponse, Error> { | ||||
|     const { cid, an, gn } = toValues(classid, assignmentNumber, groupNumber, true); | ||||
| 
 | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => groupQueryKey(cid!, an!, gn!)), | ||||
|         queryFn: async () => new GroupController(cid!, an!).getByNumber(gn!), | ||||
|         enabled: () => checkEnabled(cid, an, gn), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useCreateGroupMutation(): UseMutationReturnType< | ||||
|     GroupResponse, | ||||
|     Error, | ||||
|     { cid: string; an: number; data: GroupDTO }, | ||||
|     unknown | ||||
| > { | ||||
|     const queryClient = useQueryClient(); | ||||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: async ({ cid, an, data }) => new GroupController(cid, an).createGroup(data), | ||||
|         onSuccess: async (response) => { | ||||
|             const cid = typeof response.group.class === "string" ? response.group.class : response.group.class.id; | ||||
|             const an = | ||||
|                 typeof response.group.assignment === "number" | ||||
|                     ? response.group.assignment | ||||
|                     : response.group.assignment.id; | ||||
| 
 | ||||
|             await queryClient.invalidateQueries({ queryKey: groupsQueryKey(cid, an, true) }); | ||||
|             await queryClient.invalidateQueries({ queryKey: groupsQueryKey(cid, an, false) }); | ||||
|         }, | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useDeleteGroupMutation(): UseMutationReturnType< | ||||
|     GroupResponse, | ||||
|     Error, | ||||
|     { cid: string; an: number; gn: number }, | ||||
|     unknown | ||||
| > { | ||||
|     const queryClient = useQueryClient(); | ||||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: async ({ cid, an, gn }) => new GroupController(cid, an).deleteGroup(gn), | ||||
|         onSuccess: async (response) => { | ||||
|             const cid = typeof response.group.class === "string" ? response.group.class : response.group.class.id; | ||||
|             const an = | ||||
|                 typeof response.group.assignment === "number" | ||||
|                     ? response.group.assignment | ||||
|                     : response.group.assignment.id; | ||||
|             const gn = response.group.groupNumber; | ||||
| 
 | ||||
|             await invalidateAllGroupKeys(queryClient, cid, an, gn); | ||||
|             await invalidateAllSubmissionKeys(queryClient, cid, an, gn); | ||||
|         }, | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useUpdateGroupMutation(): UseMutationReturnType< | ||||
|     GroupResponse, | ||||
|     Error, | ||||
|     { cid: string; an: number; gn: number; data: Partial<GroupDTO> }, | ||||
|     unknown | ||||
| > { | ||||
|     const queryClient = useQueryClient(); | ||||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: async ({ cid, an, gn, data }) => new GroupController(cid, an).updateGroup(gn, data), | ||||
|         onSuccess: async (response) => { | ||||
|             const cid = typeof response.group.class === "string" ? response.group.class : response.group.class.id; | ||||
|             const an = | ||||
|                 typeof response.group.assignment === "number" | ||||
|                     ? response.group.assignment | ||||
|                     : response.group.assignment.id; | ||||
|             const gn = response.group.groupNumber; | ||||
| 
 | ||||
|             await invalidateAllGroupKeys(queryClient, cid, an, gn); | ||||
|         }, | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useGroupSubmissionsQuery( | ||||
|     classid: MaybeRefOrGetter<string | undefined>, | ||||
|     assignmentNumber: MaybeRefOrGetter<number | undefined>, | ||||
|     groupNumber: MaybeRefOrGetter<number | undefined>, | ||||
|     full: MaybeRefOrGetter<boolean> = true, | ||||
| ): UseQueryReturnType<SubmissionsResponse, Error> { | ||||
|     const { cid, an, gn, f } = toValues(classid, assignmentNumber, groupNumber, full); | ||||
| 
 | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => groupSubmissionsQueryKey(cid!, an!, gn!, f)), | ||||
|         queryFn: async () => new GroupController(cid!, an!).getSubmissions(gn!, f), | ||||
|         enabled: () => checkEnabled(cid, an, gn), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useGroupQuestionsQuery( | ||||
|     classid: MaybeRefOrGetter<string | undefined>, | ||||
|     assignmentNumber: MaybeRefOrGetter<number | undefined>, | ||||
|     groupNumber: MaybeRefOrGetter<number | undefined>, | ||||
|     full: MaybeRefOrGetter<boolean> = true, | ||||
| ): UseQueryReturnType<QuestionsResponse, Error> { | ||||
|     const { cid, an, gn, f } = toValues(classid, assignmentNumber, groupNumber, full); | ||||
| 
 | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => groupQuestionsQueryKey(cid!, an!, gn!, f)), | ||||
|         queryFn: async () => new GroupController(cid!, an!).getSubmissions(gn!, f), | ||||
|         enabled: () => checkEnabled(cid, an, gn), | ||||
|     }); | ||||
| } | ||||
							
								
								
									
										183
									
								
								frontend/src/queries/submissions.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										183
									
								
								frontend/src/queries/submissions.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,183 @@ | |||
| import { SubmissionController, type SubmissionResponse, type SubmissionsResponse } from "@/controllers/submissions"; | ||||
| import type { SubmissionDTO } from "@dwengo-1/common/interfaces/submission"; | ||||
| import { | ||||
|     QueryClient, | ||||
|     useMutation, | ||||
|     useQuery, | ||||
|     useQueryClient, | ||||
|     type UseMutationReturnType, | ||||
|     type UseQueryReturnType, | ||||
| } from "@tanstack/vue-query"; | ||||
| import { computed, toValue, type MaybeRefOrGetter } from "vue"; | ||||
| 
 | ||||
| type SubmissionsQueryKey = ["submissions", string, number, number, boolean]; | ||||
| 
 | ||||
| function submissionsQueryKey( | ||||
|     classid: string, | ||||
|     assignmentNumber: number, | ||||
|     groupNumber: number, | ||||
|     full: boolean, | ||||
| ): SubmissionsQueryKey { | ||||
|     return ["submissions", classid, assignmentNumber, groupNumber, full]; | ||||
| } | ||||
| 
 | ||||
| type SubmissionQueryKey = ["submission", string, number, number, number]; | ||||
| 
 | ||||
| function submissionQueryKey( | ||||
|     classid: string, | ||||
|     assignmentNumber: number, | ||||
|     groupNumber: number, | ||||
|     submissionNumber: number, | ||||
| ): SubmissionQueryKey { | ||||
|     return ["submission", classid, assignmentNumber, groupNumber, submissionNumber]; | ||||
| } | ||||
| 
 | ||||
| export async function invalidateAllSubmissionKeys( | ||||
|     queryClient: QueryClient, | ||||
|     classid?: string, | ||||
|     assignmentNumber?: number, | ||||
|     groupNumber?: number, | ||||
|     submissionNumber?: number, | ||||
| ): Promise<void> { | ||||
|     const keys = ["submission"]; | ||||
| 
 | ||||
|     await Promise.all( | ||||
|         keys.map(async (key) => { | ||||
|             const queryKey = [key, classid, assignmentNumber, groupNumber, submissionNumber].filter( | ||||
|                 (arg) => arg !== undefined, | ||||
|             ); | ||||
|             return queryClient.invalidateQueries({ queryKey: queryKey }); | ||||
|         }), | ||||
|     ); | ||||
| 
 | ||||
|     await queryClient.invalidateQueries({ | ||||
|         queryKey: ["submissions", classid, assignmentNumber, groupNumber].filter((arg) => arg !== undefined), | ||||
|     }); | ||||
|     await queryClient.invalidateQueries({ | ||||
|         queryKey: ["group-submissions", classid, assignmentNumber, groupNumber].filter((arg) => arg !== undefined), | ||||
|     }); | ||||
|     await queryClient.invalidateQueries({ | ||||
|         queryKey: ["assignment-submissions", classid, assignmentNumber].filter((arg) => arg !== undefined), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| function checkEnabled( | ||||
|     classid: string | undefined, | ||||
|     assignmentNumber: number | undefined, | ||||
|     groupNumber: number | undefined, | ||||
|     submissionNumber: number | undefined, | ||||
| ): boolean { | ||||
|     return ( | ||||
|         Boolean(classid) && | ||||
|         !isNaN(Number(groupNumber)) && | ||||
|         !isNaN(Number(assignmentNumber)) && | ||||
|         !isNaN(Number(submissionNumber)) | ||||
|     ); | ||||
| } | ||||
| 
 | ||||
| interface Values { | ||||
|     cid: string | undefined; | ||||
|     an: number | undefined; | ||||
|     gn: number | undefined; | ||||
|     sn: number | undefined; | ||||
|     f: boolean; | ||||
| } | ||||
| 
 | ||||
| function toValues( | ||||
|     classid: MaybeRefOrGetter<string | undefined>, | ||||
|     assignmentNumber: MaybeRefOrGetter<number | undefined>, | ||||
|     groupNumber: MaybeRefOrGetter<number | undefined>, | ||||
|     submissionNumber: MaybeRefOrGetter<number | undefined>, | ||||
|     full: MaybeRefOrGetter<boolean>, | ||||
| ): Values { | ||||
|     return { | ||||
|         cid: toValue(classid), | ||||
|         an: toValue(assignmentNumber), | ||||
|         gn: toValue(groupNumber), | ||||
|         sn: toValue(submissionNumber), | ||||
|         f: toValue(full), | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| export function useSubmissionsQuery( | ||||
|     classid: MaybeRefOrGetter<string | undefined>, | ||||
|     assignmentNumber: MaybeRefOrGetter<number | undefined>, | ||||
|     groupNumber: MaybeRefOrGetter<number | undefined>, | ||||
|     full: MaybeRefOrGetter<boolean> = true, | ||||
| ): UseQueryReturnType<SubmissionsResponse, Error> { | ||||
|     const { cid, an, gn, sn, f } = toValues(classid, assignmentNumber, groupNumber, 1, full); | ||||
| 
 | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => submissionsQueryKey(cid!, an!, gn!, f)), | ||||
|         queryFn: async () => new SubmissionController(cid!, an!, gn!).getAll(f), | ||||
|         enabled: () => checkEnabled(cid, an, gn, sn), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useSubmissionQuery( | ||||
|     classid: MaybeRefOrGetter<string | undefined>, | ||||
|     assignmentNumber: MaybeRefOrGetter<number | undefined>, | ||||
|     groupNumber: MaybeRefOrGetter<number | undefined>, | ||||
| ): UseQueryReturnType<SubmissionResponse, Error> { | ||||
|     const { cid, an, gn, sn } = toValues(classid, assignmentNumber, groupNumber, 1, true); | ||||
| 
 | ||||
|     return useQuery({ | ||||
|         queryKey: computed(() => submissionQueryKey(cid!, an!, gn!, sn!)), | ||||
|         queryFn: async () => new SubmissionController(cid!, an!, gn!).getByNumber(sn!), | ||||
|         enabled: () => checkEnabled(cid, an, gn, sn), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useCreateSubmissionMutation(): UseMutationReturnType< | ||||
|     SubmissionResponse, | ||||
|     Error, | ||||
|     { cid: string; an: number; gn: number; data: SubmissionDTO }, | ||||
|     unknown | ||||
| > { | ||||
|     const queryClient = useQueryClient(); | ||||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: async ({ cid, an, gn, data }) => new SubmissionController(cid, an, gn).createSubmission(data), | ||||
|         onSuccess: async (response) => { | ||||
|             if (!response.submission.group) { | ||||
|                 await invalidateAllSubmissionKeys(queryClient); | ||||
|             } else { | ||||
|                 const cls = response.submission.group.class; | ||||
|                 const assignment = response.submission.group.assignment; | ||||
| 
 | ||||
|                 const cid = typeof cls === "string" ? cls : cls.id; | ||||
|                 const an = typeof assignment === "number" ? assignment : assignment.id; | ||||
|                 const gn = response.submission.group.groupNumber; | ||||
| 
 | ||||
|                 await invalidateAllSubmissionKeys(queryClient, cid, an, gn); | ||||
|             } | ||||
|         }, | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useDeleteSubmissionMutation(): UseMutationReturnType< | ||||
|     SubmissionResponse, | ||||
|     Error, | ||||
|     { cid: string; an: number; gn: number; sn: number }, | ||||
|     unknown | ||||
| > { | ||||
|     const queryClient = useQueryClient(); | ||||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: async ({ cid, an, gn, sn }) => new SubmissionController(cid, an, gn).deleteSubmission(sn), | ||||
|         onSuccess: async (response) => { | ||||
|             if (!response.submission.group) { | ||||
|                 await invalidateAllSubmissionKeys(queryClient); | ||||
|             } else { | ||||
|                 const cls = response.submission.group.class; | ||||
|                 const assignment = response.submission.group.assignment; | ||||
| 
 | ||||
|                 const cid = typeof cls === "string" ? cls : cls.id; | ||||
|                 const an = typeof assignment === "number" ? assignment : assignment.id; | ||||
|                 const gn = response.submission.group.groupNumber; | ||||
| 
 | ||||
|                 await invalidateAllSubmissionKeys(queryClient, cid, an, gn); | ||||
|             } | ||||
|         }, | ||||
|     }); | ||||
| } | ||||
							
								
								
									
										78
									
								
								frontend/src/queries/teacher-invitations.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										78
									
								
								frontend/src/queries/teacher-invitations.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,78 @@ | |||
| import { useMutation, useQuery, type UseMutationReturnType, type UseQueryReturnType } from "@tanstack/vue-query"; | ||||
| import { computed, toValue } from "vue"; | ||||
| import type { MaybeRefOrGetter } from "vue"; | ||||
| import { | ||||
|     TeacherInvitationController, | ||||
|     type TeacherInvitationResponse, | ||||
|     type TeacherInvitationsResponse, | ||||
| } from "@/controllers/teacher-invitations.ts"; | ||||
| import type { TeacherInvitationData } from "@dwengo-1/common/interfaces/teacher-invitation"; | ||||
| import type { TeacherDTO } from "@dwengo-1/common/interfaces/teacher"; | ||||
| 
 | ||||
| const controller = new TeacherInvitationController(); | ||||
| 
 | ||||
| /** | ||||
|     All the invitations the teacher sent | ||||
| **/ | ||||
| export function useTeacherInvitationsSentQuery( | ||||
|     username: MaybeRefOrGetter<string | undefined>, | ||||
| ): UseQueryReturnType<TeacherInvitationsResponse, Error> { | ||||
|     return useQuery({ | ||||
|         queryFn: computed(async () => controller.getAll(toValue(username), true)), | ||||
|         enabled: () => Boolean(toValue(username)), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|     All the pending invitations sent to this teacher | ||||
|  */ | ||||
| export function useTeacherInvitationsReceivedQuery( | ||||
|     username: MaybeRefOrGetter<string | undefined>, | ||||
| ): UseQueryReturnType<TeacherInvitationsResponse, Error> { | ||||
|     return useQuery({ | ||||
|         queryFn: computed(async () => controller.getAll(toValue(username), false)), | ||||
|         enabled: () => Boolean(toValue(username)), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useTeacherInvitationQuery( | ||||
|     data: MaybeRefOrGetter<TeacherInvitationData | undefined>, | ||||
| ): UseQueryReturnType<TeacherInvitationResponse, Error> { | ||||
|     return useQuery({ | ||||
|         queryFn: computed(async () => controller.getBy(toValue(data))), | ||||
|         enabled: () => Boolean(toValue(data)), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useCreateTeacherInvitationMutation(): UseMutationReturnType< | ||||
|     TeacherInvitationResponse, | ||||
|     Error, | ||||
|     TeacherDTO, | ||||
|     unknown | ||||
| > { | ||||
|     return useMutation({ | ||||
|         mutationFn: async (data: TeacherInvitationData) => controller.create(data), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useRespondTeacherInvitationMutation(): UseMutationReturnType< | ||||
|     TeacherInvitationResponse, | ||||
|     Error, | ||||
|     TeacherDTO, | ||||
|     unknown | ||||
| > { | ||||
|     return useMutation({ | ||||
|         mutationFn: async (data: TeacherInvitationData) => controller.respond(data), | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function useDeleteTeacherInvitationMutation(): UseMutationReturnType< | ||||
|     TeacherInvitationResponse, | ||||
|     Error, | ||||
|     TeacherDTO, | ||||
|     unknown | ||||
| > { | ||||
|     return useMutation({ | ||||
|         mutationFn: async (data: TeacherInvitationData) => controller.remove(data), | ||||
|     }); | ||||
| } | ||||
|  | @ -7,7 +7,6 @@ import CreateClass from "@/views/classes/CreateClass.vue"; | |||
| import CreateAssignment from "@/views/assignments/CreateAssignment.vue"; | ||||
| import CreateDiscussion from "@/views/discussions/CreateDiscussion.vue"; | ||||
| import CallbackPage from "@/views/CallbackPage.vue"; | ||||
| import UserDiscussions from "@/views/discussions/UserDiscussions.vue"; | ||||
| import UserClasses from "@/views/classes/UserClasses.vue"; | ||||
| import UserAssignments from "@/views/classes/UserAssignments.vue"; | ||||
| import authState from "@/services/auth/auth-service.ts"; | ||||
|  | @ -57,11 +56,12 @@ const router = createRouter({ | |||
|                     name: "UserClasses", | ||||
|                     component: UserClasses, | ||||
|                 }, | ||||
|                 { | ||||
|                     path: "discussion", | ||||
|                     name: "UserDiscussions", | ||||
|                     component: UserDiscussions, | ||||
|                 }, | ||||
|                 // TODO Re-enable this route when the discussion page is ready
 | ||||
|                 // {
 | ||||
|                 //     Path: "discussion",
 | ||||
|                 //     Name: "UserDiscussions",
 | ||||
|                 //     Component: UserDiscussions,
 | ||||
|                 // },
 | ||||
|             ], | ||||
|         }, | ||||
| 
 | ||||
|  |  | |||
|  | @ -276,10 +276,11 @@ | |||
|                 <tbody> | ||||
|                     <tr | ||||
|                         v-for="i in invitations" | ||||
|                         :key="(i.class as ClassDTO).id" | ||||
|                         :key="i.classId" | ||||
|                     > | ||||
|                         <td> | ||||
|                             {{ (i.class as ClassDTO).displayName }} | ||||
|                             {{ i.classId }} | ||||
|                             <!-- TODO fetch display name via classId because db only returns classId field --> | ||||
|                         </td> | ||||
|                         <td>{{ (i.sender as TeacherDTO).firstName + " " + (i.sender as TeacherDTO).lastName }}</td> | ||||
|                         <td class="text-right"> | ||||
|  |  | |||
							
								
								
									
										174
									
								
								package-lock.json
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										174
									
								
								package-lock.json
									
										
									
										generated
									
									
									
								
							|  | @ -72,6 +72,133 @@ | |||
|                 "vitest": "^3.0.6" | ||||
|             } | ||||
|         }, | ||||
|         "backend/node_modules/@mikro-orm/cli": { | ||||
|             "version": "6.4.9", | ||||
|             "resolved": "https://registry.npmjs.org/@mikro-orm/cli/-/cli-6.4.9.tgz", | ||||
|             "integrity": "sha512-LQzVsmar/0DoJkPGyz3OpB8pa9BCQtvYreEC71h0O+RcizppJjgBQNTkj5tJd2Iqvh4hSaMv6qTv0l5UK6F2Vw==", | ||||
|             "dev": true, | ||||
|             "license": "MIT", | ||||
|             "dependencies": { | ||||
|                 "@jercle/yargonaut": "1.1.5", | ||||
|                 "@mikro-orm/core": "6.4.9", | ||||
|                 "@mikro-orm/knex": "6.4.9", | ||||
|                 "fs-extra": "11.3.0", | ||||
|                 "tsconfig-paths": "4.2.0", | ||||
|                 "yargs": "17.7.2" | ||||
|             }, | ||||
|             "bin": { | ||||
|                 "mikro-orm": "cli", | ||||
|                 "mikro-orm-esm": "esm" | ||||
|             }, | ||||
|             "engines": { | ||||
|                 "node": ">= 18.12.0" | ||||
|             } | ||||
|         }, | ||||
|         "backend/node_modules/@mikro-orm/core": { | ||||
|             "version": "6.4.9", | ||||
|             "resolved": "https://registry.npmjs.org/@mikro-orm/core/-/core-6.4.9.tgz", | ||||
|             "integrity": "sha512-osB2TbvSH4ZL1s62LCBQFAnxPqLycX5fakPHOoztudixqfbVD5QQydeGizJXMMh2zKP6vRCwIJy3MeSuFxPjHg==", | ||||
|             "license": "MIT", | ||||
|             "dependencies": { | ||||
|                 "dataloader": "2.2.3", | ||||
|                 "dotenv": "16.4.7", | ||||
|                 "esprima": "4.0.1", | ||||
|                 "fs-extra": "11.3.0", | ||||
|                 "globby": "11.1.0", | ||||
|                 "mikro-orm": "6.4.9", | ||||
|                 "reflect-metadata": "0.2.2" | ||||
|             }, | ||||
|             "engines": { | ||||
|                 "node": ">= 18.12.0" | ||||
|             }, | ||||
|             "funding": { | ||||
|                 "url": "https://github.com/sponsors/b4nan" | ||||
|             } | ||||
|         }, | ||||
|         "backend/node_modules/@mikro-orm/knex": { | ||||
|             "version": "6.4.9", | ||||
|             "resolved": "https://registry.npmjs.org/@mikro-orm/knex/-/knex-6.4.9.tgz", | ||||
|             "integrity": "sha512-iGXJfe/TziVOQsWuxMIqkOpurysWzQA6kj3+FDtOkHJAijZhqhjSBnfUVHHY/JzU9o0M0rgLrDVJFry/uEaJEA==", | ||||
|             "license": "MIT", | ||||
|             "dependencies": { | ||||
|                 "fs-extra": "11.3.0", | ||||
|                 "knex": "3.1.0", | ||||
|                 "sqlstring": "2.3.3" | ||||
|             }, | ||||
|             "engines": { | ||||
|                 "node": ">= 18.12.0" | ||||
|             }, | ||||
|             "peerDependencies": { | ||||
|                 "@mikro-orm/core": "^6.0.0", | ||||
|                 "better-sqlite3": "*", | ||||
|                 "libsql": "*", | ||||
|                 "mariadb": "*" | ||||
|             }, | ||||
|             "peerDependenciesMeta": { | ||||
|                 "better-sqlite3": { | ||||
|                     "optional": true | ||||
|                 }, | ||||
|                 "libsql": { | ||||
|                     "optional": true | ||||
|                 }, | ||||
|                 "mariadb": { | ||||
|                     "optional": true | ||||
|                 } | ||||
|             } | ||||
|         }, | ||||
|         "backend/node_modules/@mikro-orm/postgresql": { | ||||
|             "version": "6.4.9", | ||||
|             "resolved": "https://registry.npmjs.org/@mikro-orm/postgresql/-/postgresql-6.4.9.tgz", | ||||
|             "integrity": "sha512-ZdVVFAL/TSbzpEmChGdH0oUpy2KiHLjNIeItZHRQgInn1X9p0qx28VVDR78p8qgRGkQ3LquxGTkvmWI0w7qi3A==", | ||||
|             "license": "MIT", | ||||
|             "dependencies": { | ||||
|                 "@mikro-orm/knex": "6.4.9", | ||||
|                 "pg": "8.13.3", | ||||
|                 "postgres-array": "3.0.4", | ||||
|                 "postgres-date": "2.1.0", | ||||
|                 "postgres-interval": "4.0.2" | ||||
|             }, | ||||
|             "engines": { | ||||
|                 "node": ">= 18.12.0" | ||||
|             }, | ||||
|             "peerDependencies": { | ||||
|                 "@mikro-orm/core": "^6.0.0" | ||||
|             } | ||||
|         }, | ||||
|         "backend/node_modules/@mikro-orm/reflection": { | ||||
|             "version": "6.4.9", | ||||
|             "resolved": "https://registry.npmjs.org/@mikro-orm/reflection/-/reflection-6.4.9.tgz", | ||||
|             "integrity": "sha512-fgY7yLrcZm3J/8dv9reUC4PQo7C2muImU31jmzz1SxmNKPJFDJl7OzcDZlM5NOisXzsWUBrcNdCyuQiWViVc3A==", | ||||
|             "license": "MIT", | ||||
|             "dependencies": { | ||||
|                 "globby": "11.1.0", | ||||
|                 "ts-morph": "25.0.1" | ||||
|             }, | ||||
|             "engines": { | ||||
|                 "node": ">= 18.12.0" | ||||
|             }, | ||||
|             "peerDependencies": { | ||||
|                 "@mikro-orm/core": "^6.0.0" | ||||
|             } | ||||
|         }, | ||||
|         "backend/node_modules/@mikro-orm/sqlite": { | ||||
|             "version": "6.4.9", | ||||
|             "resolved": "https://registry.npmjs.org/@mikro-orm/sqlite/-/sqlite-6.4.9.tgz", | ||||
|             "integrity": "sha512-O7Jy/5DrTWpJI/3qkhRJHl+OcECx1N625LHDODAAauOK3+MJB/bj80TrvQhe6d/CHZMmvxZ7m2GzaL1NulKxRw==", | ||||
|             "license": "MIT", | ||||
|             "dependencies": { | ||||
|                 "@mikro-orm/knex": "6.4.9", | ||||
|                 "fs-extra": "11.3.0", | ||||
|                 "sqlite3": "5.1.7", | ||||
|                 "sqlstring-sqlite": "0.1.1" | ||||
|             }, | ||||
|             "engines": { | ||||
|                 "node": ">= 18.12.0" | ||||
|             }, | ||||
|             "peerDependencies": { | ||||
|                 "@mikro-orm/core": "^6.0.0" | ||||
|             } | ||||
|         }, | ||||
|         "backend/node_modules/globals": { | ||||
|             "version": "15.15.0", | ||||
|             "resolved": "https://registry.npmjs.org/globals/-/globals-15.15.0.tgz", | ||||
|  | @ -85,6 +212,48 @@ | |||
|                 "url": "https://github.com/sponsors/sindresorhus" | ||||
|             } | ||||
|         }, | ||||
|         "backend/node_modules/mikro-orm": { | ||||
|             "version": "6.4.9", | ||||
|             "resolved": "https://registry.npmjs.org/mikro-orm/-/mikro-orm-6.4.9.tgz", | ||||
|             "integrity": "sha512-XwVrWNT4NNwS6kHIKFNDfvy8L1eWcBBEHeTVzFFYcnb2ummATaLxqeVkNEmKA68jmdtfQdUmWBqGdbcIPwtL2Q==", | ||||
|             "license": "MIT", | ||||
|             "engines": { | ||||
|                 "node": ">= 18.12.0" | ||||
|             } | ||||
|         }, | ||||
|         "backend/node_modules/pg": { | ||||
|             "version": "8.13.3", | ||||
|             "resolved": "https://registry.npmjs.org/pg/-/pg-8.13.3.tgz", | ||||
|             "integrity": "sha512-P6tPt9jXbL9HVu/SSRERNYaYG++MjnscnegFh9pPHihfoBSujsrka0hyuymMzeJKFWrcG8wvCKy8rCe8e5nDUQ==", | ||||
|             "license": "MIT", | ||||
|             "dependencies": { | ||||
|                 "pg-connection-string": "^2.7.0", | ||||
|                 "pg-pool": "^3.7.1", | ||||
|                 "pg-protocol": "^1.7.1", | ||||
|                 "pg-types": "^2.1.0", | ||||
|                 "pgpass": "1.x" | ||||
|             }, | ||||
|             "engines": { | ||||
|                 "node": ">= 8.0.0" | ||||
|             }, | ||||
|             "optionalDependencies": { | ||||
|                 "pg-cloudflare": "^1.1.1" | ||||
|             }, | ||||
|             "peerDependencies": { | ||||
|                 "pg-native": ">=3.0.1" | ||||
|             }, | ||||
|             "peerDependenciesMeta": { | ||||
|                 "pg-native": { | ||||
|                     "optional": true | ||||
|                 } | ||||
|             } | ||||
|         }, | ||||
|         "backend/node_modules/pg-connection-string": { | ||||
|             "version": "2.7.0", | ||||
|             "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.7.0.tgz", | ||||
|             "integrity": "sha512-PI2W9mv53rXJQEOb8xNR8lH7Hr+EKa6oJa38zsK0S/ky2er16ios1wLKhZyxzD7jUReiWokc9WK5nxSnC7W1TA==", | ||||
|             "license": "MIT" | ||||
|         }, | ||||
|         "common": { | ||||
|             "name": "@dwengo-1/common", | ||||
|             "version": "0.1.1" | ||||
|  | @ -104,6 +273,7 @@ | |||
|                 "@tanstack/vue-query": "^5.69.0", | ||||
|                 "axios": "^1.8.2", | ||||
|                 "oidc-client-ts": "^3.1.0", | ||||
|                 "uuid": "^11.1.0", | ||||
|                 "vue": "^3.5.13", | ||||
|                 "vue-i18n": "^11.1.2", | ||||
|                 "vue-router": "^4.5.0", | ||||
|  | @ -8653,6 +8823,7 @@ | |||
|             "resolved": "https://registry.npmjs.org/pg/-/pg-8.14.1.tgz", | ||||
|             "integrity": "sha512-0TdbqfjwIun9Fm/r89oB7RFQ0bLgduAhiIqIXOsyKoiC/L54DbuAAzIEN/9Op0f1Po9X7iCPXGoa/Ah+2aI8Xw==", | ||||
|             "license": "MIT", | ||||
|             "peer": true, | ||||
|             "dependencies": { | ||||
|                 "pg-connection-string": "^2.7.0", | ||||
|                 "pg-pool": "^3.8.0", | ||||
|  | @ -8762,7 +8933,8 @@ | |||
|             "version": "2.7.0", | ||||
|             "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.7.0.tgz", | ||||
|             "integrity": "sha512-PI2W9mv53rXJQEOb8xNR8lH7Hr+EKa6oJa38zsK0S/ky2er16ios1wLKhZyxzD7jUReiWokc9WK5nxSnC7W1TA==", | ||||
|             "license": "MIT" | ||||
|             "license": "MIT", | ||||
|             "peer": true | ||||
|         }, | ||||
|         "node_modules/pgpass": { | ||||
|             "version": "1.0.5", | ||||
|  |  | |||
|  | @ -5,7 +5,7 @@ | |||
|     "private": true, | ||||
|     "type": "module", | ||||
|     "scripts": { | ||||
|         "prebuild": "npm run clean", | ||||
|         "prebuild": "npm run clean && npm run swagger --workspace=docs", | ||||
|         "build": "tsc --build tsconfig.build.json", | ||||
|         "clean": "tsc --build tsconfig.build.json --clean", | ||||
|         "watch": "tsc --build tsconfig.build.json --watch", | ||||
|  |  | |||
		Reference in a new issue
	
	 Adriaan Jacquet
						Adriaan Jacquet