fix: import errors van gabe gefixt, teacher en student abstractie weggedaan
This commit is contained in:
parent
6404335040
commit
b5390258e3
36 changed files with 9754 additions and 180 deletions
|
@ -5,8 +5,7 @@ import {
|
|||
LearningObjectMetadata,
|
||||
LearningObjectNode,
|
||||
LearningPathResponse,
|
||||
} from '../interfaces/learning-path.js';
|
||||
import { fetchLearningPaths } from './learning-paths.js';
|
||||
} from '../interfaces/learning-content.js';
|
||||
|
||||
function filterData(
|
||||
data: LearningObjectMetadata,
|
||||
|
@ -132,3 +131,7 @@ export async function getLearningObjectIdsFromPath(
|
|||
): Promise<string[]> {
|
||||
return (await fetchLearningObjects(hruid, false, language)) as string[];
|
||||
}
|
||||
function fetchLearningPaths(arg0: string[], language: string, arg2: string): LearningPathResponse | PromiseLike<LearningPathResponse> {
|
||||
throw new Error('Function not implemented.');
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { DWENGO_API_BASE } from '../../config.js';
|
||||
import { fetchWithLogging } from '../../util/apiHelper.js';
|
||||
import { fetchWithLogging } from '../../util/api-helper.js';
|
||||
import {
|
||||
FilteredLearningObject,
|
||||
LearningObjectIdentifier,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { fetchWithLogging } from '../../util/apiHelper.js';
|
||||
import { fetchWithLogging } from '../../util/api-helper.js';
|
||||
import { DWENGO_API_BASE } from '../../config.js';
|
||||
import { LearningPath, LearningPathResponse } from '../../interfaces/learning-content.js';
|
||||
import { LearningPathProvider } from './learning-path-provider.js';
|
||||
|
|
|
@ -7,6 +7,7 @@ import {QuestionRepository} from "../data/questions/question-repository.js";
|
|||
import {LearningObjectIdentifier} from "../entities/content/learning-object-identifier.js";
|
||||
import {mapToUser} from "../interfaces/user.js";
|
||||
import {Student} from "../entities/users/student.entity.js";
|
||||
import { mapToStudent } from "../interfaces/student.js";
|
||||
|
||||
export async function getAllQuestions(
|
||||
id: LearningObjectIdentifier, full: boolean
|
||||
|
@ -72,7 +73,7 @@ export async function getAnswersByQuestion(questionId: QuestionId, full: boolean
|
|||
export async function createQuestion(questionDTO: QuestionDTO) {
|
||||
const questionRepository = getQuestionRepository();
|
||||
|
||||
const author = mapToUser<Student>(questionDTO.author, new Student())
|
||||
const author = mapToStudent(questionDTO.author);
|
||||
|
||||
try {
|
||||
await questionRepository.createQuestion({
|
||||
|
|
|
@ -9,13 +9,61 @@ import { Student } from '../entities/users/student.entity.js';
|
|||
import { AssignmentDTO } from '../interfaces/assignment.js';
|
||||
import { ClassDTO, mapToClassDTO } from '../interfaces/class.js';
|
||||
import { GroupDTO, mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js';
|
||||
import { mapToStudent, mapToStudentDTO, StudentDTO } from '../interfaces/student.js';
|
||||
import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js';
|
||||
import { getAllAssignments } from './assignments.js';
|
||||
import { UserService } from './users.js';
|
||||
|
||||
export class StudentService extends UserService<Student> {
|
||||
constructor() {
|
||||
super(getStudentRepository());
|
||||
|
||||
export async function getAllStudents(): Promise<StudentDTO[]> {
|
||||
const studentRepository = getStudentRepository();
|
||||
const users = await studentRepository.findAll();
|
||||
return users.map(mapToStudentDTO);
|
||||
}
|
||||
|
||||
export async function getAllStudentIds(): Promise<string[]> {
|
||||
const users = await getAllStudents();
|
||||
return users.map((user) => {
|
||||
return user.username;
|
||||
});
|
||||
}
|
||||
|
||||
export async function getStudent(username: string): Promise<StudentDTO | null> {
|
||||
const studentRepository = getStudentRepository();
|
||||
const user = await studentRepository.findByUsername(username);
|
||||
return user ? mapToStudentDTO(user) : null;
|
||||
}
|
||||
|
||||
export async function createStudent(userData: StudentDTO): Promise<StudentDTO | null> {
|
||||
const studentRepository = getStudentRepository();
|
||||
|
||||
try {
|
||||
const newStudent = studentRepository.create(mapToStudent(userData));
|
||||
await studentRepository.save(newStudent);
|
||||
|
||||
return mapToStudentDTO(newStudent);
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteStudent(username: string): Promise<StudentDTO | null> {
|
||||
const studentRepository = getStudentRepository();
|
||||
|
||||
const user = await studentRepository.findByUsername(username);
|
||||
|
||||
if (!user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
await studentRepository.deleteByUsername(username);
|
||||
|
||||
return mapToStudentDTO(user);
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import {mapToSubmission, mapToSubmissionDTO, SubmissionDTO} from "../interfaces/
|
|||
export async function getSubmission(
|
||||
learningObjectHruid: string,
|
||||
language: Language,
|
||||
version: string,
|
||||
version: number,
|
||||
submissionNumber: number,
|
||||
): Promise<SubmissionDTO | null> {
|
||||
const loId = new LearningObjectIdentifier(learningObjectHruid, language, version);
|
||||
|
@ -38,7 +38,7 @@ export async function createSubmission(submissionDTO: SubmissionDTO) {
|
|||
export async function deleteSubmission(
|
||||
learningObjectHruid: string,
|
||||
language: Language,
|
||||
version: string,
|
||||
version: number,
|
||||
submissionNumber: number
|
||||
) {
|
||||
const submissionRepository = getSubmissionRepository();
|
||||
|
|
|
@ -17,93 +17,133 @@ import {
|
|||
} from '../interfaces/question.js';
|
||||
import { UserService } from './users.js';
|
||||
import { mapToUser } from '../interfaces/user.js';
|
||||
import { mapToTeacher, mapToTeacherDTO, TeacherDTO } from '../interfaces/teacher.js';
|
||||
|
||||
export class TeacherUserService extends UserService<Teacher> {
|
||||
constructor() {
|
||||
super(getTeacherRepository());
|
||||
export async function getAllTeachers(): Promise<TeacherDTO[]> {
|
||||
const teacherRepository = getTeacherRepository();
|
||||
const users = await teacherRepository.findAll();
|
||||
return users.map(mapToTeacherDTO);
|
||||
}
|
||||
|
||||
export async function getAllTeacherIds(): Promise<string[]> {
|
||||
const users = await getAllTeachers();
|
||||
return users.map((user) => {
|
||||
return user.username;
|
||||
});
|
||||
}
|
||||
|
||||
export async function getTeacher(username: string): Promise<TeacherDTO | null> {
|
||||
const teacherRepository = getTeacherRepository();
|
||||
const user = await teacherRepository.findByUsername(username);
|
||||
return user ? mapToTeacherDTO(user) : null;
|
||||
}
|
||||
|
||||
export async function createTeacher(userData: TeacherDTO): Promise<TeacherDTO | null> {
|
||||
const teacherRepository = getTeacherRepository();
|
||||
|
||||
try {
|
||||
const newTeacher = teacherRepository.create(mapToTeacher(userData));
|
||||
await teacherRepository.save(newTeacher);
|
||||
|
||||
return mapToTeacherDTO(newTeacher);
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export class TeacherService {
|
||||
protected teacherService = new TeacherUserService();
|
||||
protected teacherRepository = getTeacherRepository();
|
||||
protected classRepository = getClassRepository();
|
||||
protected learningObjectRepository = getLearningObjectRepository();
|
||||
protected questionRepository = getQuestionRepository();
|
||||
export async function deleteTeacher(username: string): Promise<TeacherDTO | null> {
|
||||
const teacherRepository = getTeacherRepository();
|
||||
|
||||
async fetchClassesByTeacher(username: string): Promise<ClassDTO[]> {
|
||||
const teacher = await this.teacherRepository.findByUsername(username);
|
||||
if (!teacher) {
|
||||
return [];
|
||||
}
|
||||
const user = await teacherRepository.findByUsername(username);
|
||||
|
||||
const classes = await this.classRepository.findByTeacher(teacher);
|
||||
return classes.map(mapToClassDTO);
|
||||
if (!user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
async getClassesByTeacher(username: string): Promise<ClassDTO[]> {
|
||||
return await this.fetchClassesByTeacher(username);
|
||||
}
|
||||
|
||||
async getClassIdsByTeacher(username: string): Promise<string[]> {
|
||||
const classes = await this.fetchClassesByTeacher(username);
|
||||
return classes.map((cls) => {
|
||||
return cls.id;
|
||||
});
|
||||
}
|
||||
|
||||
async fetchStudentsByTeacher(username: string) {
|
||||
const classes = await this.getClassIdsByTeacher(username);
|
||||
|
||||
return (
|
||||
await Promise.all(
|
||||
classes.map(async (id) => {
|
||||
return getClassStudents(id);
|
||||
})
|
||||
)
|
||||
).flat();
|
||||
}
|
||||
|
||||
async getStudentsByTeacher(username: string): Promise<StudentDTO[]> {
|
||||
return await this.fetchStudentsByTeacher(username);
|
||||
}
|
||||
|
||||
async getStudentIdsByTeacher(username: string): Promise<string[]> {
|
||||
const students = await this.fetchStudentsByTeacher(username);
|
||||
return students.map((student) => {
|
||||
return student.username;
|
||||
});
|
||||
}
|
||||
|
||||
async fetchTeacherQuestions(username: string): Promise<QuestionDTO[]> {
|
||||
const teacherDTO =
|
||||
await this.teacherService.getUserByUsername(username);
|
||||
if (!teacherDTO) {
|
||||
throw new Error(`Teacher with username '${username}' not found.`);
|
||||
}
|
||||
|
||||
const teacher = mapToUser<Teacher>(teacherDTO, new Teacher());
|
||||
|
||||
// Find all learning objects that this teacher manages
|
||||
const learningObjects =
|
||||
await this.learningObjectRepository.findAllByTeacher(teacher);
|
||||
|
||||
// Fetch all questions related to these learning objects
|
||||
const questions =
|
||||
await this.questionRepository.findAllByLearningObjects(
|
||||
learningObjects
|
||||
);
|
||||
|
||||
return questions.map(mapToQuestionDTO);
|
||||
}
|
||||
|
||||
async getQuestionsByTeacher(username: string): Promise<QuestionDTO[]> {
|
||||
return await this.fetchTeacherQuestions(username);
|
||||
}
|
||||
|
||||
async getQuestionIdsByTeacher(username: string): Promise<QuestionId[]> {
|
||||
const questions = await this.fetchTeacherQuestions(username);
|
||||
|
||||
return questions.map(mapToQuestionId);
|
||||
try {
|
||||
await teacherRepository.deleteByUsername(username);
|
||||
|
||||
return mapToTeacherDTO(user);
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchClassesByTeacher(username: string): Promise<ClassDTO[]> {
|
||||
const teacherRepository = getTeacherRepository();
|
||||
const teacher = await teacherRepository.findByUsername(username);
|
||||
if (!teacher) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const classRepository = getClassRepository();
|
||||
const classes = await classRepository.findByTeacher(teacher);
|
||||
return classes.map(mapToClassDTO);
|
||||
}
|
||||
|
||||
export async function getClassesByTeacher(username: string): Promise<ClassDTO[]> {
|
||||
return await fetchClassesByTeacher(username);
|
||||
}
|
||||
|
||||
export async function getClassIdsByTeacher(username: string): Promise<string[]> {
|
||||
const classes = await fetchClassesByTeacher(username);
|
||||
return classes.map((cls) => {
|
||||
return cls.id;
|
||||
});
|
||||
}
|
||||
|
||||
export async function fetchStudentsByTeacher(username: string) {
|
||||
const classes = await getClassIdsByTeacher(username);
|
||||
|
||||
return (
|
||||
await Promise.all(
|
||||
classes.map(async (id) => {
|
||||
return getClassStudents(id);
|
||||
})
|
||||
)
|
||||
).flat();
|
||||
}
|
||||
|
||||
export async function getStudentsByTeacher(username: string): Promise<StudentDTO[]> {
|
||||
return await fetchStudentsByTeacher(username);
|
||||
}
|
||||
|
||||
export async function getStudentIdsByTeacher(username: string): Promise<string[]> {
|
||||
const students = await fetchStudentsByTeacher(username);
|
||||
return students.map((student) => {
|
||||
return student.username;
|
||||
});
|
||||
}
|
||||
|
||||
export async function fetchTeacherQuestions(username: string): Promise<QuestionDTO[]> {
|
||||
const teacherRepository = getTeacherRepository();
|
||||
const teacher = await teacherRepository.findByUsername(username);
|
||||
if (!teacher) {
|
||||
throw new Error(`Teacher with username '${username}' not found.`);
|
||||
}
|
||||
|
||||
// Find all learning objects that this teacher manages
|
||||
const learningObjectRepository = getLearningObjectRepository();
|
||||
const learningObjects = await learningObjectRepository.findAllByTeacher(teacher);
|
||||
|
||||
// Fetch all questions related to these learning objects
|
||||
const questionRepository = getQuestionRepository();
|
||||
const questions =
|
||||
await questionRepository.findAllByLearningObjects(
|
||||
learningObjects
|
||||
);
|
||||
|
||||
return questions.map(mapToQuestionDTO);
|
||||
}
|
||||
|
||||
export async function getQuestionsByTeacher(username: string): Promise<QuestionDTO[]> {
|
||||
return await fetchTeacherQuestions(username);
|
||||
}
|
||||
|
||||
export async function getQuestionIdsByTeacher(username: string): Promise<QuestionId[]> {
|
||||
const questions = await fetchTeacherQuestions(username);
|
||||
|
||||
return questions.map(mapToQuestionId);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue