refactor(common): Language
This commit is contained in:
		
							parent
							
								
									5a90862098
								
							
						
					
					
						commit
						bef6c6f75b
					
				
					 48 changed files with 71 additions and 56 deletions
				
			
		|  | @ -2,11 +2,11 @@ import { Request, Response } from 'express'; | |||
| import { FALLBACK_LANG } from '../config.js'; | ||||
| import learningObjectService from '../services/learning-objects/learning-object-service.js'; | ||||
| import { EnvVars, getEnvVar } from '../util/envvars.js'; | ||||
| import { Language } from '../entities/content/language.js'; | ||||
| import attachmentService from '../services/learning-objects/attachment-service.js'; | ||||
| import { NotFoundError } from '@mikro-orm/core'; | ||||
| import { BadRequestException } from '../exceptions/bad-request-exception.js'; | ||||
| import { FilteredLearningObject, LearningObjectIdentifier, LearningPathIdentifier } from 'dwengo-1-common/src/interfaces/learning-content'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language.js'; | ||||
| 
 | ||||
| function getLearningObjectIdentifierFromRequest(req: Request): LearningObjectIdentifier { | ||||
|     if (!req.params.hruid) { | ||||
|  |  | |||
|  | @ -2,7 +2,6 @@ import { Request, Response } from 'express'; | |||
| import { themes } from '../data/themes.js'; | ||||
| import { FALLBACK_LANG } from '../config.js'; | ||||
| import learningPathService from '../services/learning-paths/learning-path-service.js'; | ||||
| import { Language } from '../entities/content/language.js'; | ||||
| import { | ||||
|     PersonalizationTarget, | ||||
|     personalizedForGroup, | ||||
|  | @ -10,6 +9,7 @@ import { | |||
| } from '../services/learning-paths/learning-path-personalization-util.js'; | ||||
| import { BadRequestException } from '../exceptions/bad-request-exception.js'; | ||||
| import { NotFoundException } from '../exceptions/not-found-exception.js'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language.js'; | ||||
| 
 | ||||
| /** | ||||
|  * Fetch learning paths based on query parameters. | ||||
|  |  | |||
|  | @ -2,8 +2,8 @@ import { Request, Response } from 'express'; | |||
| import { createQuestion, deleteQuestion, getAllQuestions, getAnswersByQuestion, getQuestion } from '../services/questions.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 { QuestionDTO, QuestionId } from 'dwengo-1-common/src/interfaces/question'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language.js'; | ||||
| 
 | ||||
| function getObjectId(req: Request, res: Response): LearningObjectIdentifier | null { | ||||
|     const { hruid, version } = req.params; | ||||
|  |  | |||
|  | @ -1,8 +1,8 @@ | |||
| import { Request, Response } from 'express'; | ||||
| import { createSubmission, deleteSubmission, getSubmission } from '../services/submissions.js'; | ||||
| import { Language, languageMap } from '../entities/content/language.js'; | ||||
| 
 | ||||
| import { SubmissionDTO } from 'dwengo-1-common/src/interfaces/submission'; | ||||
| import { Language, languageMap } from 'dwengo-1-common/src/util/language.js'; | ||||
| 
 | ||||
| interface SubmissionParams { | ||||
|     hruid: string; | ||||
|  |  | |||
|  | @ -1,7 +1,7 @@ | |||
| import { DwengoEntityRepository } from '../dwengo-entity-repository.js'; | ||||
| import { Attachment } from '../../entities/content/attachment.entity.js'; | ||||
| import { Language } from '../../entities/content/language'; | ||||
| import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language.js'; | ||||
| 
 | ||||
| export class AttachmentRepository extends DwengoEntityRepository<Attachment> { | ||||
|     public findByLearningObjectIdAndName(learningObjectId: LearningObjectIdentifier, name: string): Promise<Attachment | null> { | ||||
|  |  | |||
|  | @ -1,7 +1,6 @@ | |||
| import { DwengoEntityRepository } from '../dwengo-entity-repository.js'; | ||||
| import { LearningObject } from '../../entities/content/learning-object.entity.js'; | ||||
| import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier.js'; | ||||
| import { Language } from '../../entities/content/language.js'; | ||||
| import { Teacher } from '../../entities/users/teacher.entity.js'; | ||||
| 
 | ||||
| export class LearningObjectRepository extends DwengoEntityRepository<LearningObject> { | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| import { DwengoEntityRepository } from '../dwengo-entity-repository.js'; | ||||
| import { LearningPath } from '../../entities/content/learning-path.entity.js'; | ||||
| import { Language } from '../../entities/content/language.js'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language.js'; | ||||
| 
 | ||||
| export class LearningPathRepository extends DwengoEntityRepository<LearningPath> { | ||||
|     public findByHruidAndLanguage(hruid: string, language: Language): Promise<LearningPath | null> { | ||||
|  |  | |||
|  | @ -1,8 +1,8 @@ | |||
| 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'; | ||||
| import { AssignmentRepository } from '../../data/assignments/assignment-repository.js'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language.js'; | ||||
| 
 | ||||
| @Entity({ | ||||
|     repository: () => AssignmentRepository, | ||||
|  |  | |||
|  | @ -1,8 +1,8 @@ | |||
| import { Student } from '../users/student.entity.js'; | ||||
| import { Group } from './group.entity.js'; | ||||
| import { Entity, Enum, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'; | ||||
| import { Language } from '../content/language.js'; | ||||
| import { SubmissionRepository } from '../../data/assignments/submission-repository.js'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language.js'; | ||||
| 
 | ||||
| @Entity({ repository: () => SubmissionRepository }) | ||||
| export class Submission { | ||||
|  |  | |||
|  | @ -1,193 +0,0 @@ | |||
| export enum Language { | ||||
|     Afar = 'aa', | ||||
|     Abkhazian = 'ab', | ||||
|     Afrikaans = 'af', | ||||
|     Akan = 'ak', | ||||
|     Albanian = 'sq', | ||||
|     Amharic = 'am', | ||||
|     Arabic = 'ar', | ||||
|     Aragonese = 'an', | ||||
|     Armenian = 'hy', | ||||
|     Assamese = 'as', | ||||
|     Avaric = 'av', | ||||
|     Avestan = 'ae', | ||||
|     Aymara = 'ay', | ||||
|     Azerbaijani = 'az', | ||||
|     Bashkir = 'ba', | ||||
|     Bambara = 'bm', | ||||
|     Basque = 'eu', | ||||
|     Belarusian = 'be', | ||||
|     Bengali = 'bn', | ||||
|     Bihari = 'bh', | ||||
|     Bislama = 'bi', | ||||
|     Bosnian = 'bs', | ||||
|     Breton = 'br', | ||||
|     Bulgarian = 'bg', | ||||
|     Burmese = 'my', | ||||
|     Catalan = 'ca', | ||||
|     Chamorro = 'ch', | ||||
|     Chechen = 'ce', | ||||
|     Chinese = 'zh', | ||||
|     ChurchSlavic = 'cu', | ||||
|     Chuvash = 'cv', | ||||
|     Cornish = 'kw', | ||||
|     Corsican = 'co', | ||||
|     Cree = 'cr', | ||||
|     Czech = 'cs', | ||||
|     Danish = 'da', | ||||
|     Divehi = 'dv', | ||||
|     Dutch = 'nl', | ||||
|     Dzongkha = 'dz', | ||||
|     English = 'en', | ||||
|     Esperanto = 'eo', | ||||
|     Estonian = 'et', | ||||
|     Ewe = 'ee', | ||||
|     Faroese = 'fo', | ||||
|     Fijian = 'fj', | ||||
|     Finnish = 'fi', | ||||
|     French = 'fr', | ||||
|     Frisian = 'fy', | ||||
|     Fulah = 'ff', | ||||
|     Georgian = 'ka', | ||||
|     German = 'de', | ||||
|     Gaelic = 'gd', | ||||
|     Irish = 'ga', | ||||
|     Galician = 'gl', | ||||
|     Manx = 'gv', | ||||
|     Greek = 'el', | ||||
|     Guarani = 'gn', | ||||
|     Gujarati = 'gu', | ||||
|     Haitian = 'ht', | ||||
|     Hausa = 'ha', | ||||
|     Hebrew = 'he', | ||||
|     Herero = 'hz', | ||||
|     Hindi = 'hi', | ||||
|     HiriMotu = 'ho', | ||||
|     Croatian = 'hr', | ||||
|     Hungarian = 'hu', | ||||
|     Igbo = 'ig', | ||||
|     Icelandic = 'is', | ||||
|     Ido = 'io', | ||||
|     SichuanYi = 'ii', | ||||
|     Inuktitut = 'iu', | ||||
|     Interlingue = 'ie', | ||||
|     Interlingua = 'ia', | ||||
|     Indonesian = 'id', | ||||
|     Inupiaq = 'ik', | ||||
|     Italian = 'it', | ||||
|     Javanese = 'jv', | ||||
|     Japanese = 'ja', | ||||
|     Kalaallisut = 'kl', | ||||
|     Kannada = 'kn', | ||||
|     Kashmiri = 'ks', | ||||
|     Kanuri = 'kr', | ||||
|     Kazakh = 'kk', | ||||
|     Khmer = 'km', | ||||
|     Kikuyu = 'ki', | ||||
|     Kinyarwanda = 'rw', | ||||
|     Kirghiz = 'ky', | ||||
|     Komi = 'kv', | ||||
|     Kongo = 'kg', | ||||
|     Korean = 'ko', | ||||
|     Kuanyama = 'kj', | ||||
|     Kurdish = 'ku', | ||||
|     Lao = 'lo', | ||||
|     Latin = 'la', | ||||
|     Latvian = 'lv', | ||||
|     Limburgan = 'li', | ||||
|     Lingala = 'ln', | ||||
|     Lithuanian = 'lt', | ||||
|     Luxembourgish = 'lb', | ||||
|     LubaKatanga = 'lu', | ||||
|     Ganda = 'lg', | ||||
|     Macedonian = 'mk', | ||||
|     Marshallese = 'mh', | ||||
|     Malayalam = 'ml', | ||||
|     Maori = 'mi', | ||||
|     Marathi = 'mr', | ||||
|     Malay = 'ms', | ||||
|     Malagasy = 'mg', | ||||
|     Maltese = 'mt', | ||||
|     Mongolian = 'mn', | ||||
|     Nauru = 'na', | ||||
|     Navajo = 'nv', | ||||
|     SouthNdebele = 'nr', | ||||
|     NorthNdebele = 'nd', | ||||
|     Ndonga = 'ng', | ||||
|     Nepali = 'ne', | ||||
|     NorwegianNynorsk = 'nn', | ||||
|     NorwegianBokmal = 'nb', | ||||
|     Norwegian = 'no', | ||||
|     Chichewa = 'ny', | ||||
|     Occitan = 'oc', | ||||
|     Ojibwa = 'oj', | ||||
|     Oriya = 'or', | ||||
|     Oromo = 'om', | ||||
|     Ossetian = 'os', | ||||
|     Punjabi = 'pa', | ||||
|     Persian = 'fa', | ||||
|     Pali = 'pi', | ||||
|     Polish = 'pl', | ||||
|     Portuguese = 'pt', | ||||
|     Pashto = 'ps', | ||||
|     Quechua = 'qu', | ||||
|     Romansh = 'rm', | ||||
|     Romanian = 'ro', | ||||
|     Rundi = 'rn', | ||||
|     Russian = 'ru', | ||||
|     Sango = 'sg', | ||||
|     Sanskrit = 'sa', | ||||
|     Sinhala = 'si', | ||||
|     Slovak = 'sk', | ||||
|     Slovenian = 'sl', | ||||
|     NorthernSami = 'se', | ||||
|     Samoan = 'sm', | ||||
|     Shona = 'sn', | ||||
|     Sindhi = 'sd', | ||||
|     Somali = 'so', | ||||
|     Sotho = 'st', | ||||
|     Spanish = 'es', | ||||
|     Sardinian = 'sc', | ||||
|     Serbian = 'sr', | ||||
|     Swati = 'ss', | ||||
|     Sundanese = 'su', | ||||
|     Swahili = 'sw', | ||||
|     Swedish = 'sv', | ||||
|     Tahitian = 'ty', | ||||
|     Tamil = 'ta', | ||||
|     Tatar = 'tt', | ||||
|     Telugu = 'te', | ||||
|     Tajik = 'tg', | ||||
|     Tagalog = 'tl', | ||||
|     Thai = 'th', | ||||
|     Tibetan = 'bo', | ||||
|     Tigrinya = 'ti', | ||||
|     Tonga = 'to', | ||||
|     Tswana = 'tn', | ||||
|     Tsonga = 'ts', | ||||
|     Turkmen = 'tk', | ||||
|     Turkish = 'tr', | ||||
|     Twi = 'tw', | ||||
|     Uighur = 'ug', | ||||
|     Ukrainian = 'uk', | ||||
|     Urdu = 'ur', | ||||
|     Uzbek = 'uz', | ||||
|     Venda = 've', | ||||
|     Vietnamese = 'vi', | ||||
|     Volapuk = 'vo', | ||||
|     Welsh = 'cy', | ||||
|     Walloon = 'wa', | ||||
|     Wolof = 'wo', | ||||
|     Xhosa = 'xh', | ||||
|     Yiddish = 'yi', | ||||
|     Yoruba = 'yo', | ||||
|     Zhuang = 'za', | ||||
|     Zulu = 'zu', | ||||
| } | ||||
| 
 | ||||
| export const languageMap: Record<string, Language> = { | ||||
|     nl: Language.Dutch, | ||||
|     fr: Language.French, | ||||
|     en: Language.English, | ||||
|     de: Language.German, | ||||
| }; | ||||
|  | @ -1,4 +1,4 @@ | |||
| import { Language } from './language.js'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language'; | ||||
| 
 | ||||
| export class LearningObjectIdentifier { | ||||
|     constructor( | ||||
|  |  | |||
|  | @ -1,10 +1,10 @@ | |||
| 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'; | ||||
| import { DwengoContentType } from '../../services/learning-objects/processing/content-type.js'; | ||||
| import { v4 } from 'uuid'; | ||||
| import { LearningObjectRepository } from '../../data/content/learning-object-repository.js'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language.js'; | ||||
| 
 | ||||
| @Embeddable() | ||||
| export class EducationalGoal { | ||||
|  |  | |||
|  | @ -1,7 +1,7 @@ | |||
| import { Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property, Rel } from '@mikro-orm/core'; | ||||
| import { Language } from './language.js'; | ||||
| import { LearningPath } from './learning-path.entity.js'; | ||||
| import { LearningPathTransition } from './learning-path-transition.entity.js'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language.js'; | ||||
| 
 | ||||
| @Entity() | ||||
| export class LearningPathNode { | ||||
|  |  | |||
|  | @ -1,8 +1,8 @@ | |||
| import { Entity, Enum, ManyToMany, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'; | ||||
| import { Language } from './language.js'; | ||||
| import { Teacher } from '../users/teacher.entity.js'; | ||||
| import { LearningPathRepository } from '../../data/content/learning-path-repository.js'; | ||||
| import { LearningPathNode } from './learning-path-node.entity.js'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language.js'; | ||||
| 
 | ||||
| @Entity({ repository: () => LearningPathRepository }) | ||||
| export class LearningPath { | ||||
|  |  | |||
|  | @ -1,7 +1,7 @@ | |||
| import { Entity, Enum, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'; | ||||
| import { Language } from '../content/language.js'; | ||||
| import { Student } from '../users/student.entity.js'; | ||||
| import { QuestionRepository } from '../../data/questions/question-repository.js'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language.js'; | ||||
| 
 | ||||
| @Entity({ repository: () => QuestionRepository }) | ||||
| export class Question { | ||||
|  |  | |||
|  | @ -1,7 +1,7 @@ | |||
| import { languageMap } from 'dwengo-1-common/src/util/language.js'; | ||||
| import { FALLBACK_LANG } from '../config.js'; | ||||
| import { Assignment } from '../entities/assignments/assignment.entity.js'; | ||||
| import { Class } from '../entities/classes/class.entity.js'; | ||||
| import { languageMap } from '../entities/content/language.js'; | ||||
| import { AssignmentDTO } from 'dwengo-1-common/src/interfaces/assignment'; | ||||
| 
 | ||||
| export function mapToAssignmentDTOId(assignment: Assignment): AssignmentDTO { | ||||
|  |  | |||
|  | @ -1,6 +1,5 @@ | |||
| import { LearningObjectProvider } from './learning-object-provider.js'; | ||||
| import { getLearningObjectRepository, getLearningPathRepository } from '../../data/repositories.js'; | ||||
| import { Language } from '../../entities/content/language.js'; | ||||
| import { LearningObject } from '../../entities/content/learning-object.entity.js'; | ||||
| import { getUrlStringForLearningObject } from '../../util/links.js'; | ||||
| import processingService from './processing/processing-service.js'; | ||||
|  | @ -8,6 +7,7 @@ import { NotFoundError } from '@mikro-orm/core'; | |||
| import learningObjectService from './learning-object-service.js'; | ||||
| import { getLogger, Logger } from '../../logging/initalize.js'; | ||||
| import { FilteredLearningObject, LearningObjectIdentifier, LearningPathIdentifier } from 'dwengo-1-common/src/interfaces/learning-content'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language.js'; | ||||
| 
 | ||||
| const logger: Logger = getLogger(); | ||||
| 
 | ||||
|  |  | |||
|  | @ -8,13 +8,13 @@ import InlineImageProcessor from '../image/inline-image-processor.js'; | |||
| import * as marked from 'marked'; | ||||
| import { getUrlStringForLearningObjectHTML, isValidHttpUrl } from '../../../../util/links.js'; | ||||
| import { ProcessingError } from '../processing-error.js'; | ||||
| import { Language } from '../../../../entities/content/language.js'; | ||||
| 
 | ||||
| import Image = marked.Tokens.Image; | ||||
| import Heading = marked.Tokens.Heading; | ||||
| import Link = marked.Tokens.Link; | ||||
| import RendererObject = marked.RendererObject; | ||||
| import { LearningObjectIdentifier } from 'dwengo-1-common/src/interfaces/learning-content'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language.js'; | ||||
| 
 | ||||
| const prefixes = { | ||||
|     learningObject: '@learning-object', | ||||
|  |  | |||
|  | @ -13,9 +13,9 @@ import GiftProcessor from './gift/gift-processor.js'; | |||
| import { LearningObject } from '../../../entities/content/learning-object.entity.js'; | ||||
| import Processor from './processor.js'; | ||||
| import { DwengoContentType } from './content-type.js'; | ||||
| import { Language } from '../../../entities/content/language.js'; | ||||
| import { replaceAsync } from '../../../util/async.js'; | ||||
| import { LearningObjectIdentifier } from 'dwengo-1-common/src/interfaces/learning-content'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language.js'; | ||||
| 
 | ||||
| const EMBEDDED_LEARNING_OBJECT_PLACEHOLDER = /<learning-object hruid="([^"]+)" language="([^"]+)" version="([^"]+)"\/>/g; | ||||
| const LEARNING_OBJECT_DOES_NOT_EXIST = "<div class='non-existing-learning-object' />"; | ||||
|  |  | |||
|  | @ -1,7 +1,6 @@ | |||
| import { LearningPathProvider } from './learning-path-provider.js'; | ||||
| import { LearningPath as LearningPathEntity } from '../../entities/content/learning-path.entity.js'; | ||||
| import { getLearningPathRepository } from '../../data/repositories.js'; | ||||
| import { Language } from '../../entities/content/language.js'; | ||||
| import learningObjectService from '../learning-objects/learning-object-service.js'; | ||||
| import { LearningPathNode } from '../../entities/content/learning-path-node.entity.js'; | ||||
| import { LearningPathTransition } from '../../entities/content/learning-path-transition.entity.js'; | ||||
|  | @ -13,6 +12,7 @@ import { | |||
|     LearningPathResponse, | ||||
|     Transition, | ||||
| } from 'dwengo-1-common/src/interfaces/learning-content'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language.js'; | ||||
| 
 | ||||
| /** | ||||
|  * Fetches the corresponding learning object for each of the nodes and creates a map that maps each node to its | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| import { Language } from '../../entities/content/language.js'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language.js'; | ||||
| import { PersonalizationTarget } from './learning-path-personalization-util.js'; | ||||
| import { LearningPath, LearningPathResponse } from 'dwengo-1-common/src/interfaces/learning-content'; | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,9 +1,9 @@ | |||
| import dwengoApiLearningPathProvider from './dwengo-api-learning-path-provider.js'; | ||||
| import databaseLearningPathProvider from './database-learning-path-provider.js'; | ||||
| import { EnvVars, getEnvVar } from '../../util/envvars.js'; | ||||
| import { Language } from '../../entities/content/language.js'; | ||||
| import { PersonalizationTarget } from './learning-path-personalization-util.js'; | ||||
| import { LearningPath, LearningPathResponse } from 'dwengo-1-common/src/interfaces/learning-content'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language.js'; | ||||
| 
 | ||||
| const userContentPrefix = getEnvVar(EnvVars.UserContentPrefix); | ||||
| const allProviders = [dwengoApiLearningPathProvider, databaseLearningPathProvider]; | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| import { getGroupRepository, getSubmissionRepository } from '../data/repositories.js'; | ||||
| import { Language } from '../entities/content/language.js'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language.js'; | ||||
| import { getSubmissionRepository } from '../data/repositories.js'; | ||||
| import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; | ||||
| import { mapToSubmission, mapToSubmissionDTO } from '../interfaces/submission.js'; | ||||
| import { SubmissionDTO } from 'dwengo-1-common/src/interfaces/submission'; | ||||
|  |  | |||
|  | @ -9,11 +9,11 @@ import { | |||
|     getSubmissionRepository, | ||||
| } from '../../../src/data/repositories'; | ||||
| import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier'; | ||||
| import { Language } from '../../../src/entities/content/language'; | ||||
| import { StudentRepository } from '../../../src/data/users/student-repository'; | ||||
| import { GroupRepository } from '../../../src/data/assignments/group-repository'; | ||||
| import { AssignmentRepository } from '../../../src/data/assignments/assignment-repository'; | ||||
| import { ClassRepository } from '../../../src/data/classes/class-repository'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language'; | ||||
| 
 | ||||
| describe('SubmissionRepository', () => { | ||||
|     let submissionRepository: SubmissionRepository; | ||||
|  |  | |||
|  | @ -4,7 +4,7 @@ import { getAttachmentRepository, getLearningObjectRepository } from '../../../s | |||
| import { AttachmentRepository } from '../../../src/data/content/attachment-repository.js'; | ||||
| import { LearningObjectRepository } from '../../../src/data/content/learning-object-repository.js'; | ||||
| import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier.js'; | ||||
| import { Language } from '../../../src/entities/content/language.js'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language.js'; | ||||
| 
 | ||||
| describe('AttachmentRepository', () => { | ||||
|     let attachmentRepository: AttachmentRepository; | ||||
|  |  | |||
|  | @ -3,7 +3,7 @@ import { LearningObjectRepository } from '../../../src/data/content/learning-obj | |||
| import { getLearningObjectRepository } from '../../../src/data/repositories'; | ||||
| import { setupTestApp } from '../../setup-tests'; | ||||
| import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier'; | ||||
| import { Language } from '../../../src/entities/content/language'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language'; | ||||
| 
 | ||||
| describe('LearningObjectRepository', () => { | ||||
|     let learningObjectRepository: LearningObjectRepository; | ||||
|  |  | |||
|  | @ -5,7 +5,7 @@ import { LearningPathRepository } from '../../../src/data/content/learning-path- | |||
| import example from '../../test-assets/learning-paths/pn-werking-example.js'; | ||||
| import { LearningPath } from '../../../src/entities/content/learning-path.entity.js'; | ||||
| import { expectToBeCorrectEntity } from '../../test-utils/expectations.js'; | ||||
| import { Language } from '../../../src/entities/content/language.js'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language'; | ||||
| 
 | ||||
| function expectToHaveFoundPrecisely(expected: LearningPath, result: LearningPath[]): void { | ||||
|     expect(result).toHaveProperty('length'); | ||||
|  |  | |||
|  | @ -2,7 +2,7 @@ import { beforeAll, describe, expect, it } from 'vitest'; | |||
| import { getLearningPathRepository } from '../../../src/data/repositories'; | ||||
| import { LearningPathRepository } from '../../../src/data/content/learning-path-repository'; | ||||
| import { setupTestApp } from '../../setup-tests'; | ||||
| import { Language } from '../../../src/entities/content/language'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language'; | ||||
| 
 | ||||
| describe('LearningPathRepository', () => { | ||||
|     let learningPathRepository: LearningPathRepository; | ||||
|  |  | |||
|  | @ -1,10 +1,10 @@ | |||
| import { beforeAll, describe, expect, it } from 'vitest'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language'; | ||||
| import { setupTestApp } from '../../setup-tests'; | ||||
| import { AnswerRepository } from '../../../src/data/questions/answer-repository'; | ||||
| import { getAnswerRepository, getQuestionRepository, getTeacherRepository } from '../../../src/data/repositories'; | ||||
| import { QuestionRepository } from '../../../src/data/questions/question-repository'; | ||||
| import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier'; | ||||
| import { Language } from '../../../src/entities/content/language'; | ||||
| import { TeacherRepository } from '../../../src/data/users/teacher-repository'; | ||||
| 
 | ||||
| describe('AnswerRepository', () => { | ||||
|  |  | |||
|  | @ -1,11 +1,11 @@ | |||
| import { beforeAll, describe, expect, it } from 'vitest'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language'; | ||||
| import { setupTestApp } from '../../setup-tests'; | ||||
| import { QuestionRepository } from '../../../src/data/questions/question-repository'; | ||||
| import { getLearningObjectRepository, getQuestionRepository, getStudentRepository } from '../../../src/data/repositories'; | ||||
| import { StudentRepository } from '../../../src/data/users/student-repository'; | ||||
| import { LearningObjectRepository } from '../../../src/data/content/learning-object-repository'; | ||||
| import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier'; | ||||
| import { Language } from '../../../src/entities/content/language'; | ||||
| 
 | ||||
| describe('QuestionRepository', () => { | ||||
|     let questionRepository: QuestionRepository; | ||||
|  |  | |||
|  | @ -1,15 +1,15 @@ | |||
| import { beforeAll, describe, expect, it } from 'vitest'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language'; | ||||
| import { setupTestApp } from '../../setup-tests'; | ||||
| import { getLearningObjectRepository, getLearningPathRepository } from '../../../src/data/repositories'; | ||||
| import example from '../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example'; | ||||
| import learningObjectExample from '../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example'; | ||||
| import { LearningObject } from '../../../src/entities/content/learning-object.entity'; | ||||
| import databaseLearningObjectProvider from '../../../src/services/learning-objects/database-learning-object-provider'; | ||||
| import { expectToBeCorrectFilteredLearningObject } from '../../test-utils/expectations'; | ||||
| import { Language } from '../../../src/entities/content/language'; | ||||
| import learningObjectExample from '../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example'; | ||||
| import learningPathExample from '../../test-assets/learning-paths/pn-werking-example'; | ||||
| import { LearningPath } from '../../../src/entities/content/learning-path.entity'; | ||||
| import {FilteredLearningObject} from "dwengo-1-common/src/interfaces/learning-content"; | ||||
| import { FilteredLearningObject } from 'dwengo-1-common/src/interfaces/learning-content'; | ||||
| 
 | ||||
| async function initExampleData(): Promise<{ learningObject: LearningObject; learningPath: LearningPath }> { | ||||
|     const learningObjectRepo = getLearningObjectRepository(); | ||||
|  |  | |||
|  | @ -1,14 +1,14 @@ | |||
| import { beforeAll, describe, expect, it } from 'vitest'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language'; | ||||
| import { setupTestApp } from '../../setup-tests'; | ||||
| import { LearningObject } from '../../../src/entities/content/learning-object.entity'; | ||||
| import { getLearningObjectRepository, getLearningPathRepository } from '../../../src/data/repositories'; | ||||
| import learningObjectExample from '../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example'; | ||||
| import learningObjectService from '../../../src/services/learning-objects/learning-object-service'; | ||||
| import { Language } from '../../../src/entities/content/language'; | ||||
| import { EnvVars, getEnvVar } from '../../../src/util/envvars'; | ||||
| import { LearningPath } from '../../../src/entities/content/learning-path.entity'; | ||||
| import learningPathExample from '../../test-assets/learning-paths/pn-werking-example'; | ||||
| import {LearningObjectIdentifier, LearningPathIdentifier} from "dwengo-1-common/src/interfaces/learning-content"; | ||||
| import { LearningObjectIdentifier, LearningPathIdentifier } from 'dwengo-1-common/src/interfaces/learning-content'; | ||||
| 
 | ||||
| const EXPECTED_DWENGO_LEARNING_OBJECT_TITLE = 'Werken met notebooks'; | ||||
| const DWENGO_TEST_LEARNING_OBJECT_ID: LearningObjectIdentifier = { | ||||
|  | @ -105,7 +105,10 @@ describe('LearningObjectService', () => { | |||
|             expect(new Set(result.map((it) => it.key))).toEqual(DWENGO_TEST_LEARNING_PATH_HRUIDS); | ||||
|         }); | ||||
|         it('returns an empty list when queried with a non-existing learning path id', async () => { | ||||
|             const result = await learningObjectService.getLearningObjectsFromPath({ hruid: 'non_existing', language: Language.Dutch }); | ||||
|             const result = await learningObjectService.getLearningObjectsFromPath({ | ||||
|                 hruid: 'non_existing', | ||||
|                 language: Language.Dutch, | ||||
|             }); | ||||
|             expect(result).toEqual([]); | ||||
|         }); | ||||
|     }); | ||||
|  | @ -120,7 +123,10 @@ describe('LearningObjectService', () => { | |||
|             expect(new Set(result)).toEqual(DWENGO_TEST_LEARNING_PATH_HRUIDS); | ||||
|         }); | ||||
|         it('returns an empty list when queried with a non-existing learning path id', async () => { | ||||
|             const result = await learningObjectService.getLearningObjectIdsFromPath({ hruid: 'non_existing', language: Language.Dutch }); | ||||
|             const result = await learningObjectService.getLearningObjectIdsFromPath({ | ||||
|                 hruid: 'non_existing', | ||||
|                 language: Language.Dutch, | ||||
|             }); | ||||
|             expect(result).toEqual([]); | ||||
|         }); | ||||
|     }); | ||||
|  |  | |||
|  | @ -1,4 +1,5 @@ | |||
| import { beforeAll, describe, expect, it } from 'vitest'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language'; | ||||
| import { LearningObject } from '../../../src/entities/content/learning-object.entity.js'; | ||||
| import { setupTestApp } from '../../setup-tests.js'; | ||||
| import { LearningPath } from '../../../src/entities/content/learning-path.entity.js'; | ||||
|  | @ -13,14 +14,13 @@ import learningPathExample from '../../test-assets/learning-paths/pn-werking-exa | |||
| import databaseLearningPathProvider from '../../../src/services/learning-paths/database-learning-path-provider.js'; | ||||
| import { expectToBeCorrectLearningPath } from '../../test-utils/expectations.js'; | ||||
| import learningObjectService from '../../../src/services/learning-objects/learning-object-service.js'; | ||||
| import { Language } from '../../../src/entities/content/language.js'; | ||||
| import { | ||||
|     ConditionTestLearningPathAndLearningObjects, | ||||
|     createConditionTestLearningPathAndLearningObjects, | ||||
| } from '../../test-assets/learning-paths/test-conditions-example.js'; | ||||
| import { Student } from '../../../src/entities/users/student.entity.js'; | ||||
| 
 | ||||
| import {LearningObjectNode, LearningPathResponse} from "dwengo-1-common/src/interfaces/learning-content"; | ||||
| import { LearningObjectNode, LearningPathResponse } from 'dwengo-1-common/src/interfaces/learning-content'; | ||||
| 
 | ||||
| async function initExampleData(): Promise<{ learningObject: LearningObject; learningPath: LearningPath }> { | ||||
|     const learningObjectRepo = getLearningObjectRepository(); | ||||
|  | @ -105,7 +105,11 @@ function expectBranchingObjectNode( | |||
| 
 | ||||
| describe('DatabaseLearningPathProvider', () => { | ||||
|     let example: { learningObject: LearningObject; learningPath: LearningPath }; | ||||
|     let persTestData: { learningContent: ConditionTestLearningPathAndLearningObjects; studentA: Student; studentB: Student }; | ||||
|     let persTestData: { | ||||
|         learningContent: ConditionTestLearningPathAndLearningObjects; | ||||
|         studentA: Student; | ||||
|         studentB: Student; | ||||
|     }; | ||||
| 
 | ||||
|     beforeAll(async () => { | ||||
|         await setupTestApp(); | ||||
|  |  | |||
|  | @ -1,11 +1,11 @@ | |||
| import { beforeAll, describe, expect, it } from 'vitest'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language'; | ||||
| import { setupTestApp } from '../../setup-tests'; | ||||
| import { LearningObject } from '../../../src/entities/content/learning-object.entity'; | ||||
| import { LearningPath } from '../../../src/entities/content/learning-path.entity'; | ||||
| import { getLearningObjectRepository, getLearningPathRepository } from '../../../src/data/repositories'; | ||||
| import learningObjectExample from '../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example'; | ||||
| import learningPathExample from '../../test-assets/learning-paths/pn-werking-example'; | ||||
| import { Language } from '../../../src/entities/content/language'; | ||||
| import learningPathService from '../../../src/services/learning-paths/learning-path-service'; | ||||
| 
 | ||||
| async function initExampleData(): Promise<{ learningObject: LearningObject; learningPath: LearningPath }> { | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| import { LearningObjectExample } from '../learning-object-example'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language'; | ||||
| import { LearningObject } from '../../../../src/entities/content/learning-object.entity'; | ||||
| import { Language } from '../../../../src/entities/content/language'; | ||||
| import { loadTestAsset } from '../../../test-utils/load-test-asset'; | ||||
| import { DwengoContentType } from '../../../../src/services/learning-objects/processing/content-type'; | ||||
| import { EnvVars, getEnvVar } from '../../../../src/util/envvars'; | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| import { LearningObjectExample } from '../learning-object-example'; | ||||
| import { Language } from '../../../../src/entities/content/language'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language'; | ||||
| import { DwengoContentType } from '../../../../src/services/learning-objects/processing/content-type'; | ||||
| import { loadTestAsset } from '../../../test-utils/load-test-asset'; | ||||
| import { EducationalGoal, LearningObject, ReturnValue } from '../../../../src/entities/content/learning-object.entity'; | ||||
|  |  | |||
|  | @ -1,8 +1,8 @@ | |||
| import { LearningObjectExample } from '../learning-object-example'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language'; | ||||
| import { LearningObject } from '../../../../src/entities/content/learning-object.entity'; | ||||
| import { loadTestAsset } from '../../../test-utils/load-test-asset'; | ||||
| import { EnvVars, getEnvVar } from '../../../../src/util/envvars'; | ||||
| import { Language } from '../../../../src/entities/content/language'; | ||||
| import { DwengoContentType } from '../../../../src/services/learning-objects/processing/content-type'; | ||||
| 
 | ||||
| const example: LearningObjectExample = { | ||||
|  |  | |||
|  | @ -1,8 +1,8 @@ | |||
| import { LearningObjectExample } from '../learning-object-example'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language'; | ||||
| import { LearningObject } from '../../../../src/entities/content/learning-object.entity'; | ||||
| import { loadTestAsset } from '../../../test-utils/load-test-asset'; | ||||
| import { EnvVars, getEnvVar } from '../../../../src/util/envvars'; | ||||
| import { Language } from '../../../../src/entities/content/language'; | ||||
| import { DwengoContentType } from '../../../../src/services/learning-objects/processing/content-type'; | ||||
| 
 | ||||
| const example: LearningObjectExample = { | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| import { Language } from '../../../src/entities/content/language'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language'; | ||||
| import { LearningPathTransition } from '../../../src/entities/content/learning-path-transition.entity'; | ||||
| import { LearningPathNode } from '../../../src/entities/content/learning-path-node.entity'; | ||||
| import { LearningPath } from '../../../src/entities/content/learning-path.entity'; | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| import { LearningPath } from '../../../src/entities/content/learning-path.entity'; | ||||
| import { Language } from '../../../src/entities/content/language'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language'; | ||||
| import { EnvVars, getEnvVar } from '../../../src/util/envvars'; | ||||
| import { createLearningPathNode, createLearningPathTransition } from './learning-path-utils'; | ||||
| import { LearningPathNode } from '../../../src/entities/content/learning-path-node.entity'; | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| import { LearningPath } from '../../../src/entities/content/learning-path.entity'; | ||||
| import { Language } from '../../../src/entities/content/language'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language'; | ||||
| import testMultipleChoiceExample from '../learning-objects/test-multiple-choice/test-multiple-choice-example'; | ||||
| import { dummyLearningObject } from '../learning-objects/dummy/dummy-learning-object-example'; | ||||
| import { createLearningPathNode, createLearningPathTransition } from './learning-path-utils'; | ||||
|  |  | |||
|  | @ -2,7 +2,7 @@ import { AssertionError } from 'node:assert'; | |||
| import { LearningObject } from '../../src/entities/content/learning-object.entity'; | ||||
| import { LearningPath as LearningPathEntity } from '../../src/entities/content/learning-path.entity'; | ||||
| import { expect } from 'vitest'; | ||||
| import {FilteredLearningObject, LearningPath} from "dwengo-1-common/src/interfaces/learning-content"; | ||||
| import { FilteredLearningObject, LearningPath } from 'dwengo-1-common/src/interfaces/learning-content'; | ||||
| 
 | ||||
| // Ignored properties because they belang for example to the class, not to the entity itself.
 | ||||
| const IGNORE_PROPERTIES = ['parent']; | ||||
|  | @ -12,7 +12,13 @@ const IGNORE_PROPERTIES = ['parent']; | |||
|  * @param actual The actual entity retrieved from the database | ||||
|  * @param expected The (previously added) entity we would expect to retrieve | ||||
|  */ | ||||
| export function expectToBeCorrectEntity<T extends object>(actual: { entity: T; name?: string }, expected: { entity: T; name?: string }): void { | ||||
| export function expectToBeCorrectEntity<T extends object>( | ||||
|     actual: { entity: T; name?: string }, | ||||
|     expected: { | ||||
|         entity: T; | ||||
|         name?: string; | ||||
|     } | ||||
| ): void { | ||||
|     if (!actual.name) { | ||||
|         actual.name = 'actual'; | ||||
|     } | ||||
|  |  | |||
|  | @ -1,7 +1,7 @@ | |||
| import { Connection, EntityManager, IDatabaseDriver } from '@mikro-orm/core'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language'; | ||||
| import { Assignment } from '../../../src/entities/assignments/assignment.entity'; | ||||
| import { Class } from '../../../src/entities/classes/class.entity'; | ||||
| import { Language } from '../../../src/entities/content/language'; | ||||
| 
 | ||||
| export function makeTestAssignemnts(em: EntityManager<IDatabaseDriver<Connection>>, classes: Array<Class>): Array<Assignment> { | ||||
|     const assignment01 = em.create(Assignment, { | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| import { Connection, EntityManager, IDatabaseDriver } from '@mikro-orm/core'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language'; | ||||
| import { Submission } from '../../../src/entities/assignments/submission.entity'; | ||||
| import { Language } from '../../../src/entities/content/language'; | ||||
| import { Student } from '../../../src/entities/users/student.entity'; | ||||
| import { Group } from '../../../src/entities/assignments/group.entity'; | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| import { Connection, EntityManager, IDatabaseDriver } from '@mikro-orm/core'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language'; | ||||
| import { LearningObject, ReturnValue } from '../../../src/entities/content/learning-object.entity'; | ||||
| import { Language } from '../../../src/entities/content/language'; | ||||
| import { DwengoContentType } from '../../../src/services/learning-objects/processing/content-type'; | ||||
| 
 | ||||
| export function makeTestLearningObjects(em: EntityManager<IDatabaseDriver<Connection>>): Array<LearningObject> { | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| import { Connection, EntityManager, IDatabaseDriver } from '@mikro-orm/core'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language'; | ||||
| import { LearningPath } from '../../../src/entities/content/learning-path.entity'; | ||||
| import { Language } from '../../../src/entities/content/language'; | ||||
| import { LearningPathTransition } from '../../../src/entities/content/learning-path-transition.entity'; | ||||
| import { LearningPathNode } from '../../../src/entities/content/learning-path-node.entity'; | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| import { Connection, EntityManager, IDatabaseDriver } from '@mikro-orm/core'; | ||||
| import { Language } from 'dwengo-1-common/src/util/language'; | ||||
| import { Question } from '../../../src/entities/questions/question.entity'; | ||||
| import { Language } from '../../../src/entities/content/language'; | ||||
| import { Student } from '../../../src/entities/users/student.entity'; | ||||
| 
 | ||||
| export function makeTestQuestions(em: EntityManager<IDatabaseDriver<Connection>>, students: Array<Student>): Array<Question> { | ||||
|  |  | |||
		Reference in a new issue