diff --git a/backend/src/config.ts b/backend/src/config.ts index 65582c8b..69af5d74 100644 --- a/backend/src/config.ts +++ b/backend/src/config.ts @@ -1,5 +1,5 @@ import { EnvVars, getEnvVar } from './util/envvars.js'; -import {Language} from "./entities/content/language.js"; +import { Language } from './entities/content/language.js'; // API export const DWENGO_API_BASE = getEnvVar(EnvVars.LearningContentRepoApiBaseUrl); diff --git a/backend/src/controllers/assignments.ts b/backend/src/controllers/assignments.ts index dcaa07a2..b0695b85 100644 --- a/backend/src/controllers/assignments.ts +++ b/backend/src/controllers/assignments.ts @@ -9,10 +9,7 @@ interface AssignmentParams { id: string; } -export async function getAllAssignmentsHandler( - req: Request, - res: Response -): Promise { +export async function getAllAssignmentsHandler(req: Request, res: Response): Promise { const classid = req.params.classid; const full = req.query.full === 'true'; @@ -23,18 +20,11 @@ export async function getAllAssignmentsHandler( }); } -export async function createAssignmentHandler( - req: Request, - res: Response, -): Promise { +export async function createAssignmentHandler(req: Request, res: Response): Promise { const classid = req.params.classid; const assignmentData = req.body as AssignmentDTO; - if (!assignmentData.description - || !assignmentData.language - || !assignmentData.learningPath - || !assignmentData.title - ) { + if (!assignmentData.description || !assignmentData.language || !assignmentData.learningPath || !assignmentData.title) { res.status(400).json({ error: 'Missing one or more required fields: title, description, learningPath, title', }); @@ -44,17 +34,14 @@ export async function createAssignmentHandler( const assignment = createAssignment(classid, assignmentData); if (!assignment) { - res.status(500).json({ error: "Could not create assignment "}); + res.status(500).json({ error: 'Could not create assignment ' }); return; } res.status(201).json({ assignment: assignment }); } -export async function getAssignmentHandler( - req: Request, - res: Response -): Promise { +export async function getAssignmentHandler(req: Request, res: Response): Promise { const id = +req.params.id; const classid = req.params.classid; @@ -73,10 +60,7 @@ export async function getAssignmentHandler( res.json(assignment); } -export async function getAssignmentsSubmissionsHandler( - req: Request, - res: Response, -): Promise { +export async function getAssignmentsSubmissionsHandler(req: Request, res: Response): Promise { const classid = req.params.classid; const assignmentNumber = +req.params.id; diff --git a/backend/src/controllers/classes.ts b/backend/src/controllers/classes.ts index 5fd4ce9d..6fb58fb9 100644 --- a/backend/src/controllers/classes.ts +++ b/backend/src/controllers/classes.ts @@ -1,19 +1,9 @@ import { Request, Response } from 'express'; -import { - createClass, - getAllClasses, - getClass, - getClassStudents, - getClassStudentsIds, - getClassTeacherInvitations, -} from '../services/class.js'; +import { createClass, getAllClasses, getClass, getClassStudents, getClassStudentsIds, getClassTeacherInvitations } from '../services/class.js'; import { ClassDTO, mapToClass } from '../interfaces/class.js'; import { getClassRepository, getStudentRepository, getTeacherRepository } from '../data/repositories.js'; -export async function getAllClassesHandler( - req: Request, - res: Response -): Promise { +export async function getAllClassesHandler(req: Request, res: Response): Promise { const full = req.query.full === 'true'; const classes = await getAllClasses(full); @@ -22,10 +12,7 @@ export async function getAllClassesHandler( }); } -export async function createClassHandler( - req: Request, - res: Response, -): Promise { +export async function createClassHandler(req: Request, res: Response): Promise { const classData = req.body as ClassDTO; if (!classData.displayName) { @@ -38,17 +25,14 @@ export async function createClassHandler( const cls = await createClass(classData); if (!cls) { - res.status(500).json({ error: "Something went wrong while creating class" }); - return + res.status(500).json({ error: 'Something went wrong while creating class' }); + return; } res.status(201).json({ class: cls }); } -export async function getClassHandler( - req: Request, - res: Response -): Promise { +export async function getClassHandler(req: Request, res: Response): Promise { try { const classId = req.params.id; const cls = await getClass(classId); @@ -71,26 +55,18 @@ export async function getClassHandler( } } -export async function getClassStudentsHandler( - req: Request, - res: Response -): Promise { +export async function getClassStudentsHandler(req: Request, res: Response): Promise { const classId = req.params.id; const full = req.query.full === 'true'; - const students = full - ? await getClassStudents(classId) - : await getClassStudentsIds(classId); + const students = full ? await getClassStudents(classId) : await getClassStudentsIds(classId); res.json({ students: students, }); } -export async function getTeacherInvitationsHandler( - req: Request, - res: Response -): Promise { +export async function getTeacherInvitationsHandler(req: Request, res: Response): Promise { const classId = req.params.id; const full = req.query.full === 'true'; // TODO: not implemented yet diff --git a/backend/src/controllers/groups.ts b/backend/src/controllers/groups.ts index 9ef5b93c..dbe83060 100644 --- a/backend/src/controllers/groups.ts +++ b/backend/src/controllers/groups.ts @@ -9,10 +9,7 @@ interface GroupParams { groupid?: string; } -export async function getGroupHandler( - req: Request, - res: Response -): Promise { +export async function getGroupHandler(req: Request, res: Response): Promise { const classId = req.params.classid; const full = req.query.full === 'true'; const assignmentId = +req.params.assignmentid; @@ -34,10 +31,7 @@ export async function getGroupHandler( res.json(group); } -export async function getAllGroupsHandler( - req: Request, - res: Response -): Promise { +export async function getAllGroupsHandler(req: Request, res: Response): Promise { const classId = req.params.classid; const full = req.query.full === 'true'; @@ -55,10 +49,7 @@ export async function getAllGroupsHandler( }); } -export async function createGroupHandler( - req: Request, - res: Response, -): Promise { +export async function createGroupHandler(req: Request, res: Response): Promise { const classid = req.params.classid; const assignmentId = +req.params.assignmentid; @@ -71,17 +62,14 @@ export async function createGroupHandler( const group = createGroup(groupData, classid, assignmentId); if (!group) { - res.status(500).json({ error: "Something went wrong while creating group" }); - return + res.status(500).json({ error: 'Something went wrong while creating group' }); + return; } res.status(201).json({ group: group }); } -export async function getGroupSubmissionsHandler( - req: Request, - res: Response, -): Promise { +export async function getGroupSubmissionsHandler(req: Request, res: Response): Promise { const classId = req.params.classid; // Const full = req.query.full === 'true'; @@ -104,4 +92,4 @@ export async function getGroupSubmissionsHandler( res.json({ submissions: submissions, }); -} \ No newline at end of file +} diff --git a/backend/src/controllers/questions.ts b/backend/src/controllers/questions.ts index b4451aa2..917b48ae 100644 --- a/backend/src/controllers/questions.ts +++ b/backend/src/controllers/questions.ts @@ -1,121 +1,119 @@ -import {Request, Response} from "express"; -import { - createQuestion, - deleteQuestion, - getAllQuestions, - getAnswersByQuestion, - getQuestion -} from "../services/questions.js"; -import {QuestionDTO, QuestionId} from "../interfaces/question.js"; -import {FALLBACK_LANG, FALLBACK_SEQ_NUM} from "../config.js"; -import {LearningObjectIdentifier} from "../entities/content/learning-object-identifier.js"; -import {Language} from "../entities/content/language.js"; +import { Request, Response } from 'express'; +import { createQuestion, deleteQuestion, getAllQuestions, getAnswersByQuestion, getQuestion } from '../services/questions.js'; +import { QuestionDTO, QuestionId } from '../interfaces/question.js'; +import { FALLBACK_LANG, FALLBACK_SEQ_NUM } from '../config.js'; +import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; +import { Language } from '../entities/content/language.js'; function getObjectId(req: Request, res: Response): LearningObjectIdentifier | null { - const { hruid, version } = req.params - const lang = req.query.lang + const { hruid, version } = req.params; + const lang = req.query.lang; - if (!hruid || !version ) { - res.status(400).json({ error: "Missing required parameters." }); + if (!hruid || !version) { + res.status(400).json({ error: 'Missing required parameters.' }); return null; } return { hruid, - language: lang as Language || FALLBACK_LANG, - version: +version - } + language: (lang as Language) || FALLBACK_LANG, + version: +version, + }; } function getQuestionId(req: Request, res: Response): QuestionId | null { - const seq = req.params.seq - const learningObjectIdentifier = getObjectId(req,res); + const seq = req.params.seq; + const learningObjectIdentifier = getObjectId(req, res); - if (!learningObjectIdentifier) - {return null} + if (!learningObjectIdentifier) { + return null; + } return { learningObjectIdentifier, - sequenceNumber: seq ? Number(seq) : FALLBACK_SEQ_NUM - } + sequenceNumber: seq ? Number(seq) : FALLBACK_SEQ_NUM, + }; } -export async function getAllQuestionsHandler( - req: Request, - res: Response -): Promise { +export async function getAllQuestionsHandler(req: Request, res: Response): Promise { const objectId = getObjectId(req, res); const full = req.query.full === 'true'; - if (!objectId) - {return} + if (!objectId) { + return; + } const questions = await getAllQuestions(objectId, full); - if (!questions) - {res.status(404).json({ error: `Questions not found.` });} - else - {res.json(questions);} + if (!questions) { + res.status(404).json({ error: `Questions not found.` }); + } else { + res.json(questions); + } } export async function getQuestionHandler(req: Request, res: Response): Promise { const questionId = getQuestionId(req, res); - if (!questionId) - {return} + if (!questionId) { + return; + } const question = await getQuestion(questionId); - if (!question) - {res.status(404).json({ error: `Question not found.` });} - else - {res.json(question)} + if (!question) { + res.status(404).json({ error: `Question not found.` }); + } else { + res.json(question); + } } export async function getQuestionAnswersHandler(req: Request, res: Response): Promise { const questionId = getQuestionId(req, res); const full = req.query.full === 'true'; - if (!questionId) - {return} + if (!questionId) { + return; + } const answers = getAnswersByQuestion(questionId, full); - if (!answers) - {res.status(404).json({ error: `Questions not found.` });} - else - {res.json(answers)} + if (!answers) { + res.status(404).json({ error: `Questions not found.` }); + } else { + res.json(answers); + } } export async function createQuestionHandler(req: Request, res: Response): Promise { const questionDTO = req.body as QuestionDTO; if (!questionDTO.learningObjectIdentifier || !questionDTO.author || !questionDTO.content) { - res.status(400).json({error: 'Missing required fields: identifier and content'}); + res.status(400).json({ error: 'Missing required fields: identifier and content' }); return; } const question = await createQuestion(questionDTO); - if (!question) - {res.status(400).json({error: 'Could not add question'});} - else - {res.json(question)} + if (!question) { + res.status(400).json({ error: 'Could not add question' }); + } else { + res.json(question); + } } export async function deleteQuestionHandler(req: Request, res: Response): Promise { const questionId = getQuestionId(req, res); - if (!questionId) - {return} + if (!questionId) { + return; + } const question = await deleteQuestion(questionId); - if (!question) - {res.status(400).json({error: 'Could not find nor delete question'});} - else - {res.json(question)} + if (!question) { + res.status(400).json({ error: 'Could not find nor delete question' }); + } else { + res.json(question); + } } - - - diff --git a/backend/src/controllers/students.ts b/backend/src/controllers/students.ts index aae37b50..5c17513d 100644 --- a/backend/src/controllers/students.ts +++ b/backend/src/controllers/students.ts @@ -10,9 +10,7 @@ import { } from '../services/students.js'; import { ClassDTO } from '../interfaces/class.js'; import { getAllAssignments } from '../services/assignments.js'; -import { - getUserHandler, -} from './users.js'; +import { getUserHandler } from './users.js'; import { Student } from '../entities/users/student.entity.js'; import { StudentDTO } from '../interfaces/student.js'; import { getStudentRepository } from '../data/repositories.js'; @@ -20,17 +18,12 @@ import { UserDTO } from '../interfaces/user.js'; // TODO: accept arguments (full, ...) // TODO: endpoints -export async function getAllStudentsHandler( - req: Request, - res: Response, -): Promise { +export async function getAllStudentsHandler(req: Request, res: Response): Promise { const full = req.query.full === 'true'; const studentRepository = getStudentRepository(); - const students: StudentDTO[] | string[] = full - ? await getAllStudents() - : await getAllStudents(); + const students: StudentDTO[] | string[] = full ? await getAllStudents() : await getAllStudents(); if (!students) { res.status(404).json({ error: `Student not found.` }); @@ -40,11 +33,7 @@ export async function getAllStudentsHandler( res.status(201).json(students); } - -export async function getStudentHandler( - req: Request, - res: Response, -): Promise { +export async function getStudentHandler(req: Request, res: Response): Promise { const username = req.params.username; if (!username) { @@ -64,10 +53,7 @@ export async function getStudentHandler( res.status(201).json(user); } -export async function createStudentHandler( - req: Request, - res: Response, -) { +export async function createStudentHandler(req: Request, res: Response) { const userData = req.body as StudentDTO; if (!userData.username || !userData.firstName || !userData.lastName) { @@ -81,10 +67,7 @@ export async function createStudentHandler( res.status(201).json(newUser); } -export async function deleteStudentHandler( - req: Request, - res: Response, -) { +export async function deleteStudentHandler(req: Request, res: Response) { const username = req.params.username; if (!username) { @@ -103,10 +86,7 @@ export async function deleteStudentHandler( res.status(200).json(deletedUser); } -export async function getStudentClassesHandler( - req: Request, - res: Response -): Promise { +export async function getStudentClassesHandler(req: Request, res: Response): Promise { try { const full = req.query.full === 'true'; const username = req.params.id; @@ -132,10 +112,7 @@ export async function getStudentClassesHandler( // Might not be fully correct depending on if // A class has an assignment, that all students // Have this assignment. -export async function getStudentAssignmentsHandler( - req: Request, - res: Response -): Promise { +export async function getStudentAssignmentsHandler(req: Request, res: Response): Promise { const full = req.query.full === 'true'; const username = req.params.id; @@ -146,24 +123,18 @@ export async function getStudentAssignmentsHandler( }); } -export async function getStudentGroupsHandler( - req: Request, - res: Response, -): Promise { +export async function getStudentGroupsHandler(req: Request, res: Response): Promise { const full = req.query.full === 'true'; const username = req.params.id; const groups = await getStudentGroups(username, full); - + res.json({ groups: groups, }); } -export async function getStudentSubmissionsHandler( - req: Request, - res: Response, -): Promise { +export async function getStudentSubmissionsHandler(req: Request, res: Response): Promise { const username = req.params.id; const submissions = await getStudentSubmissions(username); @@ -175,4 +146,3 @@ export async function getStudentSubmissionsHandler( function getAllStudents(): StudentDTO[] | string[] | PromiseLike { throw new Error('Function not implemented.'); } - diff --git a/backend/src/controllers/submissions.ts b/backend/src/controllers/submissions.ts index 96f0185c..1e66dbe9 100644 --- a/backend/src/controllers/submissions.ts +++ b/backend/src/controllers/submissions.ts @@ -1,17 +1,14 @@ -import { Request, Response } from "express"; -import {createSubmission, deleteSubmission, getSubmission} from "../services/submissions.js"; -import { Language, languageMap } from "../entities/content/language.js"; -import {SubmissionDTO} from "../interfaces/submission"; +import { Request, Response } from 'express'; +import { createSubmission, deleteSubmission, getSubmission } from '../services/submissions.js'; +import { Language, languageMap } from '../entities/content/language.js'; +import { SubmissionDTO } from '../interfaces/submission'; interface SubmissionParams { - hruid: string, + hruid: string; id: number; } -export async function getSubmissionHandler( - req: Request, - res: Response, -): Promise { +export async function getSubmissionHandler(req: Request, res: Response): Promise { const lohruid = req.params.hruid; const submissionNumber = +req.params.id; @@ -33,18 +30,19 @@ export async function getSubmissionHandler( res.json(submission); } -export async function createSubmissionHandler(req: Request, res: Response){ +export async function createSubmissionHandler(req: Request, res: Response) { const submissionDTO = req.body as SubmissionDTO; const submission = await createSubmission(submissionDTO); - if (!submission) - {res.status(404).json({ error: 'Submission not added' });} - else - {res.json(submission)} + if (!submission) { + res.status(404).json({ error: 'Submission not added' }); + } else { + res.json(submission); + } } -export async function deleteSubmissionHandler(req: Request, res: Response){ +export async function deleteSubmissionHandler(req: Request, res: Response) { const hruid = req.params.hruid; const submissionNumber = +req.params.id; @@ -53,8 +51,9 @@ export async function deleteSubmissionHandler(req: Request, res: Response){ const submission = await deleteSubmission(hruid, lang, version, submissionNumber); - if (!submission) - {res.status(404).json({ error: 'Submission not found' });} - else - {res.json(submission)} + if (!submission) { + res.status(404).json({ error: 'Submission not found' }); + } else { + res.json(submission); + } } diff --git a/backend/src/controllers/teachers.ts b/backend/src/controllers/teachers.ts index 02846fd9..52e5e713 100644 --- a/backend/src/controllers/teachers.ts +++ b/backend/src/controllers/teachers.ts @@ -1,5 +1,16 @@ import { Request, Response } from 'express'; -import { createTeacher, deleteTeacher, getAllTeachers, getClassesByTeacher, getClassIdsByTeacher, getQuestionIdsByTeacher, getQuestionsByTeacher, getStudentIdsByTeacher, getStudentsByTeacher, getTeacher } from '../services/teachers.js'; +import { + createTeacher, + deleteTeacher, + getAllTeachers, + getClassesByTeacher, + getClassIdsByTeacher, + getQuestionIdsByTeacher, + getQuestionsByTeacher, + getStudentIdsByTeacher, + getStudentsByTeacher, + getTeacher, +} from '../services/teachers.js'; import { ClassDTO } from '../interfaces/class.js'; import { StudentDTO } from '../interfaces/student.js'; import { QuestionDTO, QuestionId } from '../interfaces/question.js'; @@ -7,17 +18,12 @@ import { Teacher } from '../entities/users/teacher.entity.js'; import { TeacherDTO } from '../interfaces/teacher.js'; import { getTeacherRepository } from '../data/repositories.js'; -export async function getAllTeachersHandler( - req: Request, - res: Response, -): Promise { +export async function getAllTeachersHandler(req: Request, res: Response): Promise { const full = req.query.full === 'true'; const teacherRepository = getTeacherRepository(); - const teachers: TeacherDTO[] | string[] = full - ? await getAllTeachers() - : await getAllTeachers(); + const teachers: TeacherDTO[] | string[] = full ? await getAllTeachers() : await getAllTeachers(); if (!teachers) { res.status(404).json({ error: `Teacher not found.` }); @@ -27,11 +33,7 @@ export async function getAllTeachersHandler( res.status(201).json(teachers); } - -export async function getTeacherHandler( - req: Request, - res: Response, -): Promise { +export async function getTeacherHandler(req: Request, res: Response): Promise { const username = req.params.username; if (!username) { @@ -51,10 +53,7 @@ export async function getTeacherHandler( res.status(201).json(user); } -export async function createTeacherHandler( - req: Request, - res: Response, -) { +export async function createTeacherHandler(req: Request, res: Response) { const userData = req.body as TeacherDTO; if (!userData.username || !userData.firstName || !userData.lastName) { @@ -68,10 +67,7 @@ export async function createTeacherHandler( res.status(201).json(newUser); } -export async function deleteTeacherHandler( - req: Request, - res: Response, -) { +export async function deleteTeacherHandler(req: Request, res: Response) { const username = req.params.username; if (!username) { @@ -90,11 +86,7 @@ export async function deleteTeacherHandler( res.status(200).json(deletedUser); } - -export async function getTeacherClassHandler( - req: Request, - res: Response -): Promise { +export async function getTeacherClassHandler(req: Request, res: Response): Promise { try { const username = req.params.username as string; const full = req.query.full === 'true'; @@ -104,9 +96,7 @@ export async function getTeacherClassHandler( return; } - const classes: ClassDTO[] | string[] = full - ? await getClassesByTeacher(username) - : await getClassIdsByTeacher(username); + const classes: ClassDTO[] | string[] = full ? await getClassesByTeacher(username) : await getClassIdsByTeacher(username); res.status(201).json(classes); } catch (error) { @@ -115,10 +105,7 @@ export async function getTeacherClassHandler( } } -export async function getTeacherStudentHandler( - req: Request, - res: Response -): Promise { +export async function getTeacherStudentHandler(req: Request, res: Response): Promise { try { const username = req.params.username as string; const full = req.query.full === 'true'; @@ -128,9 +115,7 @@ export async function getTeacherStudentHandler( return; } - const students: StudentDTO[] | string[] = full - ? await getStudentsByTeacher(username) - : await getStudentIdsByTeacher(username); + const students: StudentDTO[] | string[] = full ? await getStudentsByTeacher(username) : await getStudentIdsByTeacher(username); res.status(201).json(students); } catch (error) { @@ -139,10 +124,7 @@ export async function getTeacherStudentHandler( } } -export async function getTeacherQuestionHandler( - req: Request, - res: Response -): Promise { +export async function getTeacherQuestionHandler(req: Request, res: Response): Promise { try { const username = req.params.username as string; const full = req.query.full === 'true'; @@ -152,9 +134,7 @@ export async function getTeacherQuestionHandler( return; } - const questions: QuestionDTO[] | QuestionId[] = full - ? await getQuestionsByTeacher(username) - : await getQuestionIdsByTeacher(username); + const questions: QuestionDTO[] | QuestionId[] = full ? await getQuestionsByTeacher(username) : await getQuestionIdsByTeacher(username); res.status(201).json(questions); } catch (error) { diff --git a/backend/src/controllers/users.ts b/backend/src/controllers/users.ts index 8b256a0e..850c6549 100644 --- a/backend/src/controllers/users.ts +++ b/backend/src/controllers/users.ts @@ -3,17 +3,11 @@ import { UserService } from '../services/users.js'; import { UserDTO } from '../interfaces/user.js'; import { User } from '../entities/users/user.entity.js'; -export async function getAllUsersHandler( - req: Request, - res: Response, - service: UserService -): Promise { +export async function getAllUsersHandler(req: Request, res: Response, service: UserService): Promise { try { const full = req.query.full === 'true'; - const users: UserDTO[] | string[] = full - ? await service.getAllUsers() - : await service.getAllUserIds(); + const users: UserDTO[] | string[] = full ? await service.getAllUsers() : await service.getAllUserIds(); if (!users) { res.status(404).json({ error: `Users not found.` }); @@ -27,11 +21,7 @@ export async function getAllUsersHandler( } } -export async function getUserHandler( - req: Request, - res: Response, - service: UserService -): Promise { +export async function getUserHandler(req: Request, res: Response, service: UserService): Promise { try { const username = req.params.username as string; @@ -56,12 +46,7 @@ export async function getUserHandler( } } -export async function createUserHandler( - req: Request, - res: Response, - service: UserService, - UserClass: new () => T -) { +export async function createUserHandler(req: Request, res: Response, service: UserService, UserClass: new () => T) { try { console.log('req', req); const userData = req.body as UserDTO; @@ -81,11 +66,7 @@ export async function createUserHandler( } } -export async function deleteUserHandler( - req: Request, - res: Response, - service: UserService -) { +export async function deleteUserHandler(req: Request, res: Response, service: UserService) { try { const username = req.params.username; diff --git a/backend/src/data/assignments/group-repository.ts b/backend/src/data/assignments/group-repository.ts index 56736787..eb1b09e2 100644 --- a/backend/src/data/assignments/group-repository.ts +++ b/backend/src/data/assignments/group-repository.ts @@ -4,10 +4,7 @@ import { Assignment } from '../../entities/assignments/assignment.entity.js'; import { Student } from '../../entities/users/student.entity.js'; export class GroupRepository extends DwengoEntityRepository { - public findByAssignmentAndGroupNumber( - assignment: Assignment, - groupNumber: number - ): Promise { + public findByAssignmentAndGroupNumber(assignment: Assignment, groupNumber: number): Promise { return this.findOne( { assignment: assignment, @@ -16,26 +13,16 @@ export class GroupRepository extends DwengoEntityRepository { { populate: ['members'] } ); } - public findAllGroupsForAssignment( - assignment: Assignment - ): Promise { + public findAllGroupsForAssignment(assignment: Assignment): Promise { return this.findAll({ where: { assignment: assignment }, populate: ['members'], }); } - public findAllGroupsWithStudent( - student: Student - ): Promise { - return this.find( - { members: student }, - { populate: ['members'] } - ) + public findAllGroupsWithStudent(student: Student): Promise { + return this.find({ members: student }, { populate: ['members'] }); } - public deleteByAssignmentAndGroupNumber( - assignment: Assignment, - groupNumber: number - ) { + public deleteByAssignmentAndGroupNumber(assignment: Assignment, groupNumber: number) { return this.deleteWhere({ assignment: assignment, groupNumber: groupNumber, diff --git a/backend/src/data/assignments/submission-repository.ts b/backend/src/data/assignments/submission-repository.ts index 6ec1217f..251823fa 100644 --- a/backend/src/data/assignments/submission-repository.ts +++ b/backend/src/data/assignments/submission-repository.ts @@ -5,10 +5,7 @@ import { LearningObjectIdentifier } from '../../entities/content/learning-object import { Student } from '../../entities/users/student.entity.js'; export class SubmissionRepository extends DwengoEntityRepository { - public findSubmissionByLearningObjectAndSubmissionNumber( - loId: LearningObjectIdentifier, - submissionNumber: number - ): Promise { + public findSubmissionByLearningObjectAndSubmissionNumber(loId: LearningObjectIdentifier, submissionNumber: number): Promise { return this.findOne({ learningObjectHruid: loId.hruid, learningObjectLanguage: loId.language, @@ -17,10 +14,7 @@ export class SubmissionRepository extends DwengoEntityRepository { }); } - public findMostRecentSubmissionForStudent( - loId: LearningObjectIdentifier, - submitter: Student - ): Promise { + public findMostRecentSubmissionForStudent(loId: LearningObjectIdentifier, submitter: Student): Promise { return this.findOne( { learningObjectHruid: loId.hruid, @@ -32,10 +26,7 @@ export class SubmissionRepository extends DwengoEntityRepository { ); } - public findMostRecentSubmissionForGroup( - loId: LearningObjectIdentifier, - group: Group - ): Promise { + public findMostRecentSubmissionForGroup(loId: LearningObjectIdentifier, group: Group): Promise { return this.findOne( { learningObjectHruid: loId.hruid, @@ -47,26 +38,15 @@ export class SubmissionRepository extends DwengoEntityRepository { ); } - public findAllSubmissionsForGroup( - group: Group, - ): Promise { - return this.find( - { onBehalfOf: group }, - ); + public findAllSubmissionsForGroup(group: Group): Promise { + return this.find({ onBehalfOf: group }); } - public findAllSubmissionsForStudent( - student: Student, - ): Promise { - return this.find( - { submitter: student }, - ); + public findAllSubmissionsForStudent(student: Student): Promise { + return this.find({ submitter: student }); } - public deleteSubmissionByLearningObjectAndSubmissionNumber( - loId: LearningObjectIdentifier, - submissionNumber: number - ): Promise { + public deleteSubmissionByLearningObjectAndSubmissionNumber(loId: LearningObjectIdentifier, submissionNumber: number): Promise { return this.deleteWhere({ learningObjectHruid: loId.hruid, learningObjectLanguage: loId.language, diff --git a/backend/src/data/classes/class-repository.ts b/backend/src/data/classes/class-repository.ts index 4f2f5b0e..0ceed98e 100644 --- a/backend/src/data/classes/class-repository.ts +++ b/backend/src/data/classes/class-repository.ts @@ -5,10 +5,7 @@ import { Teacher } from '../../entities/users/teacher.entity'; export class ClassRepository extends DwengoEntityRepository { public findById(id: string): Promise { - return this.findOne( - { classId: id }, - { populate: ['students', 'teachers'] } - ); + return this.findOne({ classId: id }, { populate: ['students', 'teachers'] }); } public deleteById(id: string): Promise { return this.deleteWhere({ classId: id }); @@ -21,9 +18,6 @@ export class ClassRepository extends DwengoEntityRepository { } public findByTeacher(teacher: Teacher): Promise { - return this.find( - { teachers: teacher }, - { populate: ['students', 'teachers'] } - ); + return this.find({ teachers: teacher }, { populate: ['students', 'teachers'] }); } } diff --git a/backend/src/data/questions/answer-repository.ts b/backend/src/data/questions/answer-repository.ts index 0e20e479..a28342bd 100644 --- a/backend/src/data/questions/answer-repository.ts +++ b/backend/src/data/questions/answer-repository.ts @@ -19,10 +19,7 @@ export class AnswerRepository extends DwengoEntityRepository { orderBy: { sequenceNumber: 'ASC' }, }); } - public removeAnswerByQuestionAndSequenceNumber( - question: Question, - sequenceNumber: number - ): Promise { + public removeAnswerByQuestionAndSequenceNumber(question: Question, sequenceNumber: number): Promise { return this.deleteWhere({ toQuestion: question, sequenceNumber: sequenceNumber, diff --git a/backend/src/data/questions/question-repository.ts b/backend/src/data/questions/question-repository.ts index e24d48b8..9207e1dd 100644 --- a/backend/src/data/questions/question-repository.ts +++ b/backend/src/data/questions/question-repository.ts @@ -21,9 +21,7 @@ export class QuestionRepository extends DwengoEntityRepository { questionEntity.content = question.content; return this.insert(questionEntity); } - public findAllQuestionsAboutLearningObject( - loId: LearningObjectIdentifier - ): Promise { + public findAllQuestionsAboutLearningObject(loId: LearningObjectIdentifier): Promise { return this.findAll({ where: { learningObjectHruid: loId.hruid, @@ -35,10 +33,7 @@ export class QuestionRepository extends DwengoEntityRepository { }, }); } - public removeQuestionByLearningObjectAndSequenceNumber( - loId: LearningObjectIdentifier, - sequenceNumber: number - ): Promise { + public removeQuestionByLearningObjectAndSequenceNumber(loId: LearningObjectIdentifier, sequenceNumber: number): Promise { return this.deleteWhere({ learningObjectHruid: loId.hruid, learningObjectLanguage: loId.language, @@ -47,14 +42,12 @@ export class QuestionRepository extends DwengoEntityRepository { }); } - public async findAllByLearningObjects( - learningObjects: LearningObject[] - ): Promise { + public async findAllByLearningObjects(learningObjects: LearningObject[]): Promise { const objectIdentifiers = learningObjects.map((lo) => ({ - learningObjectHruid: lo.hruid, - learningObjectLanguage: lo.language, - learningObjectVersion: lo.version, - })); + learningObjectHruid: lo.hruid, + learningObjectLanguage: lo.language, + learningObjectVersion: lo.version, + })); return this.findAll({ where: { $or: objectIdentifiers }, diff --git a/backend/src/data/repositories.ts b/backend/src/data/repositories.ts index 0c091aa9..02385109 100644 --- a/backend/src/data/repositories.ts +++ b/backend/src/data/repositories.ts @@ -40,9 +40,7 @@ export function transactional(f: () => Promise) { entityManager?.transactional(f); } -function repositoryGetter>( - entity: EntityName -): () => R { +function repositoryGetter>(entity: EntityName): () => R { let cachedRepo: R | undefined; return (): R => { if (!cachedRepo) { diff --git a/backend/src/data/users/student-repository.ts b/backend/src/data/users/student-repository.ts index f3cf7b6a..0792678d 100644 --- a/backend/src/data/users/student-repository.ts +++ b/backend/src/data/users/student-repository.ts @@ -12,4 +12,4 @@ export class StudentRepository extends DwengoEntityRepository { public deleteByUsername(username: string): Promise { return this.deleteWhere({ username: username }); } -} \ No newline at end of file +} diff --git a/backend/src/data/users/teacher-repository.ts b/backend/src/data/users/teacher-repository.ts index 23ba559e..2b2bee75 100644 --- a/backend/src/data/users/teacher-repository.ts +++ b/backend/src/data/users/teacher-repository.ts @@ -9,4 +9,4 @@ export class TeacherRepository extends DwengoEntityRepository { public deleteByUsername(username: string): Promise { return this.deleteWhere({ username: username }); } -} \ No newline at end of file +} diff --git a/backend/src/entities/assignments/assignment.entity.ts b/backend/src/entities/assignments/assignment.entity.ts index a1f53386..692e2112 100644 --- a/backend/src/entities/assignments/assignment.entity.ts +++ b/backend/src/entities/assignments/assignment.entity.ts @@ -1,12 +1,4 @@ -import { - Collection, - Entity, - Enum, - ManyToOne, - OneToMany, - PrimaryKey, - Property, -} from '@mikro-orm/core'; +import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'; import { Class } from '../classes/class.entity.js'; import { Group } from './group.entity.js'; import { Language } from '../content/language.js'; diff --git a/backend/src/entities/classes/class.entity.ts b/backend/src/entities/classes/class.entity.ts index a484deff..63315304 100644 --- a/backend/src/entities/classes/class.entity.ts +++ b/backend/src/entities/classes/class.entity.ts @@ -1,10 +1,4 @@ -import { - Collection, - Entity, - ManyToMany, - PrimaryKey, - Property, -} from '@mikro-orm/core'; +import { Collection, Entity, ManyToMany, PrimaryKey, Property } from '@mikro-orm/core'; import { v4 } from 'uuid'; import { Teacher } from '../users/teacher.entity.js'; import { Student } from '../users/student.entity.js'; diff --git a/backend/src/entities/content/language.ts b/backend/src/entities/content/language.ts index 40a00919..7e7b42d2 100644 --- a/backend/src/entities/content/language.ts +++ b/backend/src/entities/content/language.ts @@ -190,4 +190,4 @@ export const languageMap: Record = { fr: Language.French, en: Language.English, de: Language.German, -}; \ No newline at end of file +}; diff --git a/backend/src/entities/content/learning-object.entity.ts b/backend/src/entities/content/learning-object.entity.ts index 4a3641bb..9eda22ba 100644 --- a/backend/src/entities/content/learning-object.entity.ts +++ b/backend/src/entities/content/learning-object.entity.ts @@ -1,13 +1,4 @@ -import { - Embeddable, - Embedded, - Entity, - Enum, - ManyToMany, - OneToMany, - PrimaryKey, - Property, -} from '@mikro-orm/core'; +import { Embeddable, Embedded, Entity, Enum, ManyToMany, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'; import { Language } from './language.js'; import { Attachment } from './attachment.entity.js'; import { Teacher } from '../users/teacher.entity.js'; diff --git a/backend/src/interfaces/answer.ts b/backend/src/interfaces/answer.ts index 0b86a4d1..493fd3c0 100644 --- a/backend/src/interfaces/answer.ts +++ b/backend/src/interfaces/answer.ts @@ -1,6 +1,6 @@ -import {mapToUserDTO, UserDTO} from "./user.js"; -import {mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId} from "./question.js"; -import {Answer} from "../entities/questions/answer.entity.js"; +import { mapToUserDTO, UserDTO } from './user.js'; +import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from './question.js'; +import { Answer } from '../entities/questions/answer.entity.js'; export interface AnswerDTO { author: UserDTO; @@ -33,6 +33,6 @@ export function mapToAnswerId(answer: AnswerDTO): AnswerId { return { author: answer.author.username, toQuestion: mapToQuestionId(answer.toQuestion), - sequenceNumber: answer.sequenceNumber - } + sequenceNumber: answer.sequenceNumber, + }; } diff --git a/backend/src/interfaces/class.ts b/backend/src/interfaces/class.ts index e04ce2d4..371e3cae 100644 --- a/backend/src/interfaces/class.ts +++ b/backend/src/interfaces/class.ts @@ -27,15 +27,11 @@ export function mapToClassDTO(cls: Class): ClassDTO { }; } -export function mapToClass( - classData: ClassDTO, - students: Collection, - teachers: Collection -): Class { +export function mapToClass(classData: ClassDTO, students: Collection, teachers: Collection): Class { const cls = new Class(); cls.displayName = classData.displayName; cls.students = students; cls.teachers = teachers; - + return cls; } diff --git a/backend/src/interfaces/question.ts b/backend/src/interfaces/question.ts index 69039ee9..8cca42f6 100644 --- a/backend/src/interfaces/question.ts +++ b/backend/src/interfaces/question.ts @@ -1,6 +1,6 @@ import { Question } from '../entities/questions/question.entity.js'; -import {UserDTO} from "./user.js"; -import {LearningObjectIdentifier} from "../entities/content/learning-object-identifier.js"; +import { UserDTO } from './user.js'; +import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; import { mapToStudentDTO, StudentDTO } from './student.js'; import { TeacherDTO } from './teacher.js'; @@ -19,8 +19,8 @@ export function mapToQuestionDTO(question: Question): QuestionDTO { const learningObjectIdentifier = { hruid: question.learningObjectHruid, language: question.learningObjectLanguage, - version: question.learningObjectVersion - } + version: question.learningObjectVersion, + }; return { learningObjectIdentifier, @@ -42,4 +42,3 @@ export function mapToQuestionId(question: QuestionDTO): QuestionId { sequenceNumber: question.sequenceNumber!, }; } - diff --git a/backend/src/interfaces/student.ts b/backend/src/interfaces/student.ts index 9790eb35..079b355b 100644 --- a/backend/src/interfaces/student.ts +++ b/backend/src/interfaces/student.ts @@ -23,11 +23,7 @@ export function mapToStudentDTO(student: Student): StudentDTO { } export function mapToStudent(studentData: StudentDTO): Student { - const student = new Student( - studentData.username, - studentData.firstName, - studentData.lastName, - ); + const student = new Student(studentData.username, studentData.firstName, studentData.lastName); return student; } diff --git a/backend/src/interfaces/submission.ts b/backend/src/interfaces/submission.ts index 40b76fad..fbaf520d 100644 --- a/backend/src/interfaces/submission.ts +++ b/backend/src/interfaces/submission.ts @@ -1,20 +1,20 @@ -import { Submission } from "../entities/assignments/submission.entity.js"; -import { Language } from "../entities/content/language.js"; -import { GroupDTO, mapToGroupDTO } from "./group.js"; -import {mapToStudent, mapToStudentDTO, StudentDTO} from "./student.js"; -import {mapToUser} from "./user"; -import {Student} from "../entities/users/student.entity"; +import { Submission } from '../entities/assignments/submission.entity.js'; +import { Language } from '../entities/content/language.js'; +import { GroupDTO, mapToGroupDTO } from './group.js'; +import { mapToStudent, mapToStudentDTO, StudentDTO } from './student.js'; +import { mapToUser } from './user'; +import { Student } from '../entities/users/student.entity'; export interface SubmissionDTO { - learningObjectHruid: string, - learningObjectLanguage: Language, - learningObjectVersion: number, + learningObjectHruid: string; + learningObjectLanguage: Language; + learningObjectVersion: number; - submissionNumber?: number, - submitter: StudentDTO, - time?: Date, - group?: GroupDTO, - content: string, + submissionNumber?: number; + submitter: StudentDTO; + time?: Date; + group?: GroupDTO; + content: string; } export function mapToSubmissionDTO(submission: Submission): SubmissionDTO { @@ -28,7 +28,7 @@ export function mapToSubmissionDTO(submission: Submission): SubmissionDTO { time: submission.submissionTime, group: submission.onBehalfOf ? mapToGroupDTO(submission.onBehalfOf) : undefined, content: submission.content, - } + }; } export function mapToSubmission(submissionDTO: SubmissionDTO): Submission { @@ -37,7 +37,7 @@ export function mapToSubmission(submissionDTO: SubmissionDTO): Submission { submission.learningObjectLanguage = submissionDTO.learningObjectLanguage; submission.learningObjectVersion = submissionDTO.learningObjectVersion; // Submission.submissionNumber = submissionDTO.submissionNumber; - submission.submitter = mapToStudent(submissionDTO.submitter) ; + submission.submitter = mapToStudent(submissionDTO.submitter); // Submission.submissionTime = submissionDTO.time; // Submission.onBehalfOf = submissionDTO.group!; // TODO fix group diff --git a/backend/src/interfaces/teacher-invitation.ts b/backend/src/interfaces/teacher-invitation.ts index d29e7476..cddef566 100644 --- a/backend/src/interfaces/teacher-invitation.ts +++ b/backend/src/interfaces/teacher-invitation.ts @@ -8,9 +8,7 @@ export interface TeacherInvitationDTO { class: string | ClassDTO; } -export function mapToTeacherInvitationDTO( - invitation: TeacherInvitation -): TeacherInvitationDTO { +export function mapToTeacherInvitationDTO(invitation: TeacherInvitation): TeacherInvitationDTO { return { sender: mapToUserDTO(invitation.sender), receiver: mapToUserDTO(invitation.receiver), @@ -18,9 +16,7 @@ export function mapToTeacherInvitationDTO( }; } -export function mapToTeacherInvitationDTOIds( - invitation: TeacherInvitation -): TeacherInvitationDTO { +export function mapToTeacherInvitationDTOIds(invitation: TeacherInvitation): TeacherInvitationDTO { return { sender: invitation.sender.username, receiver: invitation.receiver.username, diff --git a/backend/src/interfaces/teacher.ts b/backend/src/interfaces/teacher.ts index 93dbf5fd..4dd6adb4 100644 --- a/backend/src/interfaces/teacher.ts +++ b/backend/src/interfaces/teacher.ts @@ -23,11 +23,7 @@ export function mapToTeacherDTO(teacher: Teacher): TeacherDTO { } export function mapToTeacher(TeacherData: TeacherDTO): Teacher { - const teacher = new Teacher( - TeacherData.username, - TeacherData.firstName, - TeacherData.lastName, - ); + const teacher = new Teacher(TeacherData.username, TeacherData.firstName, TeacherData.lastName); return teacher; } diff --git a/backend/src/interfaces/user.ts b/backend/src/interfaces/user.ts index 64081d48..58f0dd5a 100644 --- a/backend/src/interfaces/user.ts +++ b/backend/src/interfaces/user.ts @@ -22,10 +22,7 @@ export function mapToUserDTO(user: User): UserDTO { }; } -export function mapToUser( - userData: UserDTO, - userInstance: T -): T { +export function mapToUser(userData: UserDTO, userInstance: T): T { userInstance.username = userData.username; userInstance.firstName = userData.firstName; userInstance.lastName = userData.lastName; diff --git a/backend/src/routes/learning-objects.ts b/backend/src/routes/learning-objects.ts index 45e0df4c..7532765b 100644 --- a/backend/src/routes/learning-objects.ts +++ b/backend/src/routes/learning-objects.ts @@ -1,15 +1,9 @@ import express from 'express'; -import { - getAllLearningObjects, - getAttachment, - getLearningObject, - getLearningObjectHTML, -} from '../controllers/learning-objects.js'; +import { getAllLearningObjects, getAttachment, getLearningObject, getLearningObjectHTML } from '../controllers/learning-objects.js'; import submissionRoutes from './submissions.js'; import questionRoutes from './questions.js'; - const router = express.Router(); // DWENGO learning objects @@ -32,7 +26,7 @@ router.get('/:hruid', getLearningObject); router.use('/:hruid/submissions', submissionRoutes); -router.use('/:hruid/:version/questions', questionRoutes) +router.use('/:hruid/:version/questions', questionRoutes); // Parameter: hruid of learning object // Query: language, version (optional) diff --git a/backend/src/routes/questions.ts b/backend/src/routes/questions.ts index d9a4dd9d..31a71f3b 100644 --- a/backend/src/routes/questions.ts +++ b/backend/src/routes/questions.ts @@ -1,10 +1,11 @@ import express from 'express'; import { - createQuestionHandler, deleteQuestionHandler, + createQuestionHandler, + deleteQuestionHandler, getAllQuestionsHandler, getQuestionAnswersHandler, - getQuestionHandler -} from "../controllers/questions.js"; + getQuestionHandler, +} from '../controllers/questions.js'; const router = express.Router({ mergeParams: true }); // Query language diff --git a/backend/src/routes/submissions.ts b/backend/src/routes/submissions.ts index e431260f..4db93027 100644 --- a/backend/src/routes/submissions.ts +++ b/backend/src/routes/submissions.ts @@ -1,9 +1,7 @@ import express from 'express'; -import {createSubmissionHandler, deleteSubmissionHandler, getSubmissionHandler} from '../controllers/submissions.js'; +import { createSubmissionHandler, deleteSubmissionHandler, getSubmissionHandler } from '../controllers/submissions.js'; const router = express.Router({ mergeParams: true }); - - // Root endpoint used to search objects router.get('/', (req, res) => { res.json({ diff --git a/backend/src/services/assignments.ts b/backend/src/services/assignments.ts index e67c2c0c..be121810 100644 --- a/backend/src/services/assignments.ts +++ b/backend/src/services/assignments.ts @@ -1,22 +1,9 @@ -import { - getAssignmentRepository, - getClassRepository, - getGroupRepository, - getSubmissionRepository, -} from '../data/repositories.js'; +import { getAssignmentRepository, getClassRepository, getGroupRepository, getSubmissionRepository } from '../data/repositories.js'; import { Assignment } from '../entities/assignments/assignment.entity.js'; -import { - AssignmentDTO, - mapToAssignment, - mapToAssignmentDTO, - mapToAssignmentDTOId, -} from '../interfaces/assignment.js'; +import { AssignmentDTO, mapToAssignment, mapToAssignmentDTO, mapToAssignmentDTOId } from '../interfaces/assignment.js'; import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js'; -export async function getAllAssignments( - classid: string, - full: boolean -): Promise { +export async function getAllAssignments(classid: string, full: boolean): Promise { const classRepository = getClassRepository(); const cls = await classRepository.findById(classid); @@ -25,8 +12,7 @@ export async function getAllAssignments( } const assignmentRepository = getAssignmentRepository(); - const assignments = - await assignmentRepository.findAllAssignmentsInClass(cls); + const assignments = await assignmentRepository.findAllAssignmentsInClass(cls); if (full) { return assignments.map(mapToAssignmentDTO); @@ -35,14 +21,11 @@ export async function getAllAssignments( return assignments.map(mapToAssignmentDTOId); } -export async function createAssignment( - classid: string, - assignmentData: AssignmentDTO, -): Promise { +export async function createAssignment(classid: string, assignmentData: AssignmentDTO): Promise { const classRepository = getClassRepository(); const cls = await classRepository.findById(classid); - if (!cls) { + if (!cls) { return null; } @@ -54,16 +37,12 @@ export async function createAssignment( await assignmentRepository.save(newAssignment); return newAssignment; - } catch(e) { + } catch (e) { return null; } - } -export async function getAssignment( - classid: string, - id: number -): Promise { +export async function getAssignment(classid: string, id: number): Promise { const classRepository = getClassRepository(); const cls = await classRepository.findById(classid); @@ -81,10 +60,7 @@ export async function getAssignment( return mapToAssignmentDTO(assignment); } -export async function getAssignmentsSubmissions( - classid: string, - assignmentNumber: number, -): Promise { +export async function getAssignmentsSubmissions(classid: string, assignmentNumber: number): Promise { const classRepository = getClassRepository(); const cls = await classRepository.findById(classid); @@ -103,8 +79,7 @@ export async function getAssignmentsSubmissions( const groups = await groupRepository.findAllGroupsForAssignment(assignment); const submissionRepository = getSubmissionRepository(); - const submissions = - (await Promise.all(groups.map(group => submissionRepository.findAllSubmissionsForGroup(group)))).flat(); + const submissions = (await Promise.all(groups.map((group) => submissionRepository.findAllSubmissionsForGroup(group)))).flat(); return submissions.map(mapToSubmissionDTO); -} \ No newline at end of file +} diff --git a/backend/src/services/class.ts b/backend/src/services/class.ts index 4b76d0cd..46530327 100644 --- a/backend/src/services/class.ts +++ b/backend/src/services/class.ts @@ -1,26 +1,12 @@ -import { - getClassRepository, - getStudentRepository, - getTeacherInvitationRepository, - getTeacherRepository, -} from '../data/repositories.js'; +import { getClassRepository, getStudentRepository, getTeacherInvitationRepository, getTeacherRepository } from '../data/repositories.js'; import { Class } from '../entities/classes/class.entity.js'; import { ClassDTO, mapToClassDTO } from '../interfaces/class.js'; import { mapToStudentDTO, StudentDTO } from '../interfaces/student.js'; -import { - mapToTeacherInvitationDTO, - mapToTeacherInvitationDTOIds, - TeacherInvitationDTO, -} from '../interfaces/teacher-invitation.js'; +import { mapToTeacherInvitationDTO, mapToTeacherInvitationDTOIds, TeacherInvitationDTO } from '../interfaces/teacher-invitation.js'; -export async function getAllClasses( - full: boolean -): Promise { +export async function getAllClasses(full: boolean): Promise { const classRepository = getClassRepository(); - const classes = await classRepository.find( - {}, - { populate: ['students', 'teachers'] } - ); + const classes = await classRepository.find({}, { populate: ['students', 'teachers'] }); if (!classes) { return []; @@ -35,13 +21,11 @@ export async function getAllClasses( export async function createClass(classData: ClassDTO): Promise { const teacherRepository = getTeacherRepository(); const teacherUsernames = classData.teachers || []; - const teachers = (await Promise.all(teacherUsernames.map(id => teacherRepository.findByUsername(id)))) - .filter(teacher => teacher != null); + const teachers = (await Promise.all(teacherUsernames.map((id) => teacherRepository.findByUsername(id)))).filter((teacher) => teacher != null); const studentRepository = getStudentRepository(); const studentUsernames = classData.students || []; - const students = (await Promise.all(studentUsernames.map(id => studentRepository.findByUsername(id)))) - .filter(student => student != null); + const students = (await Promise.all(studentUsernames.map((id) => studentRepository.findByUsername(id)))).filter((student) => student != null); //Const cls = mapToClass(classData, teachers, students); @@ -56,7 +40,7 @@ export async function createClass(classData: ClassDTO): Promise { await classRepository.save(newClass); return newClass; - } catch(e) { + } catch (e) { return null; } } @@ -92,10 +76,7 @@ export async function getClassStudentsIds(classId: string): Promise { return students.map((student) => student.username); } -export async function getClassTeacherInvitations( - classId: string, - full: boolean -): Promise { +export async function getClassTeacherInvitations(classId: string, full: boolean): Promise { const classRepository = getClassRepository(); const cls = await classRepository.findById(classId); @@ -104,8 +85,7 @@ export async function getClassTeacherInvitations( } const teacherInvitationRepository = getTeacherInvitationRepository(); - const invitations = - await teacherInvitationRepository.findAllInvitationsForClass(cls); + const invitations = await teacherInvitationRepository.findAllInvitationsForClass(cls); if (full) { return invitations.map(mapToTeacherInvitationDTO); diff --git a/backend/src/services/groups.ts b/backend/src/services/groups.ts index 2f2d0a14..91091703 100644 --- a/backend/src/services/groups.ts +++ b/backend/src/services/groups.ts @@ -7,19 +7,10 @@ import { getSubmissionRepository, } from '../data/repositories.js'; import { Group } from '../entities/assignments/group.entity.js'; -import { - GroupDTO, - mapToGroupDTO, - mapToGroupDTOId, -} from '../interfaces/group.js'; +import { GroupDTO, mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js'; import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js'; -export async function getGroup( - classId: string, - assignmentNumber: number, - groupNumber: number, - full: boolean -): Promise { +export async function getGroup(classId: string, assignmentNumber: number, groupNumber: number, full: boolean): Promise { const classRepository = getClassRepository(); const cls = await classRepository.findById(classId); @@ -28,20 +19,14 @@ export async function getGroup( } const assignmentRepository = getAssignmentRepository(); - const assignment = await assignmentRepository.findByClassAndId( - cls, - assignmentNumber - ); + const assignment = await assignmentRepository.findByClassAndId(cls, assignmentNumber); if (!assignment) { return null; } const groupRepository = getGroupRepository(); - const group = await groupRepository.findByAssignmentAndGroupNumber( - assignment, - groupNumber - ); + const group = await groupRepository.findByAssignmentAndGroupNumber(assignment, groupNumber); if (!group) { return null; @@ -54,16 +39,11 @@ export async function getGroup( return mapToGroupDTOId(group); } -export async function createGroup( - groupData: GroupDTO, - classid: string, - assignmentNumber: number, -): Promise { +export async function createGroup(groupData: GroupDTO, classid: string, assignmentNumber: number): Promise { const studentRepository = getStudentRepository(); - const memberUsernames = groupData.members as string[] || []; // TODO check if groupdata.members is a list - const members = (await Promise.all([...memberUsernames].map(id => studentRepository.findByUsername(id)))) - .filter(student => student != null); + const memberUsernames = (groupData.members as string[]) || []; // TODO check if groupdata.members is a list + const members = (await Promise.all([...memberUsernames].map((id) => studentRepository.findByUsername(id)))).filter((student) => student != null); console.log(members); @@ -90,17 +70,13 @@ export async function createGroup( await groupRepository.save(newGroup); return newGroup; - } catch(e) { + } catch (e) { console.log(e); return null; } } -export async function getAllGroups( - classId: string, - assignmentNumber: number, - full: boolean -): Promise { +export async function getAllGroups(classId: string, assignmentNumber: number, full: boolean): Promise { const classRepository = getClassRepository(); const cls = await classRepository.findById(classId); @@ -109,10 +85,7 @@ export async function getAllGroups( } const assignmentRepository = getAssignmentRepository(); - const assignment = await assignmentRepository.findByClassAndId( - cls, - assignmentNumber - ); + const assignment = await assignmentRepository.findByClassAndId(cls, assignmentNumber); if (!assignment) { return []; @@ -130,11 +103,7 @@ export async function getAllGroups( return groups.map(mapToGroupDTOId); } -export async function getGroupSubmissions( - classId: string, - assignmentNumber: number, - groupNumber: number, -): Promise { +export async function getGroupSubmissions(classId: string, assignmentNumber: number, groupNumber: number): Promise { const classRepository = getClassRepository(); const cls = await classRepository.findById(classId); @@ -143,20 +112,14 @@ export async function getGroupSubmissions( } const assignmentRepository = getAssignmentRepository(); - const assignment = await assignmentRepository.findByClassAndId( - cls, - assignmentNumber - ); + const assignment = await assignmentRepository.findByClassAndId(cls, assignmentNumber); if (!assignment) { return []; } const groupRepository = getGroupRepository(); - const group = await groupRepository.findByAssignmentAndGroupNumber( - assignment, - groupNumber - ); + const group = await groupRepository.findByAssignmentAndGroupNumber(assignment, groupNumber); if (!group) { return []; diff --git a/backend/src/services/learning-objects.ts b/backend/src/services/learning-objects.ts index dfde4da7..fb579471 100644 --- a/backend/src/services/learning-objects.ts +++ b/backend/src/services/learning-objects.ts @@ -1,16 +1,8 @@ import { DWENGO_API_BASE } from '../config.js'; import { fetchWithLogging } from '../util/api-helper.js'; -import { - FilteredLearningObject, - LearningObjectMetadata, - LearningObjectNode, - LearningPathResponse, -} from '../interfaces/learning-content.js'; +import { FilteredLearningObject, LearningObjectMetadata, LearningObjectNode, LearningPathResponse } from '../interfaces/learning-content.js'; -function filterData( - data: LearningObjectMetadata, - htmlUrl: string -): FilteredLearningObject { +function filterData(data: LearningObjectMetadata, htmlUrl: string): FilteredLearningObject { return { key: data.hruid, // Hruid learningObject (not path) _id: data._id, @@ -37,10 +29,7 @@ function filterData( /** * Fetches a single learning object by its HRUID */ -export async function getLearningObjectById( - hruid: string, - language: string -): Promise { +export async function getLearningObjectById(hruid: string, language: string): Promise { const metadataUrl = `${DWENGO_API_BASE}/learningObject/getMetadata?hruid=${hruid}&language=${language}`; const metadata = await fetchWithLogging( metadataUrl, @@ -59,26 +48,12 @@ export async function getLearningObjectById( /** * Generic function to fetch learning objects (full data or just HRUIDs) */ -async function fetchLearningObjects( - hruid: string, - full: boolean, - language: string -): Promise { +async function fetchLearningObjects(hruid: string, full: boolean, language: string): Promise { try { - const learningPathResponse: LearningPathResponse = - await fetchLearningPaths( - [hruid], - language, - `Learning path for HRUID "${hruid}"` - ); + const learningPathResponse: LearningPathResponse = await fetchLearningPaths([hruid], language, `Learning path for HRUID "${hruid}"`); - if ( - !learningPathResponse.success || - !learningPathResponse.data?.length - ) { - console.error( - `⚠️ WARNING: Learning path "${hruid}" exists but contains no learning objects.` - ); + if (!learningPathResponse.success || !learningPathResponse.data?.length) { + console.error(`⚠️ WARNING: Learning path "${hruid}" exists but contains no learning objects.`); return []; } @@ -88,12 +63,9 @@ async function fetchLearningObjects( return nodes.map((node) => node.learningobject_hruid); } - return await Promise.all( - nodes.map(async (node) => getLearningObjectById( - node.learningobject_hruid, - language - )) - ).then((objects) => objects.filter((obj): obj is FilteredLearningObject => obj !== null)); + return await Promise.all(nodes.map(async (node) => getLearningObjectById(node.learningobject_hruid, language))).then((objects) => + objects.filter((obj): obj is FilteredLearningObject => obj !== null) + ); } catch (error) { console.error('❌ Error fetching learning objects:', error); return []; @@ -103,27 +75,16 @@ async function fetchLearningObjects( /** * Fetch full learning object data (metadata) */ -export async function getLearningObjectsFromPath( - hruid: string, - language: string -): Promise { - return (await fetchLearningObjects( - hruid, - true, - language - )) as FilteredLearningObject[]; +export async function getLearningObjectsFromPath(hruid: string, language: string): Promise { + return (await fetchLearningObjects(hruid, true, language)) as FilteredLearningObject[]; } /** * Fetch only learning object HRUIDs */ -export async function getLearningObjectIdsFromPath( - hruid: string, - language: string -): Promise { +export async function getLearningObjectIdsFromPath(hruid: string, language: string): Promise { return (await fetchLearningObjects(hruid, false, language)) as string[]; } function fetchLearningPaths(arg0: string[], language: string, arg2: string): LearningPathResponse | PromiseLike { throw new Error('Function not implemented.'); } - diff --git a/backend/src/services/questions.ts b/backend/src/services/questions.ts index 238ebd45..ee003bcd 100644 --- a/backend/src/services/questions.ts +++ b/backend/src/services/questions.ts @@ -1,17 +1,15 @@ -import {getAnswerRepository, getQuestionRepository} from "../data/repositories.js"; -import {mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId} from "../interfaces/question.js"; -import {Question} from "../entities/questions/question.entity.js"; -import {Answer} from "../entities/questions/answer.entity.js"; -import {mapToAnswerDTO, mapToAnswerId} from "../interfaces/answer.js"; -import {QuestionRepository} from "../data/questions/question-repository.js"; -import {LearningObjectIdentifier} from "../entities/content/learning-object-identifier.js"; -import {mapToUser} from "../interfaces/user.js"; -import {Student} from "../entities/users/student.entity.js"; -import { mapToStudent } from "../interfaces/student.js"; +import { getAnswerRepository, getQuestionRepository } from '../data/repositories.js'; +import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js'; +import { Question } from '../entities/questions/question.entity.js'; +import { Answer } from '../entities/questions/answer.entity.js'; +import { mapToAnswerDTO, mapToAnswerId } from '../interfaces/answer.js'; +import { QuestionRepository } from '../data/questions/question-repository.js'; +import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; +import { mapToUser } from '../interfaces/user.js'; +import { Student } from '../entities/users/student.entity.js'; +import { mapToStudent } from '../interfaces/student.js'; -export async function getAllQuestions( - id: LearningObjectIdentifier, full: boolean -): Promise { +export async function getAllQuestions(id: LearningObjectIdentifier, full: boolean): Promise { const questionRepository: QuestionRepository = getQuestionRepository(); const questions = await questionRepository.findAllQuestionsAboutLearningObject(id); @@ -19,7 +17,7 @@ export async function getAllQuestions( return []; } - const questionsDTO: QuestionDTO[] = questions.map(mapToQuestionDTO); + const questionsDTO: QuestionDTO[] = questions.map(mapToQuestionDTO); if (full) { return questionsDTO; @@ -31,21 +29,20 @@ export async function getAllQuestions( async function fetchQuestion(questionId: QuestionId): Promise { const questionRepository = getQuestionRepository(); - return await questionRepository.findOne( - { - learningObjectHruid: questionId.learningObjectIdentifier.hruid, - learningObjectLanguage: questionId.learningObjectIdentifier.language, - learningObjectVersion: questionId.learningObjectIdentifier.version, - sequenceNumber: questionId.sequenceNumber - } - ) + return await questionRepository.findOne({ + learningObjectHruid: questionId.learningObjectIdentifier.hruid, + learningObjectLanguage: questionId.learningObjectIdentifier.language, + learningObjectVersion: questionId.learningObjectIdentifier.version, + sequenceNumber: questionId.sequenceNumber, + }); } export async function getQuestion(questionId: QuestionId): Promise { const question = await fetchQuestion(questionId); - if (!question) - {return null} + if (!question) { + return null; + } return mapToQuestionDTO(question); } @@ -54,18 +51,21 @@ export async function getAnswersByQuestion(questionId: QuestionId, full: boolean const answerRepository = getAnswerRepository(); const question = await fetchQuestion(questionId); - if (!question) - {return [];} + if (!question) { + return []; + } const answers: Answer[] = await answerRepository.findAllAnswersToQuestion(question); - if (!answers) - {return []} + if (!answers) { + return []; + } const answersDTO = answers.map(mapToAnswerDTO); - if (full) - {return answersDTO} + if (full) { + return answersDTO; + } return answersDTO.map(mapToAnswerId); } @@ -79,10 +79,10 @@ export async function createQuestion(questionDTO: QuestionDTO) { await questionRepository.createQuestion({ loId: questionDTO.learningObjectIdentifier, author, - content: questionDTO.content } - ); + content: questionDTO.content, + }); } catch (e) { - return null + return null; } return questionDTO; @@ -93,18 +93,15 @@ export async function deleteQuestion(questionId: QuestionId) { const question = await fetchQuestion(questionId); - if (!question) - {return null} - - try { - await questionRepository.removeQuestionByLearningObjectAndSequenceNumber( - questionId.learningObjectIdentifier, questionId.sequenceNumber - ); - } catch (e) { - return null + if (!question) { + return null; } - return question + try { + await questionRepository.removeQuestionByLearningObjectAndSequenceNumber(questionId.learningObjectIdentifier, questionId.sequenceNumber); + } catch (e) { + return null; + } + + return question; } - - diff --git a/backend/src/services/students.ts b/backend/src/services/students.ts index 3b677a10..5099a18d 100644 --- a/backend/src/services/students.ts +++ b/backend/src/services/students.ts @@ -1,9 +1,4 @@ -import { - getClassRepository, - getGroupRepository, - getStudentRepository, - getSubmissionRepository, -} from '../data/repositories.js'; +import { getClassRepository, getGroupRepository, getStudentRepository, getSubmissionRepository } from '../data/repositories.js'; import { Class } from '../entities/classes/class.entity.js'; import { Student } from '../entities/users/student.entity.js'; import { AssignmentDTO } from '../interfaces/assignment.js'; @@ -14,7 +9,6 @@ import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js'; import { getAllAssignments } from './assignments.js'; import { UserService } from './users.js'; - export async function getAllStudents(): Promise { const studentRepository = getStudentRepository(); const users = await studentRepository.findAll(); @@ -38,9 +32,9 @@ export async function createStudent(userData: StudentDTO): Promise await getAllAssignments(cls.classId!, full)) - ) - ).flat(); + const assignments = (await Promise.all(classes.map(async (cls) => await getAllAssignments(cls.classId!, full)))).flat(); return assignments; } @@ -121,9 +111,7 @@ export async function getStudentGroups(username: string, full: boolean): Promise return groups.map(mapToGroupDTOId); } -export async function getStudentSubmissions( - username: string -): Promise { +export async function getStudentSubmissions(username: string): Promise { const studentRepository = getStudentRepository(); const student = await studentRepository.findByUsername(username); @@ -135,4 +123,4 @@ export async function getStudentSubmissions( const submissions = await submissionRepository.findAllSubmissionsForStudent(student); return submissions.map(mapToSubmissionDTO); -} \ No newline at end of file +} diff --git a/backend/src/services/submissions.ts b/backend/src/services/submissions.ts index c9135001..a8fa96c7 100644 --- a/backend/src/services/submissions.ts +++ b/backend/src/services/submissions.ts @@ -1,13 +1,13 @@ -import {getGroupRepository, getSubmissionRepository} from "../data/repositories.js"; -import { Language } from "../entities/content/language.js"; -import { LearningObjectIdentifier } from "../entities/content/learning-object-identifier.js"; -import {mapToSubmission, mapToSubmissionDTO, SubmissionDTO} from "../interfaces/submission.js"; +import { getGroupRepository, getSubmissionRepository } from '../data/repositories.js'; +import { Language } from '../entities/content/language.js'; +import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; +import { mapToSubmission, mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js'; export async function getSubmission( learningObjectHruid: string, language: Language, version: number, - submissionNumber: number, + submissionNumber: number ): Promise { const loId = new LearningObjectIdentifier(learningObjectHruid, language, version); @@ -29,29 +29,23 @@ export async function createSubmission(submissionDTO: SubmissionDTO) { const newSubmission = await submissionRepository.create(submission); await submissionRepository.save(newSubmission); } catch (e) { - return null + return null; } return submission; } -export async function deleteSubmission( - learningObjectHruid: string, - language: Language, - version: number, - submissionNumber: number -) { +export async function deleteSubmission(learningObjectHruid: string, language: Language, version: number, submissionNumber: number) { const submissionRepository = getSubmissionRepository(); const submission = getSubmission(learningObjectHruid, language, version, submissionNumber); - if (!submission) - {return null} + if (!submission) { + return null; + } const loId = new LearningObjectIdentifier(learningObjectHruid, language, version); await submissionRepository.deleteSubmissionByLearningObjectAndSubmissionNumber(loId, submissionNumber); return submission; } - - diff --git a/backend/src/services/teachers.ts b/backend/src/services/teachers.ts index 2f462ed9..f4dbedfe 100644 --- a/backend/src/services/teachers.ts +++ b/backend/src/services/teachers.ts @@ -9,12 +9,7 @@ import { Teacher } from '../entities/users/teacher.entity.js'; import { ClassDTO, mapToClassDTO } from '../interfaces/class.js'; import { getClassStudents } from './class.js'; import { StudentDTO } from '../interfaces/student.js'; -import { - mapToQuestionDTO, - mapToQuestionId, - QuestionDTO, - QuestionId, -} from '../interfaces/question.js'; +import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js'; import { UserService } from './users.js'; import { mapToUser } from '../interfaces/user.js'; import { mapToTeacher, mapToTeacherDTO, TeacherDTO } from '../interfaces/teacher.js'; @@ -42,9 +37,9 @@ export async function createTeacher(userData: TeacherDTO): Promise export async function fetchStudentsByTeacher(username: string) { const classes = await getClassIdsByTeacher(username); - return ( - await Promise.all( - classes.map(async (id) => getClassStudents(id)) - ) - ).flat(); + return (await Promise.all(classes.map(async (id) => getClassStudents(id)))).flat(); } export async function getStudentsByTeacher(username: string): Promise { @@ -122,10 +113,7 @@ export async function fetchTeacherQuestions(username: string): Promise