Merge remote-tracking branch 'origin/refactor/common' into feat/user-routes-test-interface-refactor

# Conflicts:
#	backend/src/controllers/students.ts
#	backend/src/controllers/teachers.ts
#	backend/src/interfaces/answer.ts
#	backend/src/interfaces/question.ts
#	backend/src/interfaces/student.ts
#	backend/src/services/classes.ts
#	backend/src/services/questions.ts
#	backend/src/services/students.ts
#	backend/src/services/teachers.ts
This commit is contained in:
Gabriellvl 2025-04-02 10:16:10 +02:00
commit 4ca568e738
57 changed files with 270 additions and 190 deletions

View file

@ -1,14 +1,7 @@
import { mapToUserDTO, UserDTO } from './user.js';
import {mapToQuestionDTO, mapToQuestionDTOId, QuestionDTO, QuestionId} from './question.js';
import { mapToUserDTO } from './user.js';
import { mapToQuestionDTO, mapToQuestionDTOId } from './question.js';
import { Answer } from '../entities/questions/answer.entity.js';
export interface AnswerDTO {
author: UserDTO;
toQuestion: QuestionDTO;
sequenceNumber: number;
timestamp: string;
content: string;
}
import { AnswerDTO, AnswerId } from 'dwengo-1-common/src/interfaces/answer';
/**
* Convert a Question entity to a DTO format.
@ -23,16 +16,10 @@ export function mapToAnswerDTO(answer: Answer): AnswerDTO {
};
}
export interface AnswerId {
author: string;
toQuestion: QuestionId;
sequenceNumber: number;
}
export function mapToAnswerDTOId(answer: Answer): AnswerId {
export function mapToAnswerId(answer: AnswerDTO): AnswerId {
return {
author: answer.author.username,
toQuestion: mapToQuestionDTOId(answer.toQuestion),
sequenceNumber: answer.sequenceNumber!,
sequenceNumber: answer.sequenceNumber,
};
}

View file

@ -1,19 +1,9 @@
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 { GroupDTO } from './group.js';
import { getLogger } from '../logging/initalize.js';
export interface AssignmentDTO {
id: number;
class: string; // Id of class 'within'
title: string;
description: string;
learningPath: string;
language: string;
groups?: GroupDTO[] | string[]; // TODO
}
import { languageMap } from '../entities/content/language.js';
import { AssignmentDTO } from 'dwengo-1-common/src/interfaces/assignment';
export function mapToAssignmentDTOId(assignment: Assignment): AssignmentDTO {
return {

View file

@ -2,14 +2,7 @@ import { Collection } from '@mikro-orm/core';
import { Class } from '../entities/classes/class.entity.js';
import { Student } from '../entities/users/student.entity.js';
import { Teacher } from '../entities/users/teacher.entity.js';
export interface ClassDTO {
id: string;
displayName: string;
teachers: string[];
students: string[];
joinRequests: string[];
}
import { ClassDTO } from 'dwengo-1-common/src/interfaces/class';
export function mapToClassDTO(cls: Class): ClassDTO {
return {

View file

@ -1,12 +1,7 @@
import { Group } from '../entities/assignments/group.entity.js';
import { AssignmentDTO, mapToAssignmentDTO } from './assignment.js';
import { mapToStudentDTO, StudentDTO } from './student.js';
export interface GroupDTO {
assignment: number | AssignmentDTO;
groupNumber: number;
members: string[] | StudentDTO[];
}
import { mapToAssignmentDTO } from './assignment.js';
import { mapToStudentDTO } from './student.js';
import { GroupDTO } from 'dwengo-1-common/src/interfaces/group';
export function mapToGroupDTO(group: Group): GroupDTO {
return {

View file

@ -1,112 +0,0 @@
import { Language } from '../entities/content/language';
export interface Transition {
default: boolean;
_id: string;
next: {
_id: string;
hruid: string;
version: number;
language: string;
};
}
export interface LearningObjectIdentifier {
hruid: string;
language: Language;
version?: number;
}
export interface LearningObjectNode {
_id: string;
learningobject_hruid: string;
version: number;
language: Language;
start_node?: boolean;
transitions: Transition[];
created_at: string;
updatedAt: string;
done?: boolean; // True if a submission exists for this node by the user for whom the learning path is customized.
}
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 LearningPathIdentifier {
hruid: string;
language: Language;
}
export interface EducationalGoal {
source: string;
id: string;
}
export interface ReturnValue {
callback_url: string;
callback_schema: Record<string, unknown>;
}
export interface LearningObjectMetadata {
_id: string;
uuid: string;
hruid: string;
version: number;
language: Language;
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: Language;
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;
}

View file

@ -1,14 +1,6 @@
import { Question } from '../entities/questions/question.entity.js';
import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js';
import { mapToStudentDTO, StudentDTO } from './student.js';
export interface QuestionDTO {
learningObjectIdentifier: LearningObjectIdentifier;
sequenceNumber?: number;
author: StudentDTO;
timestamp?: string;
content: string;
}
import { mapToStudentDTO } from './student.js';
import { QuestionDTO, QuestionId } from 'dwengo-1-common/src/interfaces/question';
function getLearningObjectIdentifier(question: Question): LearningObjectIdentifier {
return {
@ -33,11 +25,6 @@ export function mapToQuestionDTO(question: Question): QuestionDTO {
};
}
export interface QuestionId {
learningObjectIdentifier: LearningObjectIdentifier;
sequenceNumber: number;
}
export function mapToQuestionDTOId(question: Question): QuestionId {
const learningObjectIdentifier = getLearningObjectIdentifier(question);

View file

@ -1,12 +1,6 @@
import { Student } from '../entities/users/student.entity.js';
import { getStudentRepository } from '../data/repositories.js';
export interface StudentDTO {
id: string;
username: string;
firstName: string;
lastName: string;
}
import { StudentDTO } from 'dwengo-1-common/src/interfaces/student';
export function mapToStudentDTO(student: Student): StudentDTO {
return {

View file

@ -1,26 +1,7 @@
import { Submission } from '../entities/assignments/submission.entity.js';
import { Language } from '../entities/content/language.js';
import { GroupDTO, mapToGroupDTO } from './group.js';
import { mapToStudent, mapToStudentDTO, StudentDTO } from './student.js';
import { LearningObjectIdentifier } from './learning-content.js';
export interface SubmissionDTO {
learningObjectIdentifier: LearningObjectIdentifier;
submissionNumber?: number;
submitter: StudentDTO;
time?: Date;
group?: GroupDTO;
content: string;
}
export interface SubmissionDTOId {
learningObjectHruid: string;
learningObjectLanguage: Language;
learningObjectVersion: number;
submissionNumber?: number;
}
import { mapToGroupDTO } from './group.js';
import { mapToStudent, mapToStudentDTO } from './student.js';
import { SubmissionDTO, SubmissionDTOId } from 'dwengo-1-common/src/interfaces/submission';
export function mapToSubmissionDTO(submission: Submission): SubmissionDTO {
return {

View file

@ -1,12 +1,7 @@
import { TeacherInvitation } from '../entities/classes/teacher-invitation.entity.js';
import { ClassDTO, mapToClassDTO } from './class.js';
import { mapToUserDTO, UserDTO } from './user.js';
export interface TeacherInvitationDTO {
sender: string | UserDTO;
receiver: string | UserDTO;
class: string | ClassDTO;
}
import { mapToClassDTO } from './class.js';
import { mapToUserDTO } from './user.js';
import { TeacherInvitationDTO } from 'dwengo-1-common/src/interfaces/teacher-invitation';
export function mapToTeacherInvitationDTO(invitation: TeacherInvitation): TeacherInvitationDTO {
return {

View file

@ -1,18 +1,6 @@
import { Teacher } from '../entities/users/teacher.entity.js';
import { getTeacherRepository } from '../data/repositories.js';
export interface TeacherDTO {
id: string;
username: string;
firstName: string;
lastName: string;
endpoints?: {
classes: string;
questions: string;
invitations: string;
groups: string;
};
}
import { TeacherDTO } from 'dwengo-1-common/src/interfaces/teacher';
export function mapToTeacherDTO(teacher: Teacher): TeacherDTO {
return {

View file

@ -1,17 +1,5 @@
import { User } from '../entities/users/user.entity.js';
export interface UserDTO {
id?: string;
username: string;
firstName: string;
lastName: string;
endpoints?: {
self: string;
classes: string;
questions: string;
invitations: string;
};
}
import { UserDTO } from 'dwengo-1-common/src/interfaces/user';
export function mapToUserDTO(user: User): UserDTO {
return {