Merge remote-tracking branch 'origin/dev' into chore/login
# Conflicts: # backend/.env.example # backend/package.json # backend/src/app.ts # backend/src/routes/login.ts # backend/src/routes/student.ts # docker-compose.yml # frontend/src/App.vue # frontend/src/views/HomePage.vue # frontend/src/views/LoginPage.vue # package-lock.json
This commit is contained in:
		
						commit
						de0199de96
					
				
					 109 changed files with 3789 additions and 1727 deletions
				
			
		|  | @ -1,8 +1,9 @@ | |||
| import express, { Express, Response } from 'express'; | ||||
| import { initORM } from './orm.js'; | ||||
| import { EnvVars, getNumericEnvVar } from './util/envvars.js'; | ||||
| 
 | ||||
| import themeRoutes from './routes/themes.js'; | ||||
| import learningPathRoutes from './routes/learningPaths.js'; | ||||
| import learningObjectRoutes from './routes/learningObjects.js'; | ||||
| 
 | ||||
| import studentRouter from './routes/student.js'; | ||||
| import groupRouter from './routes/group.js'; | ||||
|  | @ -13,20 +14,29 @@ import questionRouter from './routes/question.js'; | |||
| import authRouter from './routes/auth.js'; | ||||
| import {authenticateUser} from "./middleware/auth/auth.js"; | ||||
| import cors from "./middleware/cors.js"; | ||||
| import { getLogger, Logger } from './logging/initalize.js'; | ||||
| import { responseTimeLogger } from './logging/responseTimeLogger.js'; | ||||
| import responseTime from 'response-time'; | ||||
| import { EnvVars, getNumericEnvVar } from './util/envvars.js'; | ||||
| 
 | ||||
| const logger: Logger = getLogger(); | ||||
| 
 | ||||
| const app: Express = express(); | ||||
| const port: string | number = getNumericEnvVar(EnvVars.Port); | ||||
| 
 | ||||
| app.use(cors); | ||||
| app.use(express.json()); | ||||
| app.use(responseTime(responseTimeLogger)); | ||||
| app.use(authenticateUser); | ||||
| 
 | ||||
| // TODO Replace with Express routes
 | ||||
| app.get('/', (_, res: Response) => { | ||||
|     logger.debug('GET /'); | ||||
|     res.json({ | ||||
|         message: 'Hello Dwengo!🚀', | ||||
|     }); | ||||
| }); | ||||
| 
 | ||||
| app.use(cors); | ||||
| app.use(authenticateUser); | ||||
| 
 | ||||
| app.use('/student', studentRouter); | ||||
| app.use('/group', groupRouter); | ||||
| app.use('/assignment', assignmentRouter); | ||||
|  | @ -35,12 +45,14 @@ app.use('/class', classRouter); | |||
| app.use('/question', questionRouter); | ||||
| app.use('/auth', authRouter); | ||||
| app.use('/theme', themeRoutes); | ||||
| app.use('/learningPath', learningPathRoutes); | ||||
| app.use('/learningObject', learningObjectRoutes); | ||||
| 
 | ||||
| async function startServer() { | ||||
|     await initORM(); | ||||
| 
 | ||||
|     app.listen(port, () => { | ||||
|         console.log(`Server is running at http://localhost:${port}`); | ||||
|         logger.info(`Server is running at http://localhost:${port}`); | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										10
									
								
								backend/src/config.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								backend/src/config.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,10 @@ | |||
| export const FALLBACK_LANG: string = 'nl'; | ||||
| 
 | ||||
| // API
 | ||||
| 
 | ||||
| export const DWENGO_API_BASE: string = 'https://dwengo.org/backend/api'; | ||||
| 
 | ||||
| // Logging
 | ||||
| 
 | ||||
| export const LOG_LEVEL: string = 'development' === process.env.NODE_ENV ? 'debug' : 'info'; | ||||
| export const LOKI_HOST: string = process.env.LOKI_HOST || 'http://localhost:3102'; | ||||
							
								
								
									
										48
									
								
								backend/src/controllers/learningObjects.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								backend/src/controllers/learningObjects.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,48 @@ | |||
| import { Request, Response } from 'express'; | ||||
| import { getLearningObjectById, getLearningObjectIdsFromPath, getLearningObjectsFromPath } from '../services/learningObjects.js'; | ||||
| import { FALLBACK_LANG } from '../config.js'; | ||||
| import { FilteredLearningObject } from '../interfaces/learningPath.js'; | ||||
| import { getLogger } from '../logging/initalize.js'; | ||||
| 
 | ||||
| export async function getAllLearningObjects(req: Request, res: Response): Promise<void> { | ||||
|     try { | ||||
|         const hruid = req.query.hruid as string; | ||||
|         const full = req.query.full === 'true'; | ||||
|         const language = (req.query.language as string) || FALLBACK_LANG; | ||||
| 
 | ||||
|         if (!hruid) { | ||||
|             res.status(400).json({ error: 'HRUID query is required.' }); | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         let learningObjects: FilteredLearningObject[] | string[]; | ||||
|         if (full) { | ||||
|             learningObjects = await getLearningObjectsFromPath(hruid, language); | ||||
|         } else { | ||||
|             learningObjects = await getLearningObjectIdsFromPath(hruid, language); | ||||
|         } | ||||
| 
 | ||||
|         res.json(learningObjects); | ||||
|     } catch (error) { | ||||
|         getLogger().error('Error fetching learning objects:', error); | ||||
|         res.status(500).json({ error: 'Internal server error' }); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| export async function getLearningObject(req: Request, res: Response): Promise<void> { | ||||
|     try { | ||||
|         const { hruid } = req.params; | ||||
|         const language = (req.query.language as string) || FALLBACK_LANG; | ||||
| 
 | ||||
|         if (!hruid) { | ||||
|             res.status(400).json({ error: 'HRUID parameter is required.' }); | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         const learningObject = await getLearningObjectById(hruid, language); | ||||
|         res.json(learningObject); | ||||
|     } catch (error) { | ||||
|         getLogger().error('Error fetching learning object:', error); | ||||
|         res.status(500).json({ error: 'Internal server error' }); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										44
									
								
								backend/src/controllers/learningPaths.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								backend/src/controllers/learningPaths.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,44 @@ | |||
| import { Request, Response } from 'express'; | ||||
| import { themes } from '../data/themes.js'; | ||||
| import { FALLBACK_LANG } from '../config.js'; | ||||
| import { fetchLearningPaths, searchLearningPaths } from '../services/learningPaths.js'; | ||||
| import { getLogger } from '../logging/initalize.js'; | ||||
| /** | ||||
|  * Fetch learning paths based on query parameters. | ||||
|  */ | ||||
| export async function getLearningPaths(req: Request, res: Response): Promise<void> { | ||||
|     try { | ||||
|         const hruids = req.query.hruid; | ||||
|         const themeKey = req.query.theme as string; | ||||
|         const searchQuery = req.query.search as string; | ||||
|         const language = (req.query.language as string) || FALLBACK_LANG; | ||||
| 
 | ||||
|         let hruidList; | ||||
| 
 | ||||
|         if (hruids) { | ||||
|             hruidList = Array.isArray(hruids) ? hruids.map(String) : [String(hruids)]; | ||||
|         } else if (themeKey) { | ||||
|             const theme = themes.find((t) => t.title === themeKey); | ||||
|             if (theme) { | ||||
|                 hruidList = theme.hruids; | ||||
|             } else { | ||||
|                 res.status(404).json({ | ||||
|                     error: `Theme "${themeKey}" not found.`, | ||||
|                 }); | ||||
|                 return; | ||||
|             } | ||||
|         } else if (searchQuery) { | ||||
|             const searchResults = await searchLearningPaths(searchQuery, language); | ||||
|             res.json(searchResults); | ||||
|             return; | ||||
|         } else { | ||||
|             hruidList = themes.flatMap((theme) => theme.hruids); | ||||
|         } | ||||
| 
 | ||||
|         const learningPaths = await fetchLearningPaths(hruidList, language, `HRUIDs: ${hruidList.join(', ')}`); | ||||
|         res.json(learningPaths.data); | ||||
|     } catch (error) { | ||||
|         getLogger().error('❌ Unexpected error fetching learning paths:', error); | ||||
|         res.status(500).json({ error: 'Internal server error' }); | ||||
|     } | ||||
| } | ||||
|  | @ -1,65 +1,33 @@ | |||
| import fs from 'fs'; | ||||
| import path from 'path'; | ||||
| import yaml from 'js-yaml'; | ||||
| import { Request, Response } from 'express'; | ||||
| import { themes } from '../data/themes.js'; | ||||
| import { loadTranslations } from '../util/translationHelper.js'; | ||||
| 
 | ||||
| interface Translations { | ||||
|     curricula_page: { | ||||
|         [key: string]: { title: string; description?: string }; // Optioneel veld description
 | ||||
|         [key: string]: { title: string; description?: string }; | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * Laadt de vertalingen uit een YAML-bestand | ||||
|  */ | ||||
| function loadTranslations(language: string): Translations { | ||||
|     try { | ||||
|         const filePath = path.join(process.cwd(), '_i18n', `${language}.yml`); | ||||
|         const yamlFile = fs.readFileSync(filePath, 'utf8'); | ||||
|         return yaml.load(yamlFile) as Translations; | ||||
|     } catch (error) { | ||||
|         console.error( | ||||
|             `Kan vertaling niet laden voor ${language}, fallback naar Nederlands` | ||||
|         ); | ||||
|         console.error(error); | ||||
|         const fallbackPath = path.join(process.cwd(), '_i18n', 'nl.yml'); | ||||
|         return yaml.load(fs.readFileSync(fallbackPath, 'utf8')) as Translations; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * GET /themes → Haalt de lijst met thema's op inclusief vertalingen | ||||
|  */ | ||||
| export function getThemes(req: Request, res: Response) { | ||||
|     const language = (req.query.language as string)?.toLowerCase() || 'nl'; | ||||
|     const translations = loadTranslations(language); | ||||
| 
 | ||||
|     const themeList = themes.map((theme) => { | ||||
|         return { | ||||
|             key: theme.title, | ||||
|             title: | ||||
|                 translations.curricula_page[theme.title]?.title || theme.title, | ||||
|             description: translations.curricula_page[theme.title]?.description, | ||||
|             image: `https://dwengo.org/images/curricula/logo_${theme.title}.png`, | ||||
|         }; | ||||
|     }); | ||||
|     const translations = loadTranslations<Translations>(language); | ||||
|     const themeList = themes.map((theme) => ({ | ||||
|         key: theme.title, | ||||
|         title: translations.curricula_page[theme.title]?.title || theme.title, | ||||
|         description: translations.curricula_page[theme.title]?.description, | ||||
|         image: `https://dwengo.org/images/curricula/logo_${theme.title}.png`, | ||||
|     })); | ||||
| 
 | ||||
|     res.json(themeList); | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * GET /themes/:theme → Geeft de HRUIDs terug voor een specifiek thema | ||||
|  */ | ||||
| export function getThemeByTitle(req: Request, res: Response) { | ||||
|     const themeKey = req.params.theme; | ||||
|     const theme = themes.find((t) => { | ||||
|         return t.title === themeKey; | ||||
|     }); | ||||
|     const theme = themes.find((t) => t.title === themeKey); | ||||
| 
 | ||||
|     if (theme) { | ||||
|         res.json(theme.hruids); | ||||
|     } else { | ||||
|         res.status(404).json({ error: 'Thema niet gevonden' }); | ||||
|         res.status(404).json({ error: 'Theme not found' }); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -3,10 +3,7 @@ import { Assignment } from '../../entities/assignments/assignment.entity.js'; | |||
| import { Class } from '../../entities/classes/class.entity.js'; | ||||
| 
 | ||||
| export class AssignmentRepository extends DwengoEntityRepository<Assignment> { | ||||
|     public findByClassAndId( | ||||
|         within: Class, | ||||
|         id: number | ||||
|     ): Promise<Assignment | null> { | ||||
|     public findByClassAndId(within: Class, id: number): Promise<Assignment | null> { | ||||
|         return this.findOne({ within: within, id: id }); | ||||
|     } | ||||
|     public findAllAssignmentsInClass(within: Class): Promise<Assignment[]> { | ||||
|  |  | |||
|  | @ -3,24 +3,16 @@ import { Group } from '../../entities/assignments/group.entity.js'; | |||
| import { Assignment } from '../../entities/assignments/assignment.entity.js'; | ||||
| 
 | ||||
| export class GroupRepository extends DwengoEntityRepository<Group> { | ||||
|     public findByAssignmentAndGroupNumber( | ||||
|         assignment: Assignment, | ||||
|         groupNumber: number | ||||
|     ): Promise<Group | null> { | ||||
|     public findByAssignmentAndGroupNumber(assignment: Assignment, groupNumber: number): Promise<Group | null> { | ||||
|         return this.findOne({ | ||||
|             assignment: assignment, | ||||
|             groupNumber: groupNumber, | ||||
|         }); | ||||
|     } | ||||
|     public findAllGroupsForAssignment( | ||||
|         assignment: Assignment | ||||
|     ): Promise<Group[]> { | ||||
|     public findAllGroupsForAssignment(assignment: Assignment): Promise<Group[]> { | ||||
|         return this.findAll({ where: { assignment: assignment } }); | ||||
|     } | ||||
|     public deleteByAssignmentAndGroupNumber( | ||||
|         assignment: Assignment, | ||||
|         groupNumber: number | ||||
|     ) { | ||||
|     public deleteByAssignmentAndGroupNumber(assignment: Assignment, groupNumber: number) { | ||||
|         return this.deleteWhere({ | ||||
|             assignment: assignment, | ||||
|             groupNumber: groupNumber, | ||||
|  |  | |||
|  | @ -5,10 +5,7 @@ import { LearningObjectIdentifier } from '../../entities/content/learning-object | |||
| import { Student } from '../../entities/users/student.entity.js'; | ||||
| 
 | ||||
| export class SubmissionRepository extends DwengoEntityRepository<Submission> { | ||||
|     public findSubmissionByLearningObjectAndSubmissionNumber( | ||||
|         loId: LearningObjectIdentifier, | ||||
|         submissionNumber: number | ||||
|     ): Promise<Submission | null> { | ||||
|     public findSubmissionByLearningObjectAndSubmissionNumber(loId: LearningObjectIdentifier, submissionNumber: number): Promise<Submission | null> { | ||||
|         return this.findOne({ | ||||
|             learningObjectHruid: loId.hruid, | ||||
|             learningObjectLanguage: loId.language, | ||||
|  | @ -17,10 +14,7 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> { | |||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     public findMostRecentSubmissionForStudent( | ||||
|         loId: LearningObjectIdentifier, | ||||
|         submitter: Student | ||||
|     ): Promise<Submission | null> { | ||||
|     public findMostRecentSubmissionForStudent(loId: LearningObjectIdentifier, submitter: Student): Promise<Submission | null> { | ||||
|         return this.findOne( | ||||
|             { | ||||
|                 learningObjectHruid: loId.hruid, | ||||
|  | @ -32,10 +26,7 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> { | |||
|         ); | ||||
|     } | ||||
| 
 | ||||
|     public findMostRecentSubmissionForGroup( | ||||
|         loId: LearningObjectIdentifier, | ||||
|         group: Group | ||||
|     ): Promise<Submission | null> { | ||||
|     public findMostRecentSubmissionForGroup(loId: LearningObjectIdentifier, group: Group): Promise<Submission | null> { | ||||
|         return this.findOne( | ||||
|             { | ||||
|                 learningObjectHruid: loId.hruid, | ||||
|  | @ -47,10 +38,7 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> { | |||
|         ); | ||||
|     } | ||||
| 
 | ||||
|     public deleteSubmissionByLearningObjectAndSubmissionNumber( | ||||
|         loId: LearningObjectIdentifier, | ||||
|         submissionNumber: number | ||||
|     ): Promise<void> { | ||||
|     public deleteSubmissionByLearningObjectAndSubmissionNumber(loId: LearningObjectIdentifier, submissionNumber: number): Promise<void> { | ||||
|         return this.deleteWhere({ | ||||
|             learningObjectHruid: loId.hruid, | ||||
|             learningObjectLanguage: loId.language, | ||||
|  |  | |||
|  | @ -4,24 +4,16 @@ import { TeacherInvitation } from '../../entities/classes/teacher-invitation.ent | |||
| import { Teacher } from '../../entities/users/teacher.entity.js'; | ||||
| 
 | ||||
| export class TeacherInvitationRepository extends DwengoEntityRepository<TeacherInvitation> { | ||||
|     public findAllInvitationsForClass( | ||||
|         clazz: Class | ||||
|     ): Promise<TeacherInvitation[]> { | ||||
|     public findAllInvitationsForClass(clazz: Class): Promise<TeacherInvitation[]> { | ||||
|         return this.findAll({ where: { class: clazz } }); | ||||
|     } | ||||
|     public findAllInvitationsBy(sender: Teacher): Promise<TeacherInvitation[]> { | ||||
|         return this.findAll({ where: { sender: sender } }); | ||||
|     } | ||||
|     public findAllInvitationsFor( | ||||
|         receiver: Teacher | ||||
|     ): Promise<TeacherInvitation[]> { | ||||
|     public findAllInvitationsFor(receiver: Teacher): Promise<TeacherInvitation[]> { | ||||
|         return this.findAll({ where: { receiver: receiver } }); | ||||
|     } | ||||
|     public deleteBy( | ||||
|         clazz: Class, | ||||
|         sender: Teacher, | ||||
|         receiver: Teacher | ||||
|     ): Promise<void> { | ||||
|     public deleteBy(clazz: Class, sender: Teacher, receiver: Teacher): Promise<void> { | ||||
|         return this.deleteWhere({ | ||||
|             sender: sender, | ||||
|             receiver: receiver, | ||||
|  |  | |||
|  | @ -3,10 +3,7 @@ import { Attachment } from '../../entities/content/attachment.entity.js'; | |||
| import { LearningObject } from '../../entities/content/learning-object.entity.js'; | ||||
| 
 | ||||
| export class AttachmentRepository extends DwengoEntityRepository<Attachment> { | ||||
|     public findByLearningObjectAndNumber( | ||||
|         learningObject: LearningObject, | ||||
|         sequenceNumber: number | ||||
|     ) { | ||||
|     public findByLearningObjectAndNumber(learningObject: LearningObject, sequenceNumber: number) { | ||||
|         return this.findOne({ | ||||
|             learningObject: learningObject, | ||||
|             sequenceNumber: sequenceNumber, | ||||
|  |  | |||
|  | @ -3,9 +3,7 @@ import { LearningObject } from '../../entities/content/learning-object.entity.js | |||
| import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier.js'; | ||||
| 
 | ||||
| export class LearningObjectRepository extends DwengoEntityRepository<LearningObject> { | ||||
|     public findByIdentifier( | ||||
|         identifier: LearningObjectIdentifier | ||||
|     ): Promise<LearningObject | null> { | ||||
|     public findByIdentifier(identifier: LearningObjectIdentifier): Promise<LearningObject | null> { | ||||
|         return this.findOne({ | ||||
|             hruid: identifier.hruid, | ||||
|             language: identifier.language, | ||||
|  |  | |||
|  | @ -3,10 +3,7 @@ import { LearningPath } from '../../entities/content/learning-path.entity.js'; | |||
| import { Language } from '../../entities/content/language.js'; | ||||
| 
 | ||||
| export class LearningPathRepository extends DwengoEntityRepository<LearningPath> { | ||||
|     public findByHruidAndLanguage( | ||||
|         hruid: string, | ||||
|         language: Language | ||||
|     ): Promise<LearningPath | null> { | ||||
|     public findByHruidAndLanguage(hruid: string, language: Language): Promise<LearningPath | null> { | ||||
|         return this.findOne({ hruid: hruid, language: language }); | ||||
|     } | ||||
|     // This repository is read-only for now since creating own learning object is an extension feature.
 | ||||
|  |  | |||
|  | @ -1,16 +1,14 @@ | |||
| import { EntityRepository, FilterQuery } from '@mikro-orm/core'; | ||||
| 
 | ||||
| export abstract class DwengoEntityRepository< | ||||
|     T extends object, | ||||
| > extends EntityRepository<T> { | ||||
| export abstract class DwengoEntityRepository<T extends object> extends EntityRepository<T> { | ||||
|     public async save(entity: T) { | ||||
|         let em = this.getEntityManager(); | ||||
|         const em = this.getEntityManager(); | ||||
|         em.persist(entity); | ||||
|         await em.flush(); | ||||
|     } | ||||
|     public async deleteWhere(query: FilterQuery<T>) { | ||||
|         let toDelete = await this.findOne(query); | ||||
|         let em = this.getEntityManager(); | ||||
|         const toDelete = await this.findOne(query); | ||||
|         const em = this.getEntityManager(); | ||||
|         if (toDelete) { | ||||
|             em.remove(toDelete); | ||||
|             await em.flush(); | ||||
|  |  | |||
|  | @ -4,12 +4,8 @@ import { Question } from '../../entities/questions/question.entity.js'; | |||
| import { Teacher } from '../../entities/users/teacher.entity.js'; | ||||
| 
 | ||||
| export class AnswerRepository extends DwengoEntityRepository<Answer> { | ||||
|     public createAnswer(answer: { | ||||
|         toQuestion: Question; | ||||
|         author: Teacher; | ||||
|         content: string; | ||||
|     }): Promise<Answer> { | ||||
|         let answerEntity = new Answer(); | ||||
|     public createAnswer(answer: { toQuestion: Question; author: Teacher; content: string }): Promise<Answer> { | ||||
|         const answerEntity = new Answer(); | ||||
|         answerEntity.toQuestion = answer.toQuestion; | ||||
|         answerEntity.author = answer.author; | ||||
|         answerEntity.content = answer.content; | ||||
|  | @ -21,10 +17,7 @@ export class AnswerRepository extends DwengoEntityRepository<Answer> { | |||
|             orderBy: { sequenceNumber: 'ASC' }, | ||||
|         }); | ||||
|     } | ||||
|     public removeAnswerByQuestionAndSequenceNumber( | ||||
|         question: Question, | ||||
|         sequenceNumber: number | ||||
|     ): Promise<void> { | ||||
|     public removeAnswerByQuestionAndSequenceNumber(question: Question, sequenceNumber: number): Promise<void> { | ||||
|         return this.deleteWhere({ | ||||
|             toQuestion: question, | ||||
|             sequenceNumber: sequenceNumber, | ||||
|  |  | |||
|  | @ -4,12 +4,8 @@ import { LearningObjectIdentifier } from '../../entities/content/learning-object | |||
| import { Student } from '../../entities/users/student.entity.js'; | ||||
| 
 | ||||
| export class QuestionRepository extends DwengoEntityRepository<Question> { | ||||
|     public createQuestion(question: { | ||||
|         loId: LearningObjectIdentifier; | ||||
|         author: Student; | ||||
|         content: string; | ||||
|     }): Promise<Question> { | ||||
|         let questionEntity = new Question(); | ||||
|     public createQuestion(question: { loId: LearningObjectIdentifier; author: Student; content: string }): Promise<Question> { | ||||
|         const questionEntity = new Question(); | ||||
|         questionEntity.learningObjectHruid = question.loId.hruid; | ||||
|         questionEntity.learningObjectLanguage = question.loId.language; | ||||
|         questionEntity.learningObjectVersion = question.loId.version; | ||||
|  | @ -17,9 +13,7 @@ export class QuestionRepository extends DwengoEntityRepository<Question> { | |||
|         questionEntity.content = question.content; | ||||
|         return this.insert(questionEntity); | ||||
|     } | ||||
|     public findAllQuestionsAboutLearningObject( | ||||
|         loId: LearningObjectIdentifier | ||||
|     ): Promise<Question[]> { | ||||
|     public findAllQuestionsAboutLearningObject(loId: LearningObjectIdentifier): Promise<Question[]> { | ||||
|         return this.findAll({ | ||||
|             where: { | ||||
|                 learningObjectHruid: loId.hruid, | ||||
|  | @ -31,10 +25,7 @@ export class QuestionRepository extends DwengoEntityRepository<Question> { | |||
|             }, | ||||
|         }); | ||||
|     } | ||||
|     public removeQuestionByLearningObjectAndSequenceNumber( | ||||
|         loId: LearningObjectIdentifier, | ||||
|         sequenceNumber: number | ||||
|     ): Promise<void> { | ||||
|     public removeQuestionByLearningObjectAndSequenceNumber(loId: LearningObjectIdentifier, sequenceNumber: number): Promise<void> { | ||||
|         return this.deleteWhere({ | ||||
|             learningObjectHruid: loId.hruid, | ||||
|             learningObjectLanguage: loId.language, | ||||
|  |  | |||
|  | @ -1,9 +1,4 @@ | |||
| import { | ||||
|     AnyEntity, | ||||
|     EntityManager, | ||||
|     EntityName, | ||||
|     EntityRepository, | ||||
| } from '@mikro-orm/core'; | ||||
| import { AnyEntity, EntityManager, EntityName, EntityRepository } from '@mikro-orm/core'; | ||||
| import { forkEntityManager } from '../orm.js'; | ||||
| import { StudentRepository } from './users/student-repository.js'; | ||||
| import { Student } from '../entities/users/student.entity.js'; | ||||
|  | @ -43,9 +38,7 @@ export function transactional<T>(f: () => Promise<T>) { | |||
|     entityManager?.transactional(f); | ||||
| } | ||||
| 
 | ||||
| function repositoryGetter<T extends AnyEntity, R extends EntityRepository<T>>( | ||||
|     entity: EntityName<T> | ||||
| ): () => R { | ||||
| function repositoryGetter<T extends AnyEntity, R extends EntityRepository<T>>(entity: EntityName<T>): () => R { | ||||
|     let cachedRepo: R | undefined; | ||||
|     return (): R => { | ||||
|         if (!cachedRepo) { | ||||
|  | @ -60,60 +53,24 @@ function repositoryGetter<T extends AnyEntity, R extends EntityRepository<T>>( | |||
| 
 | ||||
| /* Users */ | ||||
| export const getUserRepository = repositoryGetter<User, UserRepository>(User); | ||||
| export const getStudentRepository = repositoryGetter< | ||||
|     Student, | ||||
|     StudentRepository | ||||
| >(Student); | ||||
| export const getTeacherRepository = repositoryGetter< | ||||
|     Teacher, | ||||
|     TeacherRepository | ||||
| >(Teacher); | ||||
| export const getStudentRepository = repositoryGetter<Student, StudentRepository>(Student); | ||||
| export const getTeacherRepository = repositoryGetter<Teacher, TeacherRepository>(Teacher); | ||||
| 
 | ||||
| /* Classes */ | ||||
| export const getClassRepository = repositoryGetter<Class, ClassRepository>( | ||||
|     Class | ||||
| ); | ||||
| export const getClassJoinRequestRepository = repositoryGetter< | ||||
|     ClassJoinRequest, | ||||
|     ClassJoinRequestRepository | ||||
| >(ClassJoinRequest); | ||||
| export const getTeacherInvitationRepository = repositoryGetter< | ||||
|     TeacherInvitation, | ||||
|     TeacherInvitationRepository | ||||
| >(TeacherInvitationRepository); | ||||
| export const getClassRepository = repositoryGetter<Class, ClassRepository>(Class); | ||||
| export const getClassJoinRequestRepository = repositoryGetter<ClassJoinRequest, ClassJoinRequestRepository>(ClassJoinRequest); | ||||
| export const getTeacherInvitationRepository = repositoryGetter<TeacherInvitation, TeacherInvitationRepository>(TeacherInvitationRepository); | ||||
| 
 | ||||
| /* Assignments */ | ||||
| export const getAssignmentRepository = repositoryGetter< | ||||
|     Assignment, | ||||
|     AssignmentRepository | ||||
| >(Assignment); | ||||
| export const getGroupRepository = repositoryGetter<Group, GroupRepository>( | ||||
|     Group | ||||
| ); | ||||
| export const getSubmissionRepository = repositoryGetter< | ||||
|     Submission, | ||||
|     SubmissionRepository | ||||
| >(Submission); | ||||
| export const getAssignmentRepository = repositoryGetter<Assignment, AssignmentRepository>(Assignment); | ||||
| export const getGroupRepository = repositoryGetter<Group, GroupRepository>(Group); | ||||
| export const getSubmissionRepository = repositoryGetter<Submission, SubmissionRepository>(Submission); | ||||
| 
 | ||||
| /* Questions and answers */ | ||||
| export const getQuestionRepository = repositoryGetter< | ||||
|     Question, | ||||
|     QuestionRepository | ||||
| >(Question); | ||||
| export const getAnswerRepository = repositoryGetter<Answer, AnswerRepository>( | ||||
|     Answer | ||||
| ); | ||||
| export const getQuestionRepository = repositoryGetter<Question, QuestionRepository>(Question); | ||||
| export const getAnswerRepository = repositoryGetter<Answer, AnswerRepository>(Answer); | ||||
| 
 | ||||
| /* Learning content */ | ||||
| export const getLearningObjectRepository = repositoryGetter< | ||||
|     LearningObject, | ||||
|     LearningObjectRepository | ||||
| >(LearningObject); | ||||
| export const getLearningPathRepository = repositoryGetter< | ||||
|     LearningPath, | ||||
|     LearningPathRepository | ||||
| >(LearningPath); | ||||
| export const getAttachmentRepository = repositoryGetter< | ||||
|     Attachment, | ||||
|     AttachmentRepository | ||||
| >(Assignment); | ||||
| export const getLearningObjectRepository = repositoryGetter<LearningObject, LearningObjectRepository>(LearningObject); | ||||
| export const getLearningPathRepository = repositoryGetter<LearningPath, LearningPathRepository>(LearningPath); | ||||
| export const getAttachmentRepository = repositoryGetter<Attachment, AttachmentRepository>(Assignment); | ||||
|  |  | |||
|  | @ -23,13 +23,7 @@ export const themes: Theme[] = [ | |||
|     }, | ||||
|     { | ||||
|         title: 'art', | ||||
|         hruids: [ | ||||
|             'pn_werking', | ||||
|             'un_artificiele_intelligentie', | ||||
|             'art1', | ||||
|             'art2', | ||||
|             'art3', | ||||
|         ], | ||||
|         hruids: ['pn_werking', 'un_artificiele_intelligentie', 'art1', 'art2', 'art3'], | ||||
|     }, | ||||
|     { | ||||
|         title: 'socialrobot', | ||||
|  | @ -37,12 +31,7 @@ export const themes: Theme[] = [ | |||
|     }, | ||||
|     { | ||||
|         title: 'agriculture', | ||||
|         hruids: [ | ||||
|             'pn_werking', | ||||
|             'un_artificiele_intelligentie', | ||||
|             'agri_landbouw', | ||||
|             'agri_lopendeband', | ||||
|         ], | ||||
|         hruids: ['pn_werking', 'un_artificiele_intelligentie', 'agri_landbouw', 'agri_lopendeband'], | ||||
|     }, | ||||
|     { | ||||
|         title: 'wegostem', | ||||
|  | @ -83,16 +72,7 @@ export const themes: Theme[] = [ | |||
|     }, | ||||
|     { | ||||
|         title: 'python_programming', | ||||
|         hruids: [ | ||||
|             'pn_werking', | ||||
|             'pn_datatypes', | ||||
|             'pn_operatoren', | ||||
|             'pn_structuren', | ||||
|             'pn_functies', | ||||
|             'art2', | ||||
|             'stem_insectbooks', | ||||
|             'un_algoenprog', | ||||
|         ], | ||||
|         hruids: ['pn_werking', 'pn_datatypes', 'pn_operatoren', 'pn_structuren', 'pn_functies', 'art2', 'stem_insectbooks', 'un_algoenprog'], | ||||
|     }, | ||||
|     { | ||||
|         title: 'stem', | ||||
|  | @ -110,15 +90,7 @@ export const themes: Theme[] = [ | |||
|     }, | ||||
|     { | ||||
|         title: 'care', | ||||
|         hruids: [ | ||||
|             'pn_werking', | ||||
|             'un_artificiele_intelligentie', | ||||
|             'aiz1_zorg', | ||||
|             'aiz2_grafen', | ||||
|             'aiz3_unplugged', | ||||
|             'aiz4_eindtermen', | ||||
|             'aiz5_triage', | ||||
|         ], | ||||
|         hruids: ['pn_werking', 'un_artificiele_intelligentie', 'aiz1_zorg', 'aiz2_grafen', 'aiz3_unplugged', 'aiz4_eindtermen', 'aiz5_triage'], | ||||
|     }, | ||||
|     { | ||||
|         title: 'chatbot', | ||||
|  |  | |||
|  | @ -1,11 +1,4 @@ | |||
| import { | ||||
|     Entity, | ||||
|     Enum, | ||||
|     ManyToOne, | ||||
|     OneToMany, | ||||
|     PrimaryKey, | ||||
|     Property, | ||||
| } from '@mikro-orm/core'; | ||||
| import { 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'; | ||||
|  |  | |||
|  | @ -4,12 +4,17 @@ import { Student } from '../users/student.entity.js'; | |||
| 
 | ||||
| @Entity() | ||||
| export class Group { | ||||
|     @ManyToOne({ entity: () => Assignment, primary: true }) | ||||
|     @ManyToOne({ | ||||
|         entity: () => Assignment, | ||||
|         primary: true, | ||||
|     }) | ||||
|     assignment!: Assignment; | ||||
| 
 | ||||
|     @PrimaryKey({ type: 'integer' }) | ||||
|     groupNumber!: number; | ||||
| 
 | ||||
|     @ManyToMany({ entity: () => Student }) | ||||
|     @ManyToMany({ | ||||
|         entity: () => Student, | ||||
|     }) | ||||
|     members!: Student[]; | ||||
| } | ||||
|  |  | |||
|  | @ -8,7 +8,10 @@ export class Submission { | |||
|     @PrimaryKey({ type: 'string' }) | ||||
|     learningObjectHruid!: string; | ||||
| 
 | ||||
|     @Enum({ items: () => Language, primary: true }) | ||||
|     @Enum({ | ||||
|         items: () => Language, | ||||
|         primary: true, | ||||
|     }) | ||||
|     learningObjectLanguage!: Language; | ||||
| 
 | ||||
|     @PrimaryKey({ type: 'string' }) | ||||
|  | @ -17,13 +20,18 @@ export class Submission { | |||
|     @PrimaryKey({ type: 'integer' }) | ||||
|     submissionNumber!: number; | ||||
| 
 | ||||
|     @ManyToOne({ entity: () => Student }) | ||||
|     @ManyToOne({ | ||||
|         entity: () => Student, | ||||
|     }) | ||||
|     submitter!: Student; | ||||
| 
 | ||||
|     @Property({ type: 'datetime' }) | ||||
|     submissionTime!: Date; | ||||
| 
 | ||||
|     @ManyToOne({ entity: () => Group, nullable: true }) | ||||
|     @ManyToOne({ | ||||
|         entity: () => Group, | ||||
|         nullable: true, | ||||
|     }) | ||||
|     onBehalfOf?: Group; | ||||
| 
 | ||||
|     @Property({ type: 'json' }) | ||||
|  |  | |||
|  | @ -1,13 +1,19 @@ | |||
| import { Entity, Enum, ManyToOne } from '@mikro-orm/core'; | ||||
| import { Student } from '../users/student.entity'; | ||||
| import { Class } from './class.entity'; | ||||
| import { Student } from '../users/student.entity.js'; | ||||
| import { Class } from './class.entity.js'; | ||||
| 
 | ||||
| @Entity() | ||||
| export class ClassJoinRequest { | ||||
|     @ManyToOne({ entity: () => Student, primary: true }) | ||||
|     @ManyToOne({ | ||||
|         entity: () => Student, | ||||
|         primary: true, | ||||
|     }) | ||||
|     requester!: Student; | ||||
| 
 | ||||
|     @ManyToOne({ entity: () => Class, primary: true }) | ||||
|     @ManyToOne({ | ||||
|         entity: () => Class, | ||||
|         primary: true, | ||||
|     }) | ||||
|     class!: Class; | ||||
| 
 | ||||
|     @Enum(() => ClassJoinRequestStatus) | ||||
|  |  | |||
|  | @ -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'; | ||||
|  |  | |||
|  | @ -7,12 +7,21 @@ import { Class } from './class.entity.js'; | |||
|  */ | ||||
| @Entity() | ||||
| export class TeacherInvitation { | ||||
|     @ManyToOne({ entity: () => Teacher, primary: true }) | ||||
|     @ManyToOne({ | ||||
|         entity: () => Teacher, | ||||
|         primary: true, | ||||
|     }) | ||||
|     sender!: Teacher; | ||||
| 
 | ||||
|     @ManyToOne({ entity: () => Teacher, primary: true }) | ||||
|     @ManyToOne({ | ||||
|         entity: () => Teacher, | ||||
|         primary: true, | ||||
|     }) | ||||
|     receiver!: Teacher; | ||||
| 
 | ||||
|     @ManyToOne({ entity: () => Class, primary: true }) | ||||
|     @ManyToOne({ | ||||
|         entity: () => Class, | ||||
|         primary: true, | ||||
|     }) | ||||
|     class!: Class; | ||||
| } | ||||
|  |  | |||
|  | @ -3,7 +3,10 @@ import { LearningObject } from './learning-object.entity.js'; | |||
| 
 | ||||
| @Entity() | ||||
| export class Attachment { | ||||
|     @ManyToOne({ entity: () => LearningObject, primary: true }) | ||||
|     @ManyToOne({ | ||||
|         entity: () => LearningObject, | ||||
|         primary: true, | ||||
|     }) | ||||
|     learningObject!: LearningObject; | ||||
| 
 | ||||
|     @PrimaryKey({ type: 'integer' }) | ||||
|  |  | |||
|  | @ -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'; | ||||
|  | @ -17,13 +8,18 @@ export class LearningObject { | |||
|     @PrimaryKey({ type: 'string' }) | ||||
|     hruid!: string; | ||||
| 
 | ||||
|     @Enum({ items: () => Language, primary: true }) | ||||
|     @Enum({ | ||||
|         items: () => Language, | ||||
|         primary: true, | ||||
|     }) | ||||
|     language!: Language; | ||||
| 
 | ||||
|     @PrimaryKey({ type: 'string' }) | ||||
|     version: string = '1'; | ||||
| 
 | ||||
|     @ManyToMany({ entity: () => Teacher }) | ||||
|     @ManyToMany({ | ||||
|         entity: () => Teacher, | ||||
|     }) | ||||
|     admins!: Teacher[]; | ||||
| 
 | ||||
|     @Property({ type: 'string' }) | ||||
|  | @ -47,7 +43,10 @@ export class LearningObject { | |||
|     @Property({ type: 'array' }) | ||||
|     skosConcepts!: string[]; | ||||
| 
 | ||||
|     @Embedded({ entity: () => EducationalGoal, array: true }) | ||||
|     @Embedded({ | ||||
|         entity: () => EducationalGoal, | ||||
|         array: true, | ||||
|     }) | ||||
|     educationalGoals: EducationalGoal[] = []; | ||||
| 
 | ||||
|     @Property({ type: 'string' }) | ||||
|  | @ -62,7 +61,9 @@ export class LearningObject { | |||
|     @Property({ type: 'integer' }) | ||||
|     estimatedTime!: number; | ||||
| 
 | ||||
|     @Embedded({ entity: () => ReturnValue }) | ||||
|     @Embedded({ | ||||
|         entity: () => ReturnValue, | ||||
|     }) | ||||
|     returnValue!: ReturnValue; | ||||
| 
 | ||||
|     @Property({ type: 'bool' }) | ||||
|  | @ -71,7 +72,10 @@ export class LearningObject { | |||
|     @Property({ type: 'string', nullable: true }) | ||||
|     contentLocation?: string; | ||||
| 
 | ||||
|     @OneToMany({ entity: () => Attachment, mappedBy: 'learningObject' }) | ||||
|     @OneToMany({ | ||||
|         entity: () => Attachment, | ||||
|         mappedBy: 'learningObject', | ||||
|     }) | ||||
|     attachments: Attachment[] = []; | ||||
| 
 | ||||
|     @Property({ type: 'blob' }) | ||||
|  |  | |||
|  | @ -1,13 +1,4 @@ | |||
| import { | ||||
|     Embeddable, | ||||
|     Embedded, | ||||
|     Entity, | ||||
|     Enum, | ||||
|     ManyToMany, | ||||
|     OneToOne, | ||||
|     PrimaryKey, | ||||
|     Property, | ||||
| } from '@mikro-orm/core'; | ||||
| import { Embeddable, Embedded, Entity, Enum, ManyToMany, OneToOne, PrimaryKey, Property } from '@mikro-orm/core'; | ||||
| import { Language } from './language.js'; | ||||
| import { Teacher } from '../users/teacher.entity.js'; | ||||
| 
 | ||||
|  | @ -16,10 +7,15 @@ export class LearningPath { | |||
|     @PrimaryKey({ type: 'string' }) | ||||
|     hruid!: string; | ||||
| 
 | ||||
|     @Enum({ items: () => Language, primary: true }) | ||||
|     @Enum({ | ||||
|         items: () => Language, | ||||
|         primary: true, | ||||
|     }) | ||||
|     language!: Language; | ||||
| 
 | ||||
|     @ManyToMany({ entity: () => Teacher }) | ||||
|     @ManyToMany({ | ||||
|         entity: () => Teacher, | ||||
|     }) | ||||
|     admins!: Teacher[]; | ||||
| 
 | ||||
|     @Property({ type: 'string' }) | ||||
|  | @ -31,7 +27,10 @@ export class LearningPath { | |||
|     @Property({ type: 'blob' }) | ||||
|     image!: string; | ||||
| 
 | ||||
|     @Embedded({ entity: () => LearningPathNode, array: true }) | ||||
|     @Embedded({ | ||||
|         entity: () => LearningPathNode, | ||||
|         array: true, | ||||
|     }) | ||||
|     nodes: LearningPathNode[] = []; | ||||
| } | ||||
| 
 | ||||
|  | @ -40,7 +39,9 @@ export class LearningPathNode { | |||
|     @Property({ type: 'string' }) | ||||
|     learningObjectHruid!: string; | ||||
| 
 | ||||
|     @Enum({ items: () => Language }) | ||||
|     @Enum({ | ||||
|         items: () => Language, | ||||
|     }) | ||||
|     language!: Language; | ||||
| 
 | ||||
|     @Property({ type: 'string' }) | ||||
|  | @ -52,7 +53,10 @@ export class LearningPathNode { | |||
|     @Property({ type: 'bool' }) | ||||
|     startNode!: boolean; | ||||
| 
 | ||||
|     @Embedded({ entity: () => LearningPathTransition, array: true }) | ||||
|     @Embedded({ | ||||
|         entity: () => LearningPathTransition, | ||||
|         array: true, | ||||
|     }) | ||||
|     transitions!: LearningPathTransition[]; | ||||
| } | ||||
| 
 | ||||
|  | @ -61,6 +65,8 @@ export class LearningPathTransition { | |||
|     @Property({ type: 'string' }) | ||||
|     condition!: string; | ||||
| 
 | ||||
|     @OneToOne({ entity: () => LearningPathNode }) | ||||
|     @OneToOne({ | ||||
|         entity: () => LearningPathNode, | ||||
|     }) | ||||
|     next!: LearningPathNode; | ||||
| } | ||||
|  |  | |||
|  | @ -1,13 +1,19 @@ | |||
| import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'; | ||||
| import { Question } from './question.entity'; | ||||
| import { Teacher } from '../users/teacher.entity'; | ||||
| import { Question } from './question.entity.js'; | ||||
| import { Teacher } from '../users/teacher.entity.js'; | ||||
| 
 | ||||
| @Entity() | ||||
| export class Answer { | ||||
|     @ManyToOne({ entity: () => Teacher, primary: true }) | ||||
|     @ManyToOne({ | ||||
|         entity: () => Teacher, | ||||
|         primary: true, | ||||
|     }) | ||||
|     author!: Teacher; | ||||
| 
 | ||||
|     @ManyToOne({ entity: () => Question, primary: true }) | ||||
|     @ManyToOne({ | ||||
|         entity: () => Question, | ||||
|         primary: true, | ||||
|     }) | ||||
|     toQuestion!: Question; | ||||
| 
 | ||||
|     @PrimaryKey({ type: 'integer' }) | ||||
|  |  | |||
|  | @ -7,7 +7,10 @@ export class Question { | |||
|     @PrimaryKey({ type: 'string' }) | ||||
|     learningObjectHruid!: string; | ||||
| 
 | ||||
|     @Enum({ items: () => Language, primary: true }) | ||||
|     @Enum({ | ||||
|         items: () => Language, | ||||
|         primary: true, | ||||
|     }) | ||||
|     learningObjectLanguage!: Language; | ||||
| 
 | ||||
|     @PrimaryKey({ type: 'string' }) | ||||
|  | @ -16,7 +19,9 @@ export class Question { | |||
|     @PrimaryKey({ type: 'integer' }) | ||||
|     sequenceNumber!: number; | ||||
| 
 | ||||
|     @ManyToOne({ entity: () => Student }) | ||||
|     @ManyToOne({ | ||||
|         entity: () => Student, | ||||
|     }) | ||||
|     author!: Student; | ||||
| 
 | ||||
|     @Property({ type: 'datetime' }) | ||||
|  |  | |||
|  | @ -4,7 +4,9 @@ import { Class } from '../classes/class.entity.js'; | |||
| import { Group } from '../assignments/group.entity.js'; | ||||
| import { StudentRepository } from '../../data/users/student-repository.js'; | ||||
| 
 | ||||
| @Entity({ repository: () => StudentRepository }) | ||||
| @Entity({ | ||||
|     repository: () => StudentRepository, | ||||
| }) | ||||
| export class Student extends User { | ||||
|     @ManyToMany(() => Class) | ||||
|     classes!: Collection<Class>; | ||||
|  |  | |||
							
								
								
									
										98
									
								
								backend/src/interfaces/learningPath.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										98
									
								
								backend/src/interfaces/learningPath.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,98 @@ | |||
| export interface Transition { | ||||
|     default: boolean; | ||||
|     _id: string; | ||||
|     next: { | ||||
|         _id: string; | ||||
|         hruid: string; | ||||
|         version: number; | ||||
|         language: string; | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| export interface LearningObjectNode { | ||||
|     _id: string; | ||||
|     learningobject_hruid: string; | ||||
|     version: number; | ||||
|     language: string; | ||||
|     start_node?: boolean; | ||||
|     transitions: Transition[]; | ||||
|     created_at: string; | ||||
|     updatedAt: string; | ||||
| } | ||||
| 
 | ||||
| export interface LearningPath { | ||||
|     _id: string; | ||||
|     language: string; | ||||
|     hruid: string; | ||||
|     title: string; | ||||
|     description: string; | ||||
|     image?: string; // Image might be missing, so it's optional
 | ||||
|     num_nodes: number; | ||||
|     num_nodes_left: number; | ||||
|     nodes: LearningObjectNode[]; | ||||
|     keywords: string; | ||||
|     target_ages: number[]; | ||||
|     min_age: number; | ||||
|     max_age: number; | ||||
|     __order: number; | ||||
| } | ||||
| 
 | ||||
| export interface EducationalGoal { | ||||
|     source: string; | ||||
|     id: string; | ||||
| } | ||||
| 
 | ||||
| export interface ReturnValue { | ||||
|     callback_url: string; | ||||
|     callback_schema: Record<string, any>; | ||||
| } | ||||
| 
 | ||||
| export interface LearningObjectMetadata { | ||||
|     _id: string; | ||||
|     uuid: string; | ||||
|     hruid: string; | ||||
|     version: number; | ||||
|     language: string; | ||||
|     title: string; | ||||
|     description: string; | ||||
|     difficulty: number; | ||||
|     estimated_time: number; | ||||
|     available: boolean; | ||||
|     teacher_exclusive: boolean; | ||||
|     educational_goals: EducationalGoal[]; | ||||
|     keywords: string[]; | ||||
|     target_ages: number[]; | ||||
|     content_type: string; // Markdown, image, etc.
 | ||||
|     content_location?: string; | ||||
|     skos_concepts?: string[]; | ||||
|     return_value?: ReturnValue; | ||||
| } | ||||
| 
 | ||||
| export interface FilteredLearningObject { | ||||
|     key: string; | ||||
|     _id: string; | ||||
|     uuid: string; | ||||
|     version: number; | ||||
|     title: string; | ||||
|     htmlUrl: string; | ||||
|     language: string; | ||||
|     difficulty: number; | ||||
|     estimatedTime: number; | ||||
|     available: boolean; | ||||
|     teacherExclusive: boolean; | ||||
|     educationalGoals: EducationalGoal[]; | ||||
|     keywords: string[]; | ||||
|     description: string; | ||||
|     targetAges: number[]; | ||||
|     contentType: string; | ||||
|     contentLocation?: string; | ||||
|     skosConcepts?: string[]; | ||||
|     returnValue?: ReturnValue; | ||||
| } | ||||
| 
 | ||||
| export interface LearningPathResponse { | ||||
|     success: boolean; | ||||
|     source: string; | ||||
|     data: LearningPath[] | null; | ||||
|     message?: string; | ||||
| } | ||||
							
								
								
									
										53
									
								
								backend/src/logging/initalize.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								backend/src/logging/initalize.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,53 @@ | |||
| import { createLogger, format, Logger as WinstonLogger, transports } from 'winston'; | ||||
| import LokiTransport from 'winston-loki'; | ||||
| import { LokiLabels } from 'loki-logger-ts'; | ||||
| import { LOG_LEVEL, LOKI_HOST } from '../config.js'; | ||||
| 
 | ||||
| export class Logger extends WinstonLogger { | ||||
|     constructor() { | ||||
|         super(); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| const Labels: LokiLabels = { | ||||
|     source: 'Dwengo-Backend', | ||||
|     service: 'API', | ||||
|     host: 'localhost', | ||||
| }; | ||||
| 
 | ||||
| let logger: Logger; | ||||
| 
 | ||||
| function initializeLogger(): Logger { | ||||
|     if (logger !== undefined) { | ||||
|         return logger; | ||||
|     } | ||||
| 
 | ||||
|     const lokiTransport: LokiTransport = new LokiTransport({ | ||||
|         host: LOKI_HOST, | ||||
|         labels: Labels, | ||||
|         level: LOG_LEVEL, | ||||
|         json: true, | ||||
|         format: format.combine(format.timestamp(), format.json()), | ||||
|         onConnectionError: (err) => { | ||||
|             // eslint-disable-next-line no-console
 | ||||
|             console.error(`Connection error: ${err}`); | ||||
|         }, | ||||
|     }); | ||||
| 
 | ||||
|     const consoleTransport = new transports.Console({ | ||||
|         level: LOG_LEVEL, | ||||
|         format: format.combine(format.cli(), format.colorize()), | ||||
|     }); | ||||
| 
 | ||||
|     logger = createLogger({ | ||||
|         transports: [lokiTransport, consoleTransport], | ||||
|     }); | ||||
| 
 | ||||
|     logger.debug(`Logger initialized with level ${LOG_LEVEL}, Loki host ${LOKI_HOST}`); | ||||
|     return logger; | ||||
| } | ||||
| 
 | ||||
| export function getLogger(): Logger { | ||||
|     logger ||= initializeLogger(); | ||||
|     return logger; | ||||
| } | ||||
							
								
								
									
										69
									
								
								backend/src/logging/mikroOrmLogger.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								backend/src/logging/mikroOrmLogger.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,69 @@ | |||
| import { DefaultLogger, LogContext, LoggerNamespace } from '@mikro-orm/core'; | ||||
| import { getLogger, Logger } from './initalize.js'; | ||||
| import { LokiLabels } from 'loki-logger-ts'; | ||||
| 
 | ||||
| export class MikroOrmLogger extends DefaultLogger { | ||||
|     private logger: Logger = getLogger(); | ||||
| 
 | ||||
|     log(namespace: LoggerNamespace, message: string, context?: LogContext) { | ||||
|         if (!this.isEnabled(namespace, context)) { | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         switch (namespace) { | ||||
|             case 'query': | ||||
|                 this.logger.debug(this.createMessage(namespace, message, context)); | ||||
|                 break; | ||||
|             case 'query-params': | ||||
|                 // TODO Which log level should this be?
 | ||||
|                 this.logger.info(this.createMessage(namespace, message, context)); | ||||
|                 break; | ||||
|             case 'schema': | ||||
|                 this.logger.info(this.createMessage(namespace, message, context)); | ||||
|                 break; | ||||
|             case 'discovery': | ||||
|                 this.logger.debug(this.createMessage(namespace, message, context)); | ||||
|                 break; | ||||
|             case 'info': | ||||
|                 this.logger.info(this.createMessage(namespace, message, context)); | ||||
|                 break; | ||||
|             case 'deprecated': | ||||
|                 this.logger.warn(this.createMessage(namespace, message, context)); | ||||
|                 break; | ||||
|             default: | ||||
|                 switch (context?.level) { | ||||
|                     case 'info': | ||||
|                         this.logger.info(this.createMessage(namespace, message, context)); | ||||
|                         break; | ||||
|                     case 'warning': | ||||
|                         this.logger.warn(message); | ||||
|                         break; | ||||
|                     case 'error': | ||||
|                         this.logger.error(message); | ||||
|                         break; | ||||
|                     default: | ||||
|                         this.logger.debug(message); | ||||
|                         break; | ||||
|                 } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private createMessage(namespace: LoggerNamespace, messageArg: string, context?: LogContext) { | ||||
|         const labels: LokiLabels = { | ||||
|             service: 'ORM', | ||||
|         }; | ||||
| 
 | ||||
|         let message: string; | ||||
|         if (context?.label) { | ||||
|             message = `[${namespace}] (${context?.label}) ${messageArg}`; | ||||
|         } else { | ||||
|             message = `[${namespace}] ${messageArg}`; | ||||
|         } | ||||
| 
 | ||||
|         return { | ||||
|             message: message, | ||||
|             labels: labels, | ||||
|             context: context, | ||||
|         }; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										21
									
								
								backend/src/logging/responseTimeLogger.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								backend/src/logging/responseTimeLogger.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,21 @@ | |||
| import { getLogger, Logger } from './initalize.js'; | ||||
| import { Request, Response } from 'express'; | ||||
| 
 | ||||
| export function responseTimeLogger(req: Request, res: Response, time: number) { | ||||
|     const logger: Logger = getLogger(); | ||||
| 
 | ||||
|     const method = req.method; | ||||
|     const url = req.url; | ||||
|     const status = res.statusCode; | ||||
| 
 | ||||
|     logger.info({ | ||||
|         message: 'Request completed', | ||||
|         method: method, | ||||
|         url: url, | ||||
|         status: status, | ||||
|         responseTime: Number(time), | ||||
|         labels: { | ||||
|             type: 'responseTime', | ||||
|         }, | ||||
|     }); | ||||
| } | ||||
|  | @ -1,35 +1,75 @@ | |||
| import { Options } from '@mikro-orm/core'; | ||||
| import { LoggerOptions, Options } from '@mikro-orm/core'; | ||||
| import { PostgreSqlDriver } from '@mikro-orm/postgresql'; | ||||
| import { EnvVars, getEnvVar, getNumericEnvVar } from './util/envvars.js'; | ||||
| import { SqliteDriver } from '@mikro-orm/sqlite'; | ||||
| import { MikroOrmLogger } from './logging/mikroOrmLogger.js'; | ||||
| import { LOG_LEVEL } from './config.js'; | ||||
| 
 | ||||
| // Import alle entity-bestanden handmatig
 | ||||
| import { User } from './entities/users/user.entity.js'; | ||||
| import { Student } from './entities/users/student.entity.js'; | ||||
| import { Teacher } from './entities/users/teacher.entity.js'; | ||||
| 
 | ||||
| import { Assignment } from './entities/assignments/assignment.entity.js'; | ||||
| import { Group } from './entities/assignments/group.entity.js'; | ||||
| import { Submission } from './entities/assignments/submission.entity.js'; | ||||
| 
 | ||||
| import { Class } from './entities/classes/class.entity.js'; | ||||
| import { ClassJoinRequest } from './entities/classes/class-join-request.entity.js'; | ||||
| import { TeacherInvitation } from './entities/classes/teacher-invitation.entity.js'; | ||||
| 
 | ||||
| import { Attachment } from './entities/content/attachment.entity.js'; | ||||
| import { LearningObject } from './entities/content/learning-object.entity.js'; | ||||
| import { LearningPath } from './entities/content/learning-path.entity.js'; | ||||
| 
 | ||||
| import { Answer } from './entities/questions/answer.entity.js'; | ||||
| import { Question } from './entities/questions/question.entity.js'; | ||||
| 
 | ||||
| const entities = [ | ||||
|     User, | ||||
|     Student, | ||||
|     Teacher, | ||||
|     Assignment, | ||||
|     Group, | ||||
|     Submission, | ||||
|     Class, | ||||
|     ClassJoinRequest, | ||||
|     TeacherInvitation, | ||||
|     Attachment, | ||||
|     LearningObject, | ||||
|     LearningPath, | ||||
|     Answer, | ||||
|     Question, | ||||
| ]; | ||||
| 
 | ||||
| const entities = ['dist/**/*.entity.js']; | ||||
| const entitiesTs = ['src/**/*.entity.ts']; | ||||
| function config(testingMode: boolean = false): Options { | ||||
|     if (testingMode) { | ||||
|         return { | ||||
|             driver: SqliteDriver, | ||||
|             dbName: getEnvVar(EnvVars.DbName), | ||||
|             entities: entities, | ||||
|             entitiesTs: entitiesTs, | ||||
|             // EntitiesTs: entitiesTs,
 | ||||
| 
 | ||||
|             // Workaround: vitest: `TypeError: Unknown file extension ".ts"` (ERR_UNKNOWN_FILE_EXTENSION)
 | ||||
|             // (see https://mikro-orm.io/docs/guide/project-setup#testing-the-endpoint)
 | ||||
|             dynamicImportProvider: (id) => import(id), | ||||
|         }; | ||||
|     } else { | ||||
|         return { | ||||
|             driver: PostgreSqlDriver, | ||||
|             host: getEnvVar(EnvVars.DbHost), | ||||
|             port: getNumericEnvVar(EnvVars.DbPort), | ||||
|             dbName: getEnvVar(EnvVars.DbName), | ||||
|             user: getEnvVar(EnvVars.DbUsername), | ||||
|             password: getEnvVar(EnvVars.DbPassword), | ||||
|             entities: entities, | ||||
|             entitiesTs: entitiesTs, | ||||
|             debug: true, | ||||
|         }; | ||||
|     } | ||||
| 
 | ||||
|     return { | ||||
|         driver: PostgreSqlDriver, | ||||
|         host: getEnvVar(EnvVars.DbHost), | ||||
|         port: getNumericEnvVar(EnvVars.DbPort), | ||||
|         dbName: getEnvVar(EnvVars.DbName), | ||||
|         user: getEnvVar(EnvVars.DbUsername), | ||||
|         password: getEnvVar(EnvVars.DbPassword), | ||||
|         entities: entities, | ||||
|         // EntitiesTs: entitiesTs,
 | ||||
| 
 | ||||
|         // Logging
 | ||||
|         debug: LOG_LEVEL === 'debug', | ||||
|         loggerFactory: (options: LoggerOptions) => new MikroOrmLogger(options), | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| export default config; | ||||
|  |  | |||
|  | @ -1,9 +1,15 @@ | |||
| import { EntityManager, MikroORM } from '@mikro-orm/core'; | ||||
| import config from './mikro-orm.config.js'; | ||||
| import { EnvVars, getEnvVar } from './util/envvars.js'; | ||||
| import { getLogger, Logger } from './logging/initalize.js'; | ||||
| 
 | ||||
| let orm: MikroORM | undefined; | ||||
| export async function initORM(testingMode: boolean = false) { | ||||
|     const logger: Logger = getLogger(); | ||||
| 
 | ||||
|     logger.info('Initializing ORM'); | ||||
|     logger.debug('MikroORM config is', config); | ||||
| 
 | ||||
|     orm = await MikroORM.init(config(testingMode)); | ||||
|     // Update the database scheme if necessary and enabled.
 | ||||
|     if (getEnvVar(EnvVars.DbUpdate)) { | ||||
|  | @ -22,9 +28,7 @@ export async function initORM(testingMode: boolean = false) { | |||
| } | ||||
| export function forkEntityManager(): EntityManager { | ||||
|     if (!orm) { | ||||
|         throw Error( | ||||
|             'Accessing the Entity Manager before the ORM is fully initialized.' | ||||
|         ); | ||||
|         throw Error('Accessing the Entity Manager before the ORM is fully initialized.'); | ||||
|     } | ||||
|     return orm.em.fork(); | ||||
| } | ||||
|  |  | |||
|  | @ -1,23 +1,20 @@ | |||
| import express from 'express' | ||||
| import express from 'express'; | ||||
| const router = express.Router(); | ||||
| 
 | ||||
| // root endpoint used to search objects
 | ||||
| // Root endpoint used to search objects
 | ||||
| router.get('/', (req, res) => { | ||||
|     res.json({ | ||||
|         assignments: [ | ||||
|             '0', | ||||
|             '1', | ||||
|         ] | ||||
|         assignments: ['0', '1'], | ||||
|     }); | ||||
| }); | ||||
| 
 | ||||
| // information about an assignment with id 'id'
 | ||||
| // Information about an assignment with id 'id'
 | ||||
| router.get('/:id', (req, res) => { | ||||
|     res.json({ | ||||
|         id: req.params.id, | ||||
|         title: 'Dit is een test assignment', | ||||
|         description: 'Een korte beschrijving', | ||||
|         groups: [ '0' ], | ||||
|         groups: ['0'], | ||||
|         learningPath: '0', | ||||
|         class: '0', | ||||
|         links: { | ||||
|  | @ -25,30 +22,24 @@ router.get('/:id', (req, res) => { | |||
|             submissions: `${req.baseUrl}/${req.params.id}`, | ||||
|         }, | ||||
|     }); | ||||
| }) | ||||
| }); | ||||
| 
 | ||||
| router.get('/:id/submissions', (req, res) => { | ||||
|     res.json({ | ||||
|         submissions: [ | ||||
|             '0' | ||||
|         ], | ||||
|         submissions: ['0'], | ||||
|     }); | ||||
| }); | ||||
| 
 | ||||
| router.get('/:id/groups', (req, res) => { | ||||
|     res.json({ | ||||
|         groups: [ | ||||
|             '0' | ||||
|         ], | ||||
|         groups: ['0'], | ||||
|     }); | ||||
| }); | ||||
| 
 | ||||
| router.get('/:id/questions', (req, res) => { | ||||
|     res.json({ | ||||
|         questions: [ | ||||
|             '0' | ||||
|         ], | ||||
|         questions: ['0'], | ||||
|     }); | ||||
| }); | ||||
| 
 | ||||
| export default router | ||||
| export default router; | ||||
|  |  | |||
|  | @ -1,55 +1,46 @@ | |||
| import express from 'express' | ||||
| import express from 'express'; | ||||
| const router = express.Router(); | ||||
| 
 | ||||
| // root endpoint used to search objects
 | ||||
| // Root endpoint used to search objects
 | ||||
| router.get('/', (req, res) => { | ||||
|     res.json({ | ||||
|         classes: [ | ||||
|             '0', | ||||
|             '1', | ||||
|         ] | ||||
|         classes: ['0', '1'], | ||||
|     }); | ||||
| }); | ||||
| 
 | ||||
| // information about an class with id 'id'
 | ||||
| // Information about an class with id 'id'
 | ||||
| router.get('/:id', (req, res) => { | ||||
|     res.json({ | ||||
|         id: req.params.id, | ||||
|         displayName: 'Klas 4B', | ||||
|         teachers: [ '0' ], | ||||
|         students: [ '0' ], | ||||
|         joinRequests: [ '0' ], | ||||
|         teachers: ['0'], | ||||
|         students: ['0'], | ||||
|         joinRequests: ['0'], | ||||
|         links: { | ||||
|             self: `${req.baseUrl}/${req.params.id}`, | ||||
|             classes: `${req.baseUrl}/${req.params.id}/invitations`, | ||||
|             questions: `${req.baseUrl}/${req.params.id}/assignments`, | ||||
|             students: `${req.baseUrl}/${req.params.id}/students`, | ||||
|         } | ||||
|         }, | ||||
|     }); | ||||
| }) | ||||
| }); | ||||
| 
 | ||||
| router.get('/:id/invitations', (req, res) => { | ||||
|     res.json({ | ||||
|         invitations: [  | ||||
|             '0' | ||||
|         ], | ||||
|         invitations: ['0'], | ||||
|     }); | ||||
| }) | ||||
| }); | ||||
| 
 | ||||
| router.get('/:id/assignments', (req, res) => { | ||||
|     res.json({ | ||||
|         assignments: [  | ||||
|             '0' | ||||
|         ], | ||||
|         assignments: ['0'], | ||||
|     }); | ||||
| }) | ||||
| }); | ||||
| 
 | ||||
| router.get('/:id/students', (req, res) => { | ||||
|     res.json({ | ||||
|         students: [  | ||||
|             '0' | ||||
|         ], | ||||
|         students: ['0'], | ||||
|     }); | ||||
| }) | ||||
| }); | ||||
| 
 | ||||
| export default router | ||||
| export default router; | ||||
|  |  | |||
|  | @ -1,34 +1,31 @@ | |||
| import express from 'express' | ||||
| import express from 'express'; | ||||
| const router = express.Router(); | ||||
| 
 | ||||
| // root endpoint used to search objects
 | ||||
| // Root endpoint used to search objects
 | ||||
| router.get('/', (req, res) => { | ||||
|     res.json({ | ||||
|         groups: [ | ||||
|             '0', | ||||
|             '1', | ||||
|         ] | ||||
|         groups: ['0', '1'], | ||||
|     }); | ||||
| }); | ||||
| 
 | ||||
| // information about a group (members, ... [TODO DOC])
 | ||||
| // Information about a group (members, ... [TODO DOC])
 | ||||
| router.get('/:id', (req, res) => { | ||||
|     res.json({ | ||||
|         id: req.params.id, | ||||
|         assignment: '0', | ||||
|         students: [ '0' ], | ||||
|         submissions: [ '0' ], | ||||
|         // reference to other endpoint
 | ||||
|         // should be less hardcoded
 | ||||
|         questions: `/group/${req.params.id}/question`,  | ||||
|         students: ['0'], | ||||
|         submissions: ['0'], | ||||
|         // Reference to other endpoint
 | ||||
|         // Should be less hardcoded
 | ||||
|         questions: `/group/${req.params.id}/question`, | ||||
|     }); | ||||
| }) | ||||
| }); | ||||
| 
 | ||||
| // the list of questions a group has made
 | ||||
| // The list of questions a group has made
 | ||||
| router.get('/:id/question', (req, res) => { | ||||
|     res.json({ | ||||
|         questions: [ '0' ], | ||||
|         questions: ['0'], | ||||
|     }); | ||||
| }) | ||||
| }); | ||||
| 
 | ||||
| export default router | ||||
| export default router; | ||||
|  |  | |||
							
								
								
									
										24
									
								
								backend/src/routes/learningObjects.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								backend/src/routes/learningObjects.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,24 @@ | |||
| import express from 'express'; | ||||
| import { getAllLearningObjects, getLearningObject } from '../controllers/learningObjects.js'; | ||||
| 
 | ||||
| const router = express.Router(); | ||||
| 
 | ||||
| // DWENGO learning objects
 | ||||
| 
 | ||||
| // Queries: hruid(path), full, language
 | ||||
| // Route to fetch list of learning objects based on hruid of learning path
 | ||||
| 
 | ||||
| // Route 1: list of object hruids
 | ||||
| // Example 1: http://localhost:3000/learningObject?hruid=un_artificiele_intelligentie
 | ||||
| 
 | ||||
| // Route 2: list of object data
 | ||||
| // Example 2: http://localhost:3000/learningObject?full=true&hruid=un_artificiele_intelligentie
 | ||||
| router.get('/', getAllLearningObjects); | ||||
| 
 | ||||
| // Parameter: hruid of learning object
 | ||||
| // Query: language
 | ||||
| // Route to fetch data of one learning object based on its hruid
 | ||||
| // Example: http://localhost:3000/learningObject/un_ai7
 | ||||
| router.get('/:hruid', getLearningObject); | ||||
| 
 | ||||
| export default router; | ||||
							
								
								
									
										27
									
								
								backend/src/routes/learningPaths.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								backend/src/routes/learningPaths.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,27 @@ | |||
| import express from 'express'; | ||||
| import { getLearningPaths } from '../controllers/learningPaths.js'; | ||||
| 
 | ||||
| const router = express.Router(); | ||||
| 
 | ||||
| // DWENGO learning paths
 | ||||
| 
 | ||||
| // Route 1: no query
 | ||||
| // Fetch all learning paths
 | ||||
| // Example 1: http://localhost:3000/learningPath
 | ||||
| 
 | ||||
| // Unified route for fetching learning paths
 | ||||
| // Route 2: Query: hruid (list), language
 | ||||
| // Fetch learning paths based on hruid list
 | ||||
| // Example 2: http://localhost:3000/learningPath?hruid=pn_werking&hruid=art1
 | ||||
| 
 | ||||
| // Query: search, language
 | ||||
| // Route to fetch learning paths based on a searchterm
 | ||||
| // Example 3: http://localhost:3000/learningPath?search=robot
 | ||||
| 
 | ||||
| // Query: theme, anguage
 | ||||
| // Route to fetch learning paths based on a theme
 | ||||
| // Example: http://localhost:3000/learningPath?theme=kiks
 | ||||
| 
 | ||||
| router.get('/', getLearningPaths); | ||||
| 
 | ||||
| export default router; | ||||
|  | @ -1,17 +1,14 @@ | |||
| import express from 'express' | ||||
| import express from 'express'; | ||||
| const router = express.Router(); | ||||
| 
 | ||||
| // root endpoint used to search objects
 | ||||
| // Root endpoint used to search objects
 | ||||
| router.get('/', (req, res) => { | ||||
|     res.json({ | ||||
|         questions: [ | ||||
|             '0', | ||||
|             '1', | ||||
|         ] | ||||
|         questions: ['0', '1'], | ||||
|     }); | ||||
| }); | ||||
| 
 | ||||
| // information about an question with id 'id'
 | ||||
| // Information about an question with id 'id'
 | ||||
| router.get('/:id', (req, res) => { | ||||
|     res.json({ | ||||
|         id: req.params.id, | ||||
|  | @ -23,16 +20,14 @@ router.get('/:id', (req, res) => { | |||
|         links: { | ||||
|             self: `${req.baseUrl}/${req.params.id}`, | ||||
|             answers: `${req.baseUrl}/${req.params.id}/answers`, | ||||
|         } | ||||
|         }, | ||||
|     }); | ||||
| }) | ||||
| }); | ||||
| 
 | ||||
| router.get('/:id/answers', (req, res) => { | ||||
|     res.json({ | ||||
|         answers: [ | ||||
|             '0' | ||||
|         ], | ||||
|     }) | ||||
| }) | ||||
|         answers: ['0'], | ||||
|     }); | ||||
| }); | ||||
| 
 | ||||
| export default router | ||||
| export default router; | ||||
|  |  | |||
|  | @ -1,17 +1,14 @@ | |||
| import express from 'express' | ||||
| import express from 'express'; | ||||
| const router = express.Router(); | ||||
| 
 | ||||
| // root endpoint used to search objects
 | ||||
| // Root endpoint used to search objects
 | ||||
| router.get('/', (req, res) => { | ||||
|     res.json({ | ||||
|         students: [ | ||||
|             '0', | ||||
|             '1', | ||||
|         ] | ||||
|         students: ['0', '1'], | ||||
|     }); | ||||
| }); | ||||
| 
 | ||||
| // information about a student's profile
 | ||||
| // Information about a student's profile
 | ||||
| router.get('/:id', (req, res) => { | ||||
|     res.json({ | ||||
|         id: req.params.id, | ||||
|  | @ -27,33 +24,32 @@ router.get('/:id', (req, res) => { | |||
|     }); | ||||
| }); | ||||
| 
 | ||||
| // the list of classes a student is in
 | ||||
| // The list of classes a student is in
 | ||||
| router.get('/:id/classes', (req, res) => { | ||||
|     res.json({ | ||||
|         classes: [ '0' ], | ||||
|         classes: ['0'], | ||||
|     }); | ||||
| }) | ||||
| }); | ||||
| 
 | ||||
| // the list of submissions a student has made
 | ||||
| // The list of submissions a student has made
 | ||||
| router.get('/:id/submissions', (req, res) => { | ||||
|     res.json({ | ||||
|         submissions: [ '0' ], | ||||
|         submissions: ['0'], | ||||
|     }); | ||||
| }) | ||||
| }); | ||||
| 
 | ||||
| 
 | ||||
| // the list of assignments a student has
 | ||||
| // The list of assignments a student has
 | ||||
| router.get('/:id/assignments', (req, res) => { | ||||
|     res.json({ | ||||
|         assignments: [ '0' ], | ||||
|         assignments: ['0'], | ||||
|     }); | ||||
| }) | ||||
| }); | ||||
| 
 | ||||
| // the list of groups a student is in
 | ||||
| // The list of groups a student is in
 | ||||
| router.get('/:id/groups', (req, res) => { | ||||
|     res.json({ | ||||
|         groups: [ '0' ], | ||||
|         groups: ['0'], | ||||
|     }); | ||||
| }) | ||||
| }); | ||||
| 
 | ||||
| export default router | ||||
| export default router; | ||||
|  |  | |||
|  | @ -1,17 +1,14 @@ | |||
| import express from 'express' | ||||
| import express from 'express'; | ||||
| const router = express.Router(); | ||||
| 
 | ||||
| // root endpoint used to search objects
 | ||||
| // Root endpoint used to search objects
 | ||||
| router.get('/', (req, res) => { | ||||
|     res.json({ | ||||
|         submissions: [ | ||||
|             '0', | ||||
|             '1', | ||||
|         ] | ||||
|         submissions: ['0', '1'], | ||||
|     }); | ||||
| }); | ||||
| 
 | ||||
| // information about an submission with id 'id'
 | ||||
| // Information about an submission with id 'id'
 | ||||
| router.get('/:id', (req, res) => { | ||||
|     res.json({ | ||||
|         id: req.params.id, | ||||
|  | @ -21,6 +18,6 @@ router.get('/:id', (req, res) => { | |||
|         content: 'Wortel 2 is rationeel', | ||||
|         learningObject: '0', | ||||
|     }); | ||||
| }) | ||||
| }); | ||||
| 
 | ||||
| export default router | ||||
| export default router; | ||||
|  |  | |||
|  | @ -1,17 +1,14 @@ | |||
| import express from 'express' | ||||
| import express from 'express'; | ||||
| const router = express.Router(); | ||||
| 
 | ||||
| // root endpoint used to search objects
 | ||||
| // Root endpoint used to search objects
 | ||||
| router.get('/', (req, res) => { | ||||
|     res.json({ | ||||
|         teachers: [ | ||||
|             '0', | ||||
|             '1', | ||||
|         ] | ||||
|         teachers: ['0', '1'], | ||||
|     }); | ||||
| }); | ||||
| 
 | ||||
| // information about a teacher
 | ||||
| // Information about a teacher
 | ||||
| router.get('/:id', (req, res) => { | ||||
|     res.json({ | ||||
|         id: req.params.id, | ||||
|  | @ -25,34 +22,27 @@ router.get('/:id', (req, res) => { | |||
|             invitations: `${req.baseUrl}/${req.params.id}/invitations`, | ||||
|         }, | ||||
|     }); | ||||
| }) | ||||
| }); | ||||
| 
 | ||||
| // the questions students asked a teacher
 | ||||
| // The questions students asked a teacher
 | ||||
| router.get('/:id/questions', (req, res) => { | ||||
|     res.json({ | ||||
|         questions: [ | ||||
|             '0' | ||||
|         ], | ||||
|         questions: ['0'], | ||||
|     }); | ||||
| }); | ||||
| 
 | ||||
| // invitations to other classes a teacher received
 | ||||
| // Invitations to other classes a teacher received
 | ||||
| router.get('/:id/invitations', (req, res) => { | ||||
|     res.json({ | ||||
|         invitations: [ | ||||
|             '0' | ||||
|         ], | ||||
|         invitations: ['0'], | ||||
|     }); | ||||
| }); | ||||
| 
 | ||||
| // a list with ids of classes a teacher is in
 | ||||
| // A list with ids of classes a teacher is in
 | ||||
| router.get('/:id/classes', (req, res) => { | ||||
|     res.json({ | ||||
|         classes: [ | ||||
|             '0' | ||||
|         ], | ||||
|         classes: ['0'], | ||||
|     }); | ||||
| }); | ||||
| 
 | ||||
| 
 | ||||
| export default router | ||||
| export default router; | ||||
|  |  | |||
|  | @ -3,7 +3,12 @@ import { getThemes, getThemeByTitle } from '../controllers/themes.js'; | |||
| 
 | ||||
| const router = express.Router(); | ||||
| 
 | ||||
| // Query: language
 | ||||
| //  Route to fetch list of {key, title, description, image} themes in their respective language
 | ||||
| router.get('/', getThemes); | ||||
| 
 | ||||
| // Arg: theme (key)
 | ||||
| //  Route to fetch list of hruids based on theme
 | ||||
| router.get('/:theme', getThemeByTitle); | ||||
| 
 | ||||
| export default router; | ||||
|  |  | |||
							
								
								
									
										91
									
								
								backend/src/services/learningObjects.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										91
									
								
								backend/src/services/learningObjects.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,91 @@ | |||
| import { DWENGO_API_BASE } from '../config.js'; | ||||
| import { fetchWithLogging } from '../util/apiHelper.js'; | ||||
| import { FilteredLearningObject, LearningObjectMetadata, LearningObjectNode, LearningPathResponse } from '../interfaces/learningPath.js'; | ||||
| import { fetchLearningPaths } from './learningPaths.js'; | ||||
| import { getLogger, Logger } from '../logging/initalize.js'; | ||||
| 
 | ||||
| const logger: Logger = getLogger(); | ||||
| 
 | ||||
| function filterData(data: LearningObjectMetadata, htmlUrl: string): FilteredLearningObject { | ||||
|     return { | ||||
|         key: data.hruid, // Hruid learningObject (not path)
 | ||||
|         _id: data._id, | ||||
|         uuid: data.uuid, | ||||
|         version: data.version, | ||||
|         title: data.title, | ||||
|         htmlUrl, // Url to fetch html content
 | ||||
|         language: data.language, | ||||
|         difficulty: data.difficulty, | ||||
|         estimatedTime: data.estimated_time, | ||||
|         available: data.available, | ||||
|         teacherExclusive: data.teacher_exclusive, | ||||
|         educationalGoals: data.educational_goals, // List with learningObjects
 | ||||
|         keywords: data.keywords, // For search
 | ||||
|         description: data.description, // For search (not an actual description)
 | ||||
|         targetAges: data.target_ages, | ||||
|         contentType: data.content_type, // Markdown, image, audio, etc.
 | ||||
|         contentLocation: data.content_location, // If content type extern
 | ||||
|         skosConcepts: data.skos_concepts, | ||||
|         returnValue: data.return_value, // Callback response information
 | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * Fetches a single learning object by its HRUID | ||||
|  */ | ||||
| export async function getLearningObjectById(hruid: string, language: string): Promise<FilteredLearningObject | null> { | ||||
|     const metadataUrl = `${DWENGO_API_BASE}/learningObject/getMetadata?hruid=${hruid}&language=${language}`; | ||||
|     const metadata = await fetchWithLogging<LearningObjectMetadata>( | ||||
|         metadataUrl, | ||||
|         `Metadata for Learning Object HRUID "${hruid}" (language ${language})` | ||||
|     ); | ||||
| 
 | ||||
|     if (!metadata) { | ||||
|         logger.warn(`⚠️ WARNING: Learning object "${hruid}" not found.`); | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
|     const htmlUrl = `${DWENGO_API_BASE}/learningObject/getRaw?hruid=${hruid}&language=${language}`; | ||||
|     return filterData(metadata, htmlUrl); | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * Generic function to fetch learning objects (full data or just HRUIDs) | ||||
|  */ | ||||
| async function fetchLearningObjects(hruid: string, full: boolean, language: string): Promise<FilteredLearningObject[] | string[]> { | ||||
|     try { | ||||
|         const learningPathResponse: LearningPathResponse = await fetchLearningPaths([hruid], language, `Learning path for HRUID "${hruid}"`); | ||||
| 
 | ||||
|         if (!learningPathResponse.success || !learningPathResponse.data?.length) { | ||||
|             logger.warn(`⚠️ WARNING: Learning path "${hruid}" exists but contains no learning objects.`); | ||||
|             return []; | ||||
|         } | ||||
| 
 | ||||
|         const nodes: LearningObjectNode[] = learningPathResponse.data[0].nodes; | ||||
| 
 | ||||
|         if (!full) { | ||||
|             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) | ||||
|         ); | ||||
|     } catch (error) { | ||||
|         logger.error('❌ Error fetching learning objects:', error); | ||||
|         return []; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * Fetch full learning object data (metadata) | ||||
|  */ | ||||
| export async function getLearningObjectsFromPath(hruid: string, language: string): Promise<FilteredLearningObject[]> { | ||||
|     return (await fetchLearningObjects(hruid, true, language)) as FilteredLearningObject[]; | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * Fetch only learning object HRUIDs | ||||
|  */ | ||||
| export async function getLearningObjectIdsFromPath(hruid: string, language: string): Promise<string[]> { | ||||
|     return (await fetchLearningObjects(hruid, false, language)) as string[]; | ||||
| } | ||||
							
								
								
									
										46
									
								
								backend/src/services/learningPaths.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								backend/src/services/learningPaths.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,46 @@ | |||
| import { fetchWithLogging } from '../util/apiHelper.js'; | ||||
| import { DWENGO_API_BASE } from '../config.js'; | ||||
| import { LearningPath, LearningPathResponse } from '../interfaces/learningPath.js'; | ||||
| import { getLogger, Logger } from '../logging/initalize.js'; | ||||
| 
 | ||||
| const logger: Logger = getLogger(); | ||||
| 
 | ||||
| export async function fetchLearningPaths(hruids: string[], language: string, source: string): Promise<LearningPathResponse> { | ||||
|     if (hruids.length === 0) { | ||||
|         return { | ||||
|             success: false, | ||||
|             source, | ||||
|             data: null, | ||||
|             message: `No HRUIDs provided for ${source}.`, | ||||
|         }; | ||||
|     } | ||||
| 
 | ||||
|     const apiUrl = `${DWENGO_API_BASE}/learningPath/getPathsFromIdList`; | ||||
|     const params = { pathIdList: JSON.stringify({ hruids }), language }; | ||||
| 
 | ||||
|     const learningPaths = await fetchWithLogging<LearningPath[]>(apiUrl, `Learning paths for ${source}`, params); | ||||
| 
 | ||||
|     if (!learningPaths || learningPaths.length === 0) { | ||||
|         logger.warn(`⚠️ WARNING: No learning paths found for ${source}.`); | ||||
|         return { | ||||
|             success: false, | ||||
|             source, | ||||
|             data: [], | ||||
|             message: `No learning paths found for ${source}.`, | ||||
|         }; | ||||
|     } | ||||
| 
 | ||||
|     return { | ||||
|         success: true, | ||||
|         source, | ||||
|         data: learningPaths, | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| export async function searchLearningPaths(query: string, language: string): Promise<LearningPath[]> { | ||||
|     const apiUrl = `${DWENGO_API_BASE}/learningPath/search`; | ||||
|     const params = { all: query, language }; | ||||
| 
 | ||||
|     const searchResults = await fetchWithLogging<LearningPath[]>(apiUrl, `Search learning paths with query "${query}"`, params); | ||||
|     return searchResults ?? []; | ||||
| } | ||||
							
								
								
									
										35
									
								
								backend/src/util/apiHelper.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								backend/src/util/apiHelper.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,35 @@ | |||
| import axios, { AxiosRequestConfig } from 'axios'; | ||||
| import { getLogger, Logger } from '../logging/initalize.js'; | ||||
| 
 | ||||
| const logger: Logger = getLogger(); | ||||
| 
 | ||||
| /** | ||||
|  * Utility function to fetch data from an API endpoint with error handling. | ||||
|  * Logs errors but does NOT throw exceptions to keep the system running. | ||||
|  * | ||||
|  * @param url The API endpoint to fetch from. | ||||
|  * @param description A short description of what is being fetched (for logging). | ||||
|  * @param params | ||||
|  * @returns The response data if successful, or null if an error occurs. | ||||
|  */ | ||||
| export async function fetchWithLogging<T>(url: string, description: string, params?: Record<string, any>): Promise<T | null> { | ||||
|     try { | ||||
|         const config: AxiosRequestConfig = params ? { params } : {}; | ||||
| 
 | ||||
|         const response = await axios.get<T>(url, config); | ||||
|         return response.data; | ||||
|     } catch (error: any) { | ||||
|         if (error.response) { | ||||
|             if (error.response.status === 404) { | ||||
|                 logger.debug(`❌ ERROR: ${description} not found (404) at "${url}".`); | ||||
|             } else { | ||||
|                 logger.debug( | ||||
|                     `❌ ERROR: Failed to fetch ${description}. Status: ${error.response.status} - ${error.response.statusText} (URL: "${url}")` | ||||
|                 ); | ||||
|             } | ||||
|         } else { | ||||
|             logger.debug(`❌ ERROR: Network or unexpected error when fetching ${description}:`, error.message); | ||||
|         } | ||||
|         return null; | ||||
|     } | ||||
| } | ||||
|  | @ -49,9 +49,7 @@ export function getNumericEnvVar(envVar: EnvVar): number { | |||
|     const valueString = getEnvVar(envVar); | ||||
|     const value = parseInt(valueString); | ||||
|     if (isNaN(value)) { | ||||
|         throw new Error( | ||||
|             `Invalid value for environment variable ${envVar.key}: ${valueString}. Expected a number.` | ||||
|         ); | ||||
|         throw new Error(`Invalid value for environment variable ${envVar.key}: ${valueString}. Expected a number.`); | ||||
|     } else { | ||||
|         return value; | ||||
|     } | ||||
|  |  | |||
							
								
								
									
										19
									
								
								backend/src/util/translationHelper.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								backend/src/util/translationHelper.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,19 @@ | |||
| import fs from 'fs'; | ||||
| import path from 'path'; | ||||
| import yaml from 'js-yaml'; | ||||
| import { FALLBACK_LANG } from '../config.js'; | ||||
| import { getLogger, Logger } from '../logging/initalize.js'; | ||||
| 
 | ||||
| const logger: Logger = getLogger(); | ||||
| 
 | ||||
| export function loadTranslations<T>(language: string): T { | ||||
|     try { | ||||
|         const filePath = path.join(process.cwd(), '_i18n', `${language}.yml`); | ||||
|         const yamlFile = fs.readFileSync(filePath, 'utf8'); | ||||
|         return yaml.load(yamlFile) as T; | ||||
|     } catch (error) { | ||||
|         logger.warn(`Cannot load translation for ${language}, fallen back to dutch`, error); | ||||
|         const fallbackPath = path.join(process.cwd(), '_i18n', `${FALLBACK_LANG}.yml`); | ||||
|         return yaml.load(fs.readFileSync(fallbackPath, 'utf8')) as T; | ||||
|     } | ||||
| } | ||||
		Reference in a new issue
	
	 Gerald Schmittinger
						Gerald Schmittinger