style: fix linting issues met Prettier
This commit is contained in:
parent
e78849f568
commit
400a955850
40 changed files with 321 additions and 700 deletions
|
@ -1,22 +1,9 @@
|
|||
import {
|
||||
getAssignmentRepository,
|
||||
getClassRepository,
|
||||
getGroupRepository,
|
||||
getSubmissionRepository,
|
||||
} from '../data/repositories.js';
|
||||
import { getAssignmentRepository, getClassRepository, getGroupRepository, getSubmissionRepository } from '../data/repositories.js';
|
||||
import { Assignment } from '../entities/assignments/assignment.entity.js';
|
||||
import {
|
||||
AssignmentDTO,
|
||||
mapToAssignment,
|
||||
mapToAssignmentDTO,
|
||||
mapToAssignmentDTOId,
|
||||
} from '../interfaces/assignment.js';
|
||||
import { AssignmentDTO, mapToAssignment, mapToAssignmentDTO, mapToAssignmentDTOId } from '../interfaces/assignment.js';
|
||||
import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js';
|
||||
|
||||
export async function getAllAssignments(
|
||||
classid: string,
|
||||
full: boolean
|
||||
): Promise<AssignmentDTO[]> {
|
||||
export async function getAllAssignments(classid: string, full: boolean): Promise<AssignmentDTO[]> {
|
||||
const classRepository = getClassRepository();
|
||||
const cls = await classRepository.findById(classid);
|
||||
|
||||
|
@ -25,8 +12,7 @@ export async function getAllAssignments(
|
|||
}
|
||||
|
||||
const assignmentRepository = getAssignmentRepository();
|
||||
const assignments =
|
||||
await assignmentRepository.findAllAssignmentsInClass(cls);
|
||||
const assignments = await assignmentRepository.findAllAssignmentsInClass(cls);
|
||||
|
||||
if (full) {
|
||||
return assignments.map(mapToAssignmentDTO);
|
||||
|
@ -35,14 +21,11 @@ export async function getAllAssignments(
|
|||
return assignments.map(mapToAssignmentDTOId);
|
||||
}
|
||||
|
||||
export async function createAssignment(
|
||||
classid: string,
|
||||
assignmentData: AssignmentDTO,
|
||||
): Promise<Assignment | null> {
|
||||
export async function createAssignment(classid: string, assignmentData: AssignmentDTO): Promise<Assignment | null> {
|
||||
const classRepository = getClassRepository();
|
||||
const cls = await classRepository.findById(classid);
|
||||
|
||||
if (!cls) {
|
||||
if (!cls) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -54,16 +37,12 @@ export async function createAssignment(
|
|||
await assignmentRepository.save(newAssignment);
|
||||
|
||||
return newAssignment;
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export async function getAssignment(
|
||||
classid: string,
|
||||
id: number
|
||||
): Promise<AssignmentDTO | null> {
|
||||
export async function getAssignment(classid: string, id: number): Promise<AssignmentDTO | null> {
|
||||
const classRepository = getClassRepository();
|
||||
const cls = await classRepository.findById(classid);
|
||||
|
||||
|
@ -81,10 +60,7 @@ export async function getAssignment(
|
|||
return mapToAssignmentDTO(assignment);
|
||||
}
|
||||
|
||||
export async function getAssignmentsSubmissions(
|
||||
classid: string,
|
||||
assignmentNumber: number,
|
||||
): Promise<SubmissionDTO[]> {
|
||||
export async function getAssignmentsSubmissions(classid: string, assignmentNumber: number): Promise<SubmissionDTO[]> {
|
||||
const classRepository = getClassRepository();
|
||||
const cls = await classRepository.findById(classid);
|
||||
|
||||
|
@ -103,8 +79,7 @@ export async function getAssignmentsSubmissions(
|
|||
const groups = await groupRepository.findAllGroupsForAssignment(assignment);
|
||||
|
||||
const submissionRepository = getSubmissionRepository();
|
||||
const submissions =
|
||||
(await Promise.all(groups.map(group => submissionRepository.findAllSubmissionsForGroup(group)))).flat();
|
||||
const submissions = (await Promise.all(groups.map((group) => submissionRepository.findAllSubmissionsForGroup(group)))).flat();
|
||||
|
||||
return submissions.map(mapToSubmissionDTO);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,12 @@
|
|||
import {
|
||||
getClassRepository,
|
||||
getStudentRepository,
|
||||
getTeacherInvitationRepository,
|
||||
getTeacherRepository,
|
||||
} from '../data/repositories.js';
|
||||
import { getClassRepository, getStudentRepository, getTeacherInvitationRepository, getTeacherRepository } from '../data/repositories.js';
|
||||
import { Class } from '../entities/classes/class.entity.js';
|
||||
import { ClassDTO, mapToClassDTO } from '../interfaces/class.js';
|
||||
import { mapToStudentDTO, StudentDTO } from '../interfaces/student.js';
|
||||
import {
|
||||
mapToTeacherInvitationDTO,
|
||||
mapToTeacherInvitationDTOIds,
|
||||
TeacherInvitationDTO,
|
||||
} from '../interfaces/teacher-invitation.js';
|
||||
import { mapToTeacherInvitationDTO, mapToTeacherInvitationDTOIds, TeacherInvitationDTO } from '../interfaces/teacher-invitation.js';
|
||||
|
||||
export async function getAllClasses(
|
||||
full: boolean
|
||||
): Promise<ClassDTO[] | string[]> {
|
||||
export async function getAllClasses(full: boolean): Promise<ClassDTO[] | string[]> {
|
||||
const classRepository = getClassRepository();
|
||||
const classes = await classRepository.find(
|
||||
{},
|
||||
{ populate: ['students', 'teachers'] }
|
||||
);
|
||||
const classes = await classRepository.find({}, { populate: ['students', 'teachers'] });
|
||||
|
||||
if (!classes) {
|
||||
return [];
|
||||
|
@ -35,13 +21,11 @@ export async function getAllClasses(
|
|||
export async function createClass(classData: ClassDTO): Promise<Class | null> {
|
||||
const teacherRepository = getTeacherRepository();
|
||||
const teacherUsernames = classData.teachers || [];
|
||||
const teachers = (await Promise.all(teacherUsernames.map(id => teacherRepository.findByUsername(id))))
|
||||
.filter(teacher => teacher != null);
|
||||
const teachers = (await Promise.all(teacherUsernames.map((id) => teacherRepository.findByUsername(id)))).filter((teacher) => teacher != null);
|
||||
|
||||
const studentRepository = getStudentRepository();
|
||||
const studentUsernames = classData.students || [];
|
||||
const students = (await Promise.all(studentUsernames.map(id => studentRepository.findByUsername(id))))
|
||||
.filter(student => student != null);
|
||||
const students = (await Promise.all(studentUsernames.map((id) => studentRepository.findByUsername(id)))).filter((student) => student != null);
|
||||
|
||||
//Const cls = mapToClass(classData, teachers, students);
|
||||
|
||||
|
@ -56,7 +40,7 @@ export async function createClass(classData: ClassDTO): Promise<Class | null> {
|
|||
await classRepository.save(newClass);
|
||||
|
||||
return newClass;
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -92,10 +76,7 @@ export async function getClassStudentsIds(classId: string): Promise<string[]> {
|
|||
return students.map((student) => student.username);
|
||||
}
|
||||
|
||||
export async function getClassTeacherInvitations(
|
||||
classId: string,
|
||||
full: boolean
|
||||
): Promise<TeacherInvitationDTO[]> {
|
||||
export async function getClassTeacherInvitations(classId: string, full: boolean): Promise<TeacherInvitationDTO[]> {
|
||||
const classRepository = getClassRepository();
|
||||
const cls = await classRepository.findById(classId);
|
||||
|
||||
|
@ -104,8 +85,7 @@ export async function getClassTeacherInvitations(
|
|||
}
|
||||
|
||||
const teacherInvitationRepository = getTeacherInvitationRepository();
|
||||
const invitations =
|
||||
await teacherInvitationRepository.findAllInvitationsForClass(cls);
|
||||
const invitations = await teacherInvitationRepository.findAllInvitationsForClass(cls);
|
||||
|
||||
if (full) {
|
||||
return invitations.map(mapToTeacherInvitationDTO);
|
||||
|
|
|
@ -7,19 +7,10 @@ import {
|
|||
getSubmissionRepository,
|
||||
} from '../data/repositories.js';
|
||||
import { Group } from '../entities/assignments/group.entity.js';
|
||||
import {
|
||||
GroupDTO,
|
||||
mapToGroupDTO,
|
||||
mapToGroupDTOId,
|
||||
} from '../interfaces/group.js';
|
||||
import { GroupDTO, mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js';
|
||||
import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js';
|
||||
|
||||
export async function getGroup(
|
||||
classId: string,
|
||||
assignmentNumber: number,
|
||||
groupNumber: number,
|
||||
full: boolean
|
||||
): Promise<GroupDTO | null> {
|
||||
export async function getGroup(classId: string, assignmentNumber: number, groupNumber: number, full: boolean): Promise<GroupDTO | null> {
|
||||
const classRepository = getClassRepository();
|
||||
const cls = await classRepository.findById(classId);
|
||||
|
||||
|
@ -28,20 +19,14 @@ export async function getGroup(
|
|||
}
|
||||
|
||||
const assignmentRepository = getAssignmentRepository();
|
||||
const assignment = await assignmentRepository.findByClassAndId(
|
||||
cls,
|
||||
assignmentNumber
|
||||
);
|
||||
const assignment = await assignmentRepository.findByClassAndId(cls, assignmentNumber);
|
||||
|
||||
if (!assignment) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const groupRepository = getGroupRepository();
|
||||
const group = await groupRepository.findByAssignmentAndGroupNumber(
|
||||
assignment,
|
||||
groupNumber
|
||||
);
|
||||
const group = await groupRepository.findByAssignmentAndGroupNumber(assignment, groupNumber);
|
||||
|
||||
if (!group) {
|
||||
return null;
|
||||
|
@ -54,16 +39,11 @@ export async function getGroup(
|
|||
return mapToGroupDTOId(group);
|
||||
}
|
||||
|
||||
export async function createGroup(
|
||||
groupData: GroupDTO,
|
||||
classid: string,
|
||||
assignmentNumber: number,
|
||||
): Promise<Group | null> {
|
||||
export async function createGroup(groupData: GroupDTO, classid: string, assignmentNumber: number): Promise<Group | null> {
|
||||
const studentRepository = getStudentRepository();
|
||||
|
||||
const memberUsernames = groupData.members as string[] || []; // TODO check if groupdata.members is a list
|
||||
const members = (await Promise.all([...memberUsernames].map(id => studentRepository.findByUsername(id))))
|
||||
.filter(student => student != null);
|
||||
const memberUsernames = (groupData.members as string[]) || []; // TODO check if groupdata.members is a list
|
||||
const members = (await Promise.all([...memberUsernames].map((id) => studentRepository.findByUsername(id)))).filter((student) => student != null);
|
||||
|
||||
console.log(members);
|
||||
|
||||
|
@ -90,17 +70,13 @@ export async function createGroup(
|
|||
await groupRepository.save(newGroup);
|
||||
|
||||
return newGroup;
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getAllGroups(
|
||||
classId: string,
|
||||
assignmentNumber: number,
|
||||
full: boolean
|
||||
): Promise<GroupDTO[]> {
|
||||
export async function getAllGroups(classId: string, assignmentNumber: number, full: boolean): Promise<GroupDTO[]> {
|
||||
const classRepository = getClassRepository();
|
||||
const cls = await classRepository.findById(classId);
|
||||
|
||||
|
@ -109,10 +85,7 @@ export async function getAllGroups(
|
|||
}
|
||||
|
||||
const assignmentRepository = getAssignmentRepository();
|
||||
const assignment = await assignmentRepository.findByClassAndId(
|
||||
cls,
|
||||
assignmentNumber
|
||||
);
|
||||
const assignment = await assignmentRepository.findByClassAndId(cls, assignmentNumber);
|
||||
|
||||
if (!assignment) {
|
||||
return [];
|
||||
|
@ -130,11 +103,7 @@ export async function getAllGroups(
|
|||
return groups.map(mapToGroupDTOId);
|
||||
}
|
||||
|
||||
export async function getGroupSubmissions(
|
||||
classId: string,
|
||||
assignmentNumber: number,
|
||||
groupNumber: number,
|
||||
): Promise<SubmissionDTO[]> {
|
||||
export async function getGroupSubmissions(classId: string, assignmentNumber: number, groupNumber: number): Promise<SubmissionDTO[]> {
|
||||
const classRepository = getClassRepository();
|
||||
const cls = await classRepository.findById(classId);
|
||||
|
||||
|
@ -143,20 +112,14 @@ export async function getGroupSubmissions(
|
|||
}
|
||||
|
||||
const assignmentRepository = getAssignmentRepository();
|
||||
const assignment = await assignmentRepository.findByClassAndId(
|
||||
cls,
|
||||
assignmentNumber
|
||||
);
|
||||
const assignment = await assignmentRepository.findByClassAndId(cls, assignmentNumber);
|
||||
|
||||
if (!assignment) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const groupRepository = getGroupRepository();
|
||||
const group = await groupRepository.findByAssignmentAndGroupNumber(
|
||||
assignment,
|
||||
groupNumber
|
||||
);
|
||||
const group = await groupRepository.findByAssignmentAndGroupNumber(assignment, groupNumber);
|
||||
|
||||
if (!group) {
|
||||
return [];
|
||||
|
|
|
@ -1,16 +1,8 @@
|
|||
import { DWENGO_API_BASE } from '../config.js';
|
||||
import { fetchWithLogging } from '../util/api-helper.js';
|
||||
import {
|
||||
FilteredLearningObject,
|
||||
LearningObjectMetadata,
|
||||
LearningObjectNode,
|
||||
LearningPathResponse,
|
||||
} from '../interfaces/learning-content.js';
|
||||
import { FilteredLearningObject, LearningObjectMetadata, LearningObjectNode, LearningPathResponse } from '../interfaces/learning-content.js';
|
||||
|
||||
function filterData(
|
||||
data: LearningObjectMetadata,
|
||||
htmlUrl: string
|
||||
): FilteredLearningObject {
|
||||
function filterData(data: LearningObjectMetadata, htmlUrl: string): FilteredLearningObject {
|
||||
return {
|
||||
key: data.hruid, // Hruid learningObject (not path)
|
||||
_id: data._id,
|
||||
|
@ -37,10 +29,7 @@ function filterData(
|
|||
/**
|
||||
* Fetches a single learning object by its HRUID
|
||||
*/
|
||||
export async function getLearningObjectById(
|
||||
hruid: string,
|
||||
language: string
|
||||
): Promise<FilteredLearningObject | null> {
|
||||
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,
|
||||
|
@ -59,26 +48,12 @@ export async function getLearningObjectById(
|
|||
/**
|
||||
* Generic function to fetch learning objects (full data or just HRUIDs)
|
||||
*/
|
||||
async function fetchLearningObjects(
|
||||
hruid: string,
|
||||
full: boolean,
|
||||
language: string
|
||||
): Promise<FilteredLearningObject[] | string[]> {
|
||||
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}"`
|
||||
);
|
||||
const learningPathResponse: LearningPathResponse = await fetchLearningPaths([hruid], language, `Learning path for HRUID "${hruid}"`);
|
||||
|
||||
if (
|
||||
!learningPathResponse.success ||
|
||||
!learningPathResponse.data?.length
|
||||
) {
|
||||
console.error(
|
||||
`⚠️ WARNING: Learning path "${hruid}" exists but contains no learning objects.`
|
||||
);
|
||||
if (!learningPathResponse.success || !learningPathResponse.data?.length) {
|
||||
console.error(`⚠️ WARNING: Learning path "${hruid}" exists but contains no learning objects.`);
|
||||
return [];
|
||||
}
|
||||
|
||||
|
@ -88,12 +63,9 @@ async function fetchLearningObjects(
|
|||
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));
|
||||
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) {
|
||||
console.error('❌ Error fetching learning objects:', error);
|
||||
return [];
|
||||
|
@ -103,27 +75,16 @@ async function fetchLearningObjects(
|
|||
/**
|
||||
* Fetch full learning object data (metadata)
|
||||
*/
|
||||
export async function getLearningObjectsFromPath(
|
||||
hruid: string,
|
||||
language: string
|
||||
): Promise<FilteredLearningObject[]> {
|
||||
return (await fetchLearningObjects(
|
||||
hruid,
|
||||
true,
|
||||
language
|
||||
)) as FilteredLearningObject[];
|
||||
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[]> {
|
||||
export async function getLearningObjectIdsFromPath(hruid: string, language: string): 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,17 +1,15 @@
|
|||
import {getAnswerRepository, getQuestionRepository} from "../data/repositories.js";
|
||||
import {mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId} from "../interfaces/question.js";
|
||||
import {Question} from "../entities/questions/question.entity.js";
|
||||
import {Answer} from "../entities/questions/answer.entity.js";
|
||||
import {mapToAnswerDTO, mapToAnswerId} from "../interfaces/answer.js";
|
||||
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";
|
||||
import { getAnswerRepository, getQuestionRepository } from '../data/repositories.js';
|
||||
import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js';
|
||||
import { Question } from '../entities/questions/question.entity.js';
|
||||
import { Answer } from '../entities/questions/answer.entity.js';
|
||||
import { mapToAnswerDTO, mapToAnswerId } from '../interfaces/answer.js';
|
||||
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
|
||||
): Promise<QuestionDTO[] | QuestionId[]> {
|
||||
export async function getAllQuestions(id: LearningObjectIdentifier, full: boolean): Promise<QuestionDTO[] | QuestionId[]> {
|
||||
const questionRepository: QuestionRepository = getQuestionRepository();
|
||||
const questions = await questionRepository.findAllQuestionsAboutLearningObject(id);
|
||||
|
||||
|
@ -19,7 +17,7 @@ export async function getAllQuestions(
|
|||
return [];
|
||||
}
|
||||
|
||||
const questionsDTO: QuestionDTO[] = questions.map(mapToQuestionDTO);
|
||||
const questionsDTO: QuestionDTO[] = questions.map(mapToQuestionDTO);
|
||||
|
||||
if (full) {
|
||||
return questionsDTO;
|
||||
|
@ -31,21 +29,20 @@ export async function getAllQuestions(
|
|||
async function fetchQuestion(questionId: QuestionId): Promise<Question | null> {
|
||||
const questionRepository = getQuestionRepository();
|
||||
|
||||
return await questionRepository.findOne(
|
||||
{
|
||||
learningObjectHruid: questionId.learningObjectIdentifier.hruid,
|
||||
learningObjectLanguage: questionId.learningObjectIdentifier.language,
|
||||
learningObjectVersion: questionId.learningObjectIdentifier.version,
|
||||
sequenceNumber: questionId.sequenceNumber
|
||||
}
|
||||
)
|
||||
return await questionRepository.findOne({
|
||||
learningObjectHruid: questionId.learningObjectIdentifier.hruid,
|
||||
learningObjectLanguage: questionId.learningObjectIdentifier.language,
|
||||
learningObjectVersion: questionId.learningObjectIdentifier.version,
|
||||
sequenceNumber: questionId.sequenceNumber,
|
||||
});
|
||||
}
|
||||
|
||||
export async function getQuestion(questionId: QuestionId): Promise<QuestionDTO | null> {
|
||||
const question = await fetchQuestion(questionId);
|
||||
|
||||
if (!question)
|
||||
{return null}
|
||||
if (!question) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return mapToQuestionDTO(question);
|
||||
}
|
||||
|
@ -54,18 +51,21 @@ export async function getAnswersByQuestion(questionId: QuestionId, full: boolean
|
|||
const answerRepository = getAnswerRepository();
|
||||
const question = await fetchQuestion(questionId);
|
||||
|
||||
if (!question)
|
||||
{return [];}
|
||||
if (!question) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const answers: Answer[] = await answerRepository.findAllAnswersToQuestion(question);
|
||||
|
||||
if (!answers)
|
||||
{return []}
|
||||
if (!answers) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const answersDTO = answers.map(mapToAnswerDTO);
|
||||
|
||||
if (full)
|
||||
{return answersDTO}
|
||||
if (full) {
|
||||
return answersDTO;
|
||||
}
|
||||
|
||||
return answersDTO.map(mapToAnswerId);
|
||||
}
|
||||
|
@ -79,10 +79,10 @@ export async function createQuestion(questionDTO: QuestionDTO) {
|
|||
await questionRepository.createQuestion({
|
||||
loId: questionDTO.learningObjectIdentifier,
|
||||
author,
|
||||
content: questionDTO.content }
|
||||
);
|
||||
content: questionDTO.content,
|
||||
});
|
||||
} catch (e) {
|
||||
return null
|
||||
return null;
|
||||
}
|
||||
|
||||
return questionDTO;
|
||||
|
@ -93,18 +93,15 @@ export async function deleteQuestion(questionId: QuestionId) {
|
|||
|
||||
const question = await fetchQuestion(questionId);
|
||||
|
||||
if (!question)
|
||||
{return null}
|
||||
|
||||
try {
|
||||
await questionRepository.removeQuestionByLearningObjectAndSequenceNumber(
|
||||
questionId.learningObjectIdentifier, questionId.sequenceNumber
|
||||
);
|
||||
} catch (e) {
|
||||
return null
|
||||
if (!question) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return question
|
||||
try {
|
||||
await questionRepository.removeQuestionByLearningObjectAndSequenceNumber(questionId.learningObjectIdentifier, questionId.sequenceNumber);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return question;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
import {
|
||||
getClassRepository,
|
||||
getGroupRepository,
|
||||
getStudentRepository,
|
||||
getSubmissionRepository,
|
||||
} from '../data/repositories.js';
|
||||
import { getClassRepository, getGroupRepository, getStudentRepository, getSubmissionRepository } from '../data/repositories.js';
|
||||
import { Class } from '../entities/classes/class.entity.js';
|
||||
import { Student } from '../entities/users/student.entity.js';
|
||||
import { AssignmentDTO } from '../interfaces/assignment.js';
|
||||
|
@ -14,7 +9,6 @@ import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js';
|
|||
import { getAllAssignments } from './assignments.js';
|
||||
import { UserService } from './users.js';
|
||||
|
||||
|
||||
export async function getAllStudents(): Promise<StudentDTO[]> {
|
||||
const studentRepository = getStudentRepository();
|
||||
const users = await studentRepository.findAll();
|
||||
|
@ -38,9 +32,9 @@ export async function createStudent(userData: StudentDTO): Promise<StudentDTO |
|
|||
try {
|
||||
const newStudent = studentRepository.create(mapToStudent(userData));
|
||||
await studentRepository.save(newStudent);
|
||||
|
||||
|
||||
return mapToStudentDTO(newStudent);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return null;
|
||||
}
|
||||
|
@ -57,9 +51,9 @@ export async function deleteStudent(username: string): Promise<StudentDTO | null
|
|||
|
||||
try {
|
||||
await studentRepository.deleteByUsername(username);
|
||||
|
||||
|
||||
return mapToStudentDTO(user);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return null;
|
||||
}
|
||||
|
@ -94,11 +88,7 @@ export async function getStudentAssignments(username: string, full: boolean): Pr
|
|||
const classRepository = getClassRepository();
|
||||
const classes = await classRepository.findByStudent(student);
|
||||
|
||||
const assignments = (
|
||||
await Promise.all(
|
||||
classes.map(async (cls) => await getAllAssignments(cls.classId!, full))
|
||||
)
|
||||
).flat();
|
||||
const assignments = (await Promise.all(classes.map(async (cls) => await getAllAssignments(cls.classId!, full)))).flat();
|
||||
|
||||
return assignments;
|
||||
}
|
||||
|
@ -121,9 +111,7 @@ export async function getStudentGroups(username: string, full: boolean): Promise
|
|||
return groups.map(mapToGroupDTOId);
|
||||
}
|
||||
|
||||
export async function getStudentSubmissions(
|
||||
username: string
|
||||
): Promise<SubmissionDTO[]> {
|
||||
export async function getStudentSubmissions(username: string): Promise<SubmissionDTO[]> {
|
||||
const studentRepository = getStudentRepository();
|
||||
const student = await studentRepository.findByUsername(username);
|
||||
|
||||
|
@ -135,4 +123,4 @@ export async function getStudentSubmissions(
|
|||
const submissions = await submissionRepository.findAllSubmissionsForStudent(student);
|
||||
|
||||
return submissions.map(mapToSubmissionDTO);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import {getGroupRepository, getSubmissionRepository} from "../data/repositories.js";
|
||||
import { Language } from "../entities/content/language.js";
|
||||
import { LearningObjectIdentifier } from "../entities/content/learning-object-identifier.js";
|
||||
import {mapToSubmission, mapToSubmissionDTO, SubmissionDTO} from "../interfaces/submission.js";
|
||||
import { getGroupRepository, getSubmissionRepository } from '../data/repositories.js';
|
||||
import { Language } from '../entities/content/language.js';
|
||||
import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js';
|
||||
import { mapToSubmission, mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js';
|
||||
|
||||
export async function getSubmission(
|
||||
learningObjectHruid: string,
|
||||
language: Language,
|
||||
version: number,
|
||||
submissionNumber: number,
|
||||
submissionNumber: number
|
||||
): Promise<SubmissionDTO | null> {
|
||||
const loId = new LearningObjectIdentifier(learningObjectHruid, language, version);
|
||||
|
||||
|
@ -29,29 +29,23 @@ export async function createSubmission(submissionDTO: SubmissionDTO) {
|
|||
const newSubmission = await submissionRepository.create(submission);
|
||||
await submissionRepository.save(newSubmission);
|
||||
} catch (e) {
|
||||
return null
|
||||
return null;
|
||||
}
|
||||
|
||||
return submission;
|
||||
}
|
||||
|
||||
export async function deleteSubmission(
|
||||
learningObjectHruid: string,
|
||||
language: Language,
|
||||
version: number,
|
||||
submissionNumber: number
|
||||
) {
|
||||
export async function deleteSubmission(learningObjectHruid: string, language: Language, version: number, submissionNumber: number) {
|
||||
const submissionRepository = getSubmissionRepository();
|
||||
|
||||
const submission = getSubmission(learningObjectHruid, language, version, submissionNumber);
|
||||
|
||||
if (!submission)
|
||||
{return null}
|
||||
if (!submission) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const loId = new LearningObjectIdentifier(learningObjectHruid, language, version);
|
||||
await submissionRepository.deleteSubmissionByLearningObjectAndSubmissionNumber(loId, submissionNumber);
|
||||
|
||||
return submission;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -9,12 +9,7 @@ import { Teacher } from '../entities/users/teacher.entity.js';
|
|||
import { ClassDTO, mapToClassDTO } from '../interfaces/class.js';
|
||||
import { getClassStudents } from './class.js';
|
||||
import { StudentDTO } from '../interfaces/student.js';
|
||||
import {
|
||||
mapToQuestionDTO,
|
||||
mapToQuestionId,
|
||||
QuestionDTO,
|
||||
QuestionId,
|
||||
} from '../interfaces/question.js';
|
||||
import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js';
|
||||
import { UserService } from './users.js';
|
||||
import { mapToUser } from '../interfaces/user.js';
|
||||
import { mapToTeacher, mapToTeacherDTO, TeacherDTO } from '../interfaces/teacher.js';
|
||||
|
@ -42,9 +37,9 @@ export async function createTeacher(userData: TeacherDTO): Promise<TeacherDTO |
|
|||
try {
|
||||
const newTeacher = teacherRepository.create(mapToTeacher(userData));
|
||||
await teacherRepository.save(newTeacher);
|
||||
|
||||
|
||||
return mapToTeacherDTO(newTeacher);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return null;
|
||||
}
|
||||
|
@ -61,9 +56,9 @@ export async function deleteTeacher(username: string): Promise<TeacherDTO | null
|
|||
|
||||
try {
|
||||
await teacherRepository.deleteByUsername(username);
|
||||
|
||||
|
||||
return mapToTeacherDTO(user);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return null;
|
||||
}
|
||||
|
@ -93,11 +88,7 @@ export async function getClassIdsByTeacher(username: string): Promise<string[]>
|
|||
export async function fetchStudentsByTeacher(username: string) {
|
||||
const classes = await getClassIdsByTeacher(username);
|
||||
|
||||
return (
|
||||
await Promise.all(
|
||||
classes.map(async (id) => getClassStudents(id))
|
||||
)
|
||||
).flat();
|
||||
return (await Promise.all(classes.map(async (id) => getClassStudents(id)))).flat();
|
||||
}
|
||||
|
||||
export async function getStudentsByTeacher(username: string): Promise<StudentDTO[]> {
|
||||
|
@ -122,10 +113,7 @@ export async function fetchTeacherQuestions(username: string): Promise<QuestionD
|
|||
|
||||
// Fetch all questions related to these learning objects
|
||||
const questionRepository = getQuestionRepository();
|
||||
const questions =
|
||||
await questionRepository.findAllByLearningObjects(
|
||||
learningObjects
|
||||
);
|
||||
const questions = await questionRepository.findAllByLearningObjects(learningObjects);
|
||||
|
||||
return questions.map(mapToQuestionDTO);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue