Merge remote-tracking branch 'origin/refactor/common' into feat/user-routes
# Conflicts: # backend/src/controllers/students.ts # backend/src/controllers/teachers.ts # backend/src/interfaces/question.ts # backend/src/services/classes.ts # backend/src/services/students.ts # backend/src/services/teachers.ts
This commit is contained in:
commit
7d8a0fcbb2
96 changed files with 205 additions and 153 deletions
|
|
@ -1,8 +1,8 @@
|
|||
import { getAssignmentRepository, getClassRepository, getGroupRepository, getSubmissionRepository } from '../data/repositories.js';
|
||||
import { mapToAssignment, mapToAssignmentDTO, mapToAssignmentDTOId } from '../interfaces/assignment.js';
|
||||
import { mapToSubmissionDTO, mapToSubmissionDTOId } from '../interfaces/submission.js';
|
||||
import { AssignmentDTO } from 'dwengo-1-common/src/interfaces/assignment';
|
||||
import { SubmissionDTO, SubmissionDTOId } from 'dwengo-1-common/src/interfaces/submission';
|
||||
import { AssignmentDTO } from '@dwengo-1/common/interfaces/assignment';
|
||||
import { SubmissionDTO, SubmissionDTOId } from '@dwengo-1/common/interfaces/submission';
|
||||
import { getLogger } from '../logging/initalize.js';
|
||||
|
||||
export async function getAllAssignments(classid: string, full: boolean): Promise<AssignmentDTO[]> {
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ import { mapToTeacherInvitationDTO, mapToTeacherInvitationDTOIds } from '../inte
|
|||
import { getLogger } from '../logging/initalize.js';
|
||||
import { NotFoundException } from '../exceptions/not-found-exception.js';
|
||||
import { Class } from '../entities/classes/class.entity.js';
|
||||
import { ClassDTO } from 'dwengo-1-common/src/interfaces/class';
|
||||
import { TeacherInvitationDTO } from 'dwengo-1-common/src/interfaces/teacher-invitation';
|
||||
import { StudentDTO } from 'dwengo-1-common/src/interfaces/student';
|
||||
import { ClassDTO } from '@dwengo-1/common/interfaces/class';
|
||||
import { TeacherInvitationDTO } from '@dwengo-1/common/interfaces/teacher-invitation';
|
||||
import { StudentDTO } from '@dwengo-1/common/interfaces/student';
|
||||
|
||||
const logger = getLogger();
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import {
|
|||
import { Group } from '../entities/assignments/group.entity.js';
|
||||
import { mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js';
|
||||
import { mapToSubmissionDTO, mapToSubmissionDTOId } from '../interfaces/submission.js';
|
||||
import { GroupDTO } from 'dwengo-1-common/src/interfaces/group';
|
||||
import { SubmissionDTO, SubmissionDTOId } from 'dwengo-1-common/src/interfaces/submission';
|
||||
import { GroupDTO } from '@dwengo-1/common/interfaces/group';
|
||||
import { SubmissionDTO, SubmissionDTOId } from '@dwengo-1/common/interfaces/submission';
|
||||
import { getLogger } from '../logging/initalize.js';
|
||||
|
||||
export async function getGroup(classId: string, assignmentNumber: number, groupNumber: number, full: boolean): Promise<GroupDTO | null> {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import {
|
|||
LearningObjectMetadata,
|
||||
LearningObjectNode,
|
||||
LearningPathResponse,
|
||||
} from 'dwengo-1-common/src/interfaces/learning-content';
|
||||
} from '@dwengo-1/common/interfaces/learning-content';
|
||||
import { getLogger } from '../logging/initalize.js';
|
||||
|
||||
function filterData(data: LearningObjectMetadata, htmlUrl: string): FilteredLearningObject {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { getAttachmentRepository } from '../../data/repositories.js';
|
||||
import { Attachment } from '../../entities/content/attachment.entity.js';
|
||||
|
||||
import { LearningObjectIdentifier } from 'dwengo-1-common/src/interfaces/learning-content';
|
||||
import { LearningObjectIdentifier } from '@dwengo-1/common/interfaces/learning-content';
|
||||
|
||||
const attachmentService = {
|
||||
async getAttachment(learningObjectId: LearningObjectIdentifier, attachmentName: string): Promise<Attachment | null> {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import processingService from './processing/processing-service.js';
|
|||
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 { FilteredLearningObject, LearningObjectIdentifier, LearningPathIdentifier } from '@dwengo-1/common/interfaces/learning-content';
|
||||
|
||||
const logger: Logger = getLogger();
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import {
|
|||
LearningObjectNode,
|
||||
LearningPathIdentifier,
|
||||
LearningPathResponse,
|
||||
} from 'dwengo-1-common/src/interfaces/learning-content';
|
||||
} from '@dwengo-1/common/interfaces/learning-content';
|
||||
|
||||
const logger: Logger = getLogger();
|
||||
|
||||
|
|
@ -66,12 +66,13 @@ async function fetchLearningObjects(learningPathId: LearningPathIdentifier, full
|
|||
}
|
||||
|
||||
const objects = await Promise.all(
|
||||
nodes.map(async (node) =>
|
||||
dwengoApiLearningObjectProvider.getLearningObjectById({
|
||||
nodes.map(async (node) => {
|
||||
const learningObjectId: LearningObjectIdentifier = {
|
||||
hruid: node.learningobject_hruid,
|
||||
language: learningPathId.language,
|
||||
})
|
||||
)
|
||||
language: learningPathId.language
|
||||
};
|
||||
return dwengoApiLearningObjectProvider.getLearningObjectById(learningObjectId);
|
||||
})
|
||||
);
|
||||
return objects.filter((obj): obj is FilteredLearningObject => obj !== null);
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { FilteredLearningObject, LearningObjectIdentifier, LearningPathIdentifier } from 'dwengo-1-common/src/interfaces/learning-content';
|
||||
import { FilteredLearningObject, LearningObjectIdentifier, LearningPathIdentifier } from '@dwengo-1/common/interfaces/learning-content';
|
||||
|
||||
export interface LearningObjectProvider {
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,7 +2,11 @@ import dwengoApiLearningObjectProvider from './dwengo-api-learning-object-provid
|
|||
import { LearningObjectProvider } from './learning-object-provider.js';
|
||||
import { envVars, getEnvVar } from '../../util/envVars.js';
|
||||
import databaseLearningObjectProvider from './database-learning-object-provider.js';
|
||||
import { FilteredLearningObject, LearningObjectIdentifier, LearningPathIdentifier } from 'dwengo-1-common/src/interfaces/learning-content';
|
||||
import {
|
||||
FilteredLearningObject,
|
||||
LearningObjectIdentifier,
|
||||
LearningPathIdentifier,
|
||||
} from '@dwengo-1/common/interfaces/learning-content';
|
||||
|
||||
function getProvider(id: LearningObjectIdentifier): LearningObjectProvider {
|
||||
if (id.hruid.startsWith(getEnvVar(envVars.UserContentPrefix))) {
|
||||
|
|
|
|||
|
|
@ -8,13 +8,12 @@ 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 { LearningObjectIdentifier } from '@dwengo-1/common/interfaces/learning-content';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
|
||||
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 { LearningObjectIdentifier } from '@dwengo-1/common/interfaces/learning-content';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
|
||||
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';
|
||||
|
|
@ -12,7 +11,8 @@ import {
|
|||
LearningPath,
|
||||
LearningPathResponse,
|
||||
Transition,
|
||||
} from 'dwengo-1-common/src/interfaces/learning-content';
|
||||
} from '@dwengo-1/common/interfaces/learning-content';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
|
||||
/**
|
||||
* Fetches the corresponding learning object for each of the nodes and creates a map that maps each node to its
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { fetchWithLogging } from '../../util/api-helper.js';
|
|||
import { DWENGO_API_BASE } from '../../config.js';
|
||||
import { LearningPathProvider } from './learning-path-provider.js';
|
||||
import { getLogger, Logger } from '../../logging/initalize.js';
|
||||
import { LearningPath, LearningPathResponse } from 'dwengo-1-common/src/interfaces/learning-content';
|
||||
import { LearningPath, LearningPathResponse } from '@dwengo-1/common/interfaces/learning-content';
|
||||
|
||||
const logger: Logger = getLogger();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Language } from '../../entities/content/language.js';
|
||||
import { LearningPath, LearningPathResponse } from '@dwengo-1/common/interfaces/learning-content';
|
||||
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/util/language';
|
||||
|
||||
/**
|
||||
* Generic interface for a service which provides access to learning paths from a data source.
|
||||
|
|
|
|||
|
|
@ -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 { LearningPath, LearningPathResponse } from '@dwengo-1/common/interfaces/learning-content';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
|
||||
const userContentPrefix = getEnvVar(envVars.UserContentPrefix);
|
||||
const allProviders = [dwengoApiLearningPathProvider, databaseLearningPathProvider];
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ import { mapToAnswerDTO, mapToAnswerDTOId } from '../interfaces/answer.js';
|
|||
import { QuestionRepository } from '../data/questions/question-repository.js';
|
||||
import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js';
|
||||
import { mapToStudent } from '../interfaces/student.js';
|
||||
import { QuestionDTO, QuestionId } from 'dwengo-1-common/src/interfaces/question';
|
||||
import { AnswerDTO, AnswerId } from 'dwengo-1-common/src/interfaces/answer';
|
||||
import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question';
|
||||
import { AnswerDTO, AnswerId } from '@dwengo-1/common/interfaces/answer';
|
||||
|
||||
export async function getAllQuestions(id: LearningObjectIdentifier, full: boolean): Promise<QuestionDTO[] | QuestionId[]> {
|
||||
const questionRepository: QuestionRepository = getQuestionRepository();
|
||||
|
|
@ -71,9 +71,14 @@ export async function createQuestion(questionDTO: QuestionDTO): Promise<Question
|
|||
|
||||
const author = mapToStudent(questionDTO.author);
|
||||
|
||||
const loId: LearningObjectIdentifier = {
|
||||
...questionDTO.learningObjectIdentifier,
|
||||
version: questionDTO.learningObjectIdentifier.version ?? 1,
|
||||
}
|
||||
|
||||
try {
|
||||
await questionRepository.createQuestion({
|
||||
loId: questionDTO.learningObjectIdentifier,
|
||||
loId,
|
||||
author,
|
||||
content: questionDTO.content,
|
||||
});
|
||||
|
|
@ -93,8 +98,13 @@ export async function deleteQuestion(questionId: QuestionId): Promise<QuestionDT
|
|||
return null;
|
||||
}
|
||||
|
||||
const loId : LearningObjectIdentifier = {
|
||||
...questionId.learningObjectIdentifier,
|
||||
version: questionId.learningObjectIdentifier.version ?? 1
|
||||
}
|
||||
|
||||
try {
|
||||
await questionRepository.removeQuestionByLearningObjectAndSequenceNumber(questionId.learningObjectIdentifier, questionId.sequenceNumber);
|
||||
await questionRepository.removeQuestionByLearningObjectAndSequenceNumber(loId, questionId.sequenceNumber);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { getSubmissionRepository } from '../data/repositories.js';
|
||||
import { Language } from '../entities/content/language.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';
|
||||
import { SubmissionDTO } from '@dwengo-1/common/interfaces/submission';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
|
||||
export async function getSubmission(
|
||||
learningObjectHruid: string,
|
||||
|
|
|
|||
Reference in a new issue