style: fix linting issues met Prettier
This commit is contained in:
parent
b963101f62
commit
34facfe7c8
12 changed files with 70 additions and 72 deletions
|
@ -1,8 +1,15 @@
|
||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
import { createAssignment, deleteAssignment, getAllAssignments, getAssignment, getAssignmentsSubmissions, putAssignment } from '../services/assignments.js';
|
import {
|
||||||
|
createAssignment,
|
||||||
|
deleteAssignment,
|
||||||
|
getAllAssignments,
|
||||||
|
getAssignment,
|
||||||
|
getAssignmentsSubmissions,
|
||||||
|
putAssignment,
|
||||||
|
} from '../services/assignments.js';
|
||||||
import { AssignmentDTO } from '@dwengo-1/common/interfaces/assignment';
|
import { AssignmentDTO } from '@dwengo-1/common/interfaces/assignment';
|
||||||
import {requireFields} from "./error-helper";
|
import { requireFields } from './error-helper';
|
||||||
import {BadRequestException} from "../exceptions/bad-request-exception";
|
import { BadRequestException } from '../exceptions/bad-request-exception';
|
||||||
import { getLogger } from '../logging/initalize.js';
|
import { getLogger } from '../logging/initalize.js';
|
||||||
import { Assignment } from '../entities/assignments/assignment.entity.js';
|
import { Assignment } from '../entities/assignments/assignment.entity.js';
|
||||||
import { EntityDTO } from '@mikro-orm/core';
|
import { EntityDTO } from '@mikro-orm/core';
|
||||||
|
@ -37,7 +44,7 @@ export async function getAssignmentHandler(req: Request, res: Response): Promise
|
||||||
requireFields({ id, classid });
|
requireFields({ id, classid });
|
||||||
|
|
||||||
if (isNaN(id)) {
|
if (isNaN(id)) {
|
||||||
throw new BadRequestException("Assignment id should be a number")
|
throw new BadRequestException('Assignment id should be a number');
|
||||||
}
|
}
|
||||||
|
|
||||||
const assignment = await getAssignment(classid, id);
|
const assignment = await getAssignment(classid, id);
|
||||||
|
@ -51,7 +58,7 @@ export async function putAssignmentHandler(req: Request, res: Response): Promise
|
||||||
requireFields({ id, classid });
|
requireFields({ id, classid });
|
||||||
|
|
||||||
if (isNaN(id)) {
|
if (isNaN(id)) {
|
||||||
throw new BadRequestException("Assignment id should be a number")
|
throw new BadRequestException('Assignment id should be a number');
|
||||||
}
|
}
|
||||||
|
|
||||||
const assignmentData = req.body as Partial<EntityDTO<Assignment>>;
|
const assignmentData = req.body as Partial<EntityDTO<Assignment>>;
|
||||||
|
@ -66,10 +73,10 @@ export async function deleteAssignmentHandler(req: Request, res: Response): Prom
|
||||||
requireFields({ id, classid });
|
requireFields({ id, classid });
|
||||||
|
|
||||||
if (isNaN(id)) {
|
if (isNaN(id)) {
|
||||||
throw new BadRequestException("Assignment id should be a number");
|
throw new BadRequestException('Assignment id should be a number');
|
||||||
}
|
}
|
||||||
|
|
||||||
const assignment = await deleteAssignment(classid, id);
|
const assignment = await deleteAssignment(classid, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAssignmentsSubmissionsHandler(req: Request, res: Response): Promise<void> {
|
export async function getAssignmentsSubmissionsHandler(req: Request, res: Response): Promise<void> {
|
||||||
|
@ -79,7 +86,7 @@ export async function getAssignmentsSubmissionsHandler(req: Request, res: Respon
|
||||||
requireFields({ assignmentNumber, classid });
|
requireFields({ assignmentNumber, classid });
|
||||||
|
|
||||||
if (isNaN(assignmentNumber)) {
|
if (isNaN(assignmentNumber)) {
|
||||||
throw new BadRequestException("Assignment id should be a number")
|
throw new BadRequestException('Assignment id should be a number');
|
||||||
}
|
}
|
||||||
|
|
||||||
const submissions = await getAssignmentsSubmissions(classid, assignmentNumber, full);
|
const submissions = await getAssignmentsSubmissions(classid, assignmentNumber, full);
|
||||||
|
|
|
@ -11,10 +11,10 @@ import {
|
||||||
getClassStudents,
|
getClassStudents,
|
||||||
getClassTeacherInvitations,
|
getClassTeacherInvitations,
|
||||||
getClassTeachers,
|
getClassTeachers,
|
||||||
putClass
|
putClass,
|
||||||
} from '../services/classes.js';
|
} from '../services/classes.js';
|
||||||
import { ClassDTO } from '@dwengo-1/common/interfaces/class';
|
import { ClassDTO } from '@dwengo-1/common/interfaces/class';
|
||||||
import {requireFields} from "./error-helper";
|
import { requireFields } from './error-helper';
|
||||||
import { EntityDTO } from '@mikro-orm/core';
|
import { EntityDTO } from '@mikro-orm/core';
|
||||||
import { Class } from '../entities/classes/class.entity.js';
|
import { Class } from '../entities/classes/class.entity.js';
|
||||||
|
|
||||||
|
|
|
@ -7,19 +7,17 @@ import { Language, languageMap } from '@dwengo-1/common/util/language';
|
||||||
import { SubmissionDTO } from '@dwengo-1/common/interfaces/submission';
|
import { SubmissionDTO } from '@dwengo-1/common/interfaces/submission';
|
||||||
import { requireFields } from './error-helper.js';
|
import { requireFields } from './error-helper.js';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export async function getSubmissionHandler(req: Request, res: Response): Promise<void> {
|
export async function getSubmissionHandler(req: Request, res: Response): Promise<void> {
|
||||||
const lohruid = req.params.hruid;
|
const lohruid = req.params.hruid;
|
||||||
const lang = languageMap[req.query.language as string] || Language.Dutch;
|
const lang = languageMap[req.query.language as string] || Language.Dutch;
|
||||||
const version = (req.query.version || 1) as number;
|
const version = (req.query.version || 1) as number;
|
||||||
const submissionNumber = Number(req.params.id);
|
const submissionNumber = Number(req.params.id);
|
||||||
requireFields({ lohruid, submissionNumber });
|
requireFields({ lohruid, submissionNumber });
|
||||||
|
|
||||||
if (isNaN(submissionNumber)) {
|
if (isNaN(submissionNumber)) {
|
||||||
throw new BadRequestException('Submission number must be a number');
|
throw new BadRequestException('Submission number must be a number');
|
||||||
}
|
}
|
||||||
|
|
||||||
const loId = new LearningObjectIdentifier(lohruid, lang, version);
|
const loId = new LearningObjectIdentifier(lohruid, lang, version);
|
||||||
const submission = await getSubmission(loId, submissionNumber);
|
const submission = await getSubmission(loId, submissionNumber);
|
||||||
|
|
||||||
|
@ -54,7 +52,7 @@ export async function deleteSubmissionHandler(req: Request, res: Response): Prom
|
||||||
requireFields({ hruid, submissionNumber });
|
requireFields({ hruid, submissionNumber });
|
||||||
|
|
||||||
if (isNaN(submissionNumber)) {
|
if (isNaN(submissionNumber)) {
|
||||||
throw new BadRequestException('Submission number must be a number');
|
throw new BadRequestException('Submission number must be a number');
|
||||||
}
|
}
|
||||||
|
|
||||||
const loId = new LearningObjectIdentifier(hruid, lang, version);
|
const loId = new LearningObjectIdentifier(hruid, lang, version);
|
||||||
|
|
|
@ -58,12 +58,12 @@ export class QuestionRepository extends DwengoEntityRepository<Question> {
|
||||||
|
|
||||||
public async findAllByAssignment(assignment: Assignment): Promise<Question[]> {
|
public async findAllByAssignment(assignment: Assignment): Promise<Question[]> {
|
||||||
return this.find({
|
return this.find({
|
||||||
author: assignment.groups.flatMap(group => group.members),
|
author: assignment.groups.flatMap((group) => group.members),
|
||||||
learningObjectHruid: assignment.learningPathHruid,
|
learningObjectHruid: assignment.learningPathHruid,
|
||||||
learningObjectLanguage: assignment.learningPathLanguage,
|
learningObjectLanguage: assignment.learningPathLanguage,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async findAllByAuthor(author: Student): Promise<Question[]> {
|
public async findAllByAuthor(author: Student): Promise<Question[]> {
|
||||||
return this.findAll({
|
return this.findAll({
|
||||||
where: { author },
|
where: { author },
|
||||||
|
|
|
@ -8,7 +8,8 @@ import {
|
||||||
deleteClassTeacherHandler,
|
deleteClassTeacherHandler,
|
||||||
getAllClassesHandler,
|
getAllClassesHandler,
|
||||||
getClassHandler,
|
getClassHandler,
|
||||||
getClassStudentsHandler, getClassTeachersHandler,
|
getClassStudentsHandler,
|
||||||
|
getClassTeachersHandler,
|
||||||
getTeacherInvitationsHandler,
|
getTeacherInvitationsHandler,
|
||||||
putClassHandler,
|
putClassHandler,
|
||||||
} from '../controllers/classes.js';
|
} from '../controllers/classes.js';
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
import { AssignmentDTO } from '@dwengo-1/common/interfaces/assignment';
|
import { AssignmentDTO } from '@dwengo-1/common/interfaces/assignment';
|
||||||
import { getAssignmentRepository, getClassRepository, getGroupRepository, getQuestionRepository, getSubmissionRepository } from '../data/repositories.js';
|
import {
|
||||||
|
getAssignmentRepository,
|
||||||
|
getClassRepository,
|
||||||
|
getGroupRepository,
|
||||||
|
getQuestionRepository,
|
||||||
|
getSubmissionRepository,
|
||||||
|
} from '../data/repositories.js';
|
||||||
import { Assignment } from '../entities/assignments/assignment.entity.js';
|
import { Assignment } from '../entities/assignments/assignment.entity.js';
|
||||||
import { NotFoundException } from '../exceptions/not-found-exception.js';
|
import { NotFoundException } from '../exceptions/not-found-exception.js';
|
||||||
import { mapToAssignment, mapToAssignmentDTO, mapToAssignmentDTOId } from '../interfaces/assignment.js';
|
import { mapToAssignment, mapToAssignmentDTO, mapToAssignmentDTOId } from '../interfaces/assignment.js';
|
||||||
|
@ -18,7 +24,7 @@ export async function fetchAssignment(classid: string, assignmentNumber: number)
|
||||||
const cls = await classRepository.findById(classid);
|
const cls = await classRepository.findById(classid);
|
||||||
|
|
||||||
if (!cls) {
|
if (!cls) {
|
||||||
throw new NotFoundException('Could not find assignment\'s class');
|
throw new NotFoundException("Could not find assignment's class");
|
||||||
}
|
}
|
||||||
|
|
||||||
const assignmentRepository = getAssignmentRepository();
|
const assignmentRepository = getAssignmentRepository();
|
||||||
|
@ -48,10 +54,10 @@ export async function createAssignment(classid: string, assignmentData: Assignme
|
||||||
const cls = await fetchClass(classid);
|
const cls = await fetchClass(classid);
|
||||||
|
|
||||||
const assignment = mapToAssignment(assignmentData, cls);
|
const assignment = mapToAssignment(assignmentData, cls);
|
||||||
|
|
||||||
const assignmentRepository = getAssignmentRepository();
|
const assignmentRepository = getAssignmentRepository();
|
||||||
const newAssignment = assignmentRepository.create(assignment);
|
const newAssignment = assignmentRepository.create(assignment);
|
||||||
await assignmentRepository.save(newAssignment, {preventOverwrite: true});
|
await assignmentRepository.save(newAssignment, { preventOverwrite: true });
|
||||||
|
|
||||||
return mapToAssignmentDTO(newAssignment);
|
return mapToAssignmentDTO(newAssignment);
|
||||||
}
|
}
|
||||||
|
@ -63,7 +69,7 @@ export async function getAssignment(classid: string, id: number): Promise<Assign
|
||||||
|
|
||||||
export async function putAssignment(classid: string, id: number, assignmentData: Partial<EntityDTO<Assignment>>): Promise<AssignmentDTO> {
|
export async function putAssignment(classid: string, id: number, assignmentData: Partial<EntityDTO<Assignment>>): Promise<AssignmentDTO> {
|
||||||
const assignment = await fetchAssignment(classid, id);
|
const assignment = await fetchAssignment(classid, id);
|
||||||
|
|
||||||
await putObject<Assignment, AssignmentDTO>(assignment, assignmentData, getAssignmentRepository());
|
await putObject<Assignment, AssignmentDTO>(assignment, assignmentData, getAssignmentRepository());
|
||||||
|
|
||||||
return mapToAssignmentDTO(assignment);
|
return mapToAssignmentDTO(assignment);
|
||||||
|
@ -90,9 +96,7 @@ export async function getAssignmentsSubmissions(
|
||||||
const groups = await groupRepository.findAllGroupsForAssignment(assignment);
|
const groups = await groupRepository.findAllGroupsForAssignment(assignment);
|
||||||
|
|
||||||
const submissionRepository = getSubmissionRepository();
|
const submissionRepository = getSubmissionRepository();
|
||||||
const submissions = (await Promise.all(
|
const submissions = (await Promise.all(groups.map(async (group) => submissionRepository.findAllSubmissionsForGroup(group)))).flat();
|
||||||
groups.map(async (group) => submissionRepository.findAllSubmissionsForGroup(group))
|
|
||||||
)).flat();
|
|
||||||
|
|
||||||
if (full) {
|
if (full) {
|
||||||
return submissions.map(mapToSubmissionDTO);
|
return submissions.map(mapToSubmissionDTO);
|
||||||
|
@ -101,11 +105,7 @@ export async function getAssignmentsSubmissions(
|
||||||
return submissions.map(mapToSubmissionDTOId);
|
return submissions.map(mapToSubmissionDTOId);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAssignmentsQuestions(
|
export async function getAssignmentsQuestions(classid: string, assignmentNumber: number, full: boolean): Promise<QuestionDTO[] | QuestionId[]> {
|
||||||
classid: string,
|
|
||||||
assignmentNumber: number,
|
|
||||||
full: boolean
|
|
||||||
): Promise<QuestionDTO[] | QuestionId[]> {
|
|
||||||
const assignment = await fetchAssignment(classid, assignmentNumber);
|
const assignment = await fetchAssignment(classid, assignmentNumber);
|
||||||
|
|
||||||
const questionRepository = getQuestionRepository();
|
const questionRepository = getQuestionRepository();
|
||||||
|
@ -116,4 +116,4 @@ export async function getAssignmentsQuestions(
|
||||||
}
|
}
|
||||||
|
|
||||||
return questions.map(mapToQuestionDTO);
|
return questions.map(mapToQuestionDTO);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,10 @@ import { Class } from '../entities/classes/class.entity.js';
|
||||||
import { ClassDTO } from '@dwengo-1/common/interfaces/class';
|
import { ClassDTO } from '@dwengo-1/common/interfaces/class';
|
||||||
import { TeacherInvitationDTO } from '@dwengo-1/common/interfaces/teacher-invitation';
|
import { TeacherInvitationDTO } from '@dwengo-1/common/interfaces/teacher-invitation';
|
||||||
import { StudentDTO } from '@dwengo-1/common/interfaces/student';
|
import { StudentDTO } from '@dwengo-1/common/interfaces/student';
|
||||||
import {fetchTeacher} from "./teachers";
|
import { fetchTeacher } from './teachers';
|
||||||
import {fetchStudent, getStudent} from "./students";
|
import { fetchStudent, getStudent } from './students';
|
||||||
import {TeacherDTO} from "@dwengo-1/common/interfaces/teacher";
|
import { TeacherDTO } from '@dwengo-1/common/interfaces/teacher';
|
||||||
import {mapToTeacherDTO} from "../interfaces/teacher";
|
import { mapToTeacherDTO } from '../interfaces/teacher';
|
||||||
import { EntityDTO } from '@mikro-orm/core';
|
import { EntityDTO } from '@mikro-orm/core';
|
||||||
import { putObject } from './service-helper.js';
|
import { putObject } from './service-helper.js';
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ export async function fetchClass(classid: string): Promise<Class> {
|
||||||
const cls = await classRepository.findById(classid);
|
const cls = await classRepository.findById(classid);
|
||||||
|
|
||||||
if (!cls) {
|
if (!cls) {
|
||||||
throw new NotFoundException("Class not found");
|
throw new NotFoundException('Class not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
return cls;
|
return cls;
|
||||||
|
@ -43,10 +43,10 @@ export async function getClass(classId: string): Promise<ClassDTO> {
|
||||||
|
|
||||||
export async function createClass(classData: ClassDTO): Promise<ClassDTO> {
|
export async function createClass(classData: ClassDTO): Promise<ClassDTO> {
|
||||||
const teacherUsernames = classData.teachers || [];
|
const teacherUsernames = classData.teachers || [];
|
||||||
const teachers = (await Promise.all(teacherUsernames.map(async (id) => fetchTeacher(id) )));
|
const teachers = await Promise.all(teacherUsernames.map(async (id) => fetchTeacher(id)));
|
||||||
|
|
||||||
const studentUsernames = classData.students || [];
|
const studentUsernames = classData.students || [];
|
||||||
const students = (await Promise.all(studentUsernames.map(async (id) => fetchStudent(id) )));
|
const students = await Promise.all(studentUsernames.map(async (id) => fetchStudent(id)));
|
||||||
|
|
||||||
const classRepository = getClassRepository();
|
const classRepository = getClassRepository();
|
||||||
const newClass = classRepository.create({
|
const newClass = classRepository.create({
|
||||||
|
@ -54,7 +54,7 @@ export async function createClass(classData: ClassDTO): Promise<ClassDTO> {
|
||||||
teachers: teachers,
|
teachers: teachers,
|
||||||
students: students,
|
students: students,
|
||||||
});
|
});
|
||||||
await classRepository.save(newClass, {preventOverwrite: true});
|
await classRepository.save(newClass, { preventOverwrite: true });
|
||||||
|
|
||||||
return mapToClassDTO(newClass);
|
return mapToClassDTO(newClass);
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ export async function getClassStudentsDTO(classId: string): Promise<StudentDTO[]
|
||||||
export async function getClassTeachers(classId: string, full: boolean): Promise<TeacherDTO[] | string[]> {
|
export async function getClassTeachers(classId: string, full: boolean): Promise<TeacherDTO[] | string[]> {
|
||||||
const cls = await fetchClass(classId);
|
const cls = await fetchClass(classId);
|
||||||
|
|
||||||
if (full){
|
if (full) {
|
||||||
return cls.teachers.map(mapToTeacherDTO);
|
return cls.teachers.map(mapToTeacherDTO);
|
||||||
}
|
}
|
||||||
return cls.teachers.map((student) => student.username);
|
return cls.teachers.map((student) => student.username);
|
||||||
|
@ -114,7 +114,7 @@ export async function getClassTeacherInvitations(classId: string, full: boolean)
|
||||||
|
|
||||||
export async function deleteClassStudent(classId: string, username: string): Promise<ClassDTO> {
|
export async function deleteClassStudent(classId: string, username: string): Promise<ClassDTO> {
|
||||||
const cls = await fetchClass(classId);
|
const cls = await fetchClass(classId);
|
||||||
|
|
||||||
const newStudents = { students: cls.students.filter((student) => student.username !== username) };
|
const newStudents = { students: cls.students.filter((student) => student.username !== username) };
|
||||||
await putObject<Class, ClassDTO>(cls, newStudents, getClassRepository());
|
await putObject<Class, ClassDTO>(cls, newStudents, getClassRepository());
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ export async function deleteClassStudent(classId: string, username: string): Pro
|
||||||
|
|
||||||
export async function deleteClassTeacher(classId: string, username: string): Promise<ClassDTO> {
|
export async function deleteClassTeacher(classId: string, username: string): Promise<ClassDTO> {
|
||||||
const cls = await fetchClass(classId);
|
const cls = await fetchClass(classId);
|
||||||
|
|
||||||
const newTeachers = { teachers: cls.teachers.filter((teacher) => teacher.username !== username) };
|
const newTeachers = { teachers: cls.teachers.filter((teacher) => teacher.username !== username) };
|
||||||
await putObject<Class, ClassDTO>(cls, newTeachers, getClassRepository());
|
await putObject<Class, ClassDTO>(cls, newTeachers, getClassRepository());
|
||||||
|
|
||||||
|
@ -134,9 +134,9 @@ export async function addClassStudent(classId: string, username: string): Promis
|
||||||
const cls = await fetchClass(classId);
|
const cls = await fetchClass(classId);
|
||||||
const newStudent = await fetchStudent(username);
|
const newStudent = await fetchStudent(username);
|
||||||
|
|
||||||
const newStudents = { students: [...cls.students, newStudent] }
|
const newStudents = { students: [...cls.students, newStudent] };
|
||||||
await putObject<Class, ClassDTO>(cls, newStudents, getClassRepository());
|
await putObject<Class, ClassDTO>(cls, newStudents, getClassRepository());
|
||||||
|
|
||||||
return mapToClassDTO(cls);
|
return mapToClassDTO(cls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ export async function addClassTeacher(classId: string, username: string): Promis
|
||||||
const newTeacher = await fetchTeacher(username);
|
const newTeacher = await fetchTeacher(username);
|
||||||
|
|
||||||
const newTeachers = { teachers: [...cls.teachers, newTeacher] };
|
const newTeachers = { teachers: [...cls.teachers, newTeacher] };
|
||||||
await putObject<Class, ClassDTO>(cls, newTeachers, getClassRepository());
|
await putObject<Class, ClassDTO>(cls, newTeachers, getClassRepository());
|
||||||
|
|
||||||
return mapToClassDTO(cls);
|
return mapToClassDTO(cls);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ export async function fetchGroup(classId: string, assignmentNumber: number, grou
|
||||||
throw new NotFoundException('Could not find group');
|
throw new NotFoundException('Could not find group');
|
||||||
}
|
}
|
||||||
|
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getGroup(classId: string, assignmentNumber: number, groupNumber: number): Promise<GroupDTO> {
|
export async function getGroup(classId: string, assignmentNumber: number, groupNumber: number): Promise<GroupDTO> {
|
||||||
|
@ -38,7 +38,7 @@ export async function getGroup(classId: string, assignmentNumber: number, groupN
|
||||||
export async function deleteGroup(classId: string, assignmentNumber: number, groupNumber: number): Promise<GroupDTO> {
|
export async function deleteGroup(classId: string, assignmentNumber: number, groupNumber: number): Promise<GroupDTO> {
|
||||||
const group = await fetchGroup(classId, assignmentNumber, groupNumber);
|
const group = await fetchGroup(classId, assignmentNumber, groupNumber);
|
||||||
const assignment = await fetchAssignment(classId, assignmentNumber);
|
const assignment = await fetchAssignment(classId, assignmentNumber);
|
||||||
|
|
||||||
const groupRepository = getGroupRepository();
|
const groupRepository = getGroupRepository();
|
||||||
await groupRepository.deleteByAssignmentAndGroupNumber(assignment, groupNumber);
|
await groupRepository.deleteByAssignmentAndGroupNumber(assignment, groupNumber);
|
||||||
|
|
||||||
|
@ -46,8 +46,8 @@ export async function deleteGroup(classId: string, assignmentNumber: number, gro
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getExistingGroupFromGroupDTO(groupData: GroupDTO) {
|
export async function getExistingGroupFromGroupDTO(groupData: GroupDTO) {
|
||||||
const classId = typeof(groupData.class) === 'string' ? groupData.class : groupData.class.id;
|
const classId = typeof groupData.class === 'string' ? groupData.class : groupData.class.id;
|
||||||
const assignmentNumber = typeof(groupData.assignment) === 'number' ? groupData.assignment : groupData.assignment.id;
|
const assignmentNumber = typeof groupData.assignment === 'number' ? groupData.assignment : groupData.assignment.id;
|
||||||
const groupNumber = groupData.groupNumber;
|
const groupNumber = groupData.groupNumber;
|
||||||
|
|
||||||
return await fetchGroup(classId, assignmentNumber, groupNumber);
|
return await fetchGroup(classId, assignmentNumber, groupNumber);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { EntityDTO, FromEntityType } from "@mikro-orm/core";
|
import { EntityDTO, FromEntityType } from '@mikro-orm/core';
|
||||||
import { DwengoEntityRepository } from "../data/dwengo-entity-repository";
|
import { DwengoEntityRepository } from '../data/dwengo-entity-repository';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility function to perform an PUT on an object.
|
* Utility function to perform an PUT on an object.
|
||||||
|
@ -7,14 +7,14 @@ import { DwengoEntityRepository } from "../data/dwengo-entity-repository";
|
||||||
* @param object The object that needs to be changed
|
* @param object The object that needs to be changed
|
||||||
* @param data The datafields and their values that will be updated
|
* @param data The datafields and their values that will be updated
|
||||||
* @param repo The repository on which this action needs to be performed
|
* @param repo The repository on which this action needs to be performed
|
||||||
*
|
*
|
||||||
* @returns Nothing.
|
* @returns Nothing.
|
||||||
*/
|
*/
|
||||||
export async function putObject<T extends object, DTO>(
|
export async function putObject<T extends object, DTO>(
|
||||||
object: T,
|
object: T,
|
||||||
data: Partial<EntityDTO<FromEntityType<T>>>,
|
data: Partial<EntityDTO<FromEntityType<T>>>,
|
||||||
repo: DwengoEntityRepository<T>
|
repo: DwengoEntityRepository<T>
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
repo.assign(object, data);
|
repo.assign(object, data);
|
||||||
await repo.getEntityManager().flush();
|
await repo.getEntityManager().flush();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,7 @@ import { fetchStudent } from './students.js';
|
||||||
import { fetchGroup, getExistingGroupFromGroupDTO } from './groups.js';
|
import { fetchGroup, getExistingGroupFromGroupDTO } from './groups.js';
|
||||||
import { Submission } from '../entities/assignments/submission.entity.js';
|
import { Submission } from '../entities/assignments/submission.entity.js';
|
||||||
|
|
||||||
export async function fetchSubmission(
|
export async function fetchSubmission(loId: LearningObjectIdentifier, submissionNumber: number): Promise<Submission> {
|
||||||
loId: LearningObjectIdentifier,
|
|
||||||
submissionNumber: number,
|
|
||||||
): Promise<Submission> {
|
|
||||||
const submissionRepository = getSubmissionRepository();
|
const submissionRepository = getSubmissionRepository();
|
||||||
const submission = await submissionRepository.findSubmissionByLearningObjectAndSubmissionNumber(loId, submissionNumber);
|
const submission = await submissionRepository.findSubmissionByLearningObjectAndSubmissionNumber(loId, submissionNumber);
|
||||||
|
|
||||||
|
@ -22,17 +19,12 @@ export async function fetchSubmission(
|
||||||
return submission;
|
return submission;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getSubmission(
|
export async function getSubmission(loId: LearningObjectIdentifier, submissionNumber: number): Promise<SubmissionDTO> {
|
||||||
loId: LearningObjectIdentifier,
|
|
||||||
submissionNumber: number
|
|
||||||
): Promise<SubmissionDTO> {
|
|
||||||
const submission = await fetchSubmission(loId, submissionNumber);
|
const submission = await fetchSubmission(loId, submissionNumber);
|
||||||
return mapToSubmissionDTO(submission);
|
return mapToSubmissionDTO(submission);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAllSubmissions(
|
export async function getAllSubmissions(loId: LearningObjectIdentifier): Promise<SubmissionDTO[]> {
|
||||||
loId: LearningObjectIdentifier,
|
|
||||||
): Promise<SubmissionDTO[]> {
|
|
||||||
const submissionRepository = getSubmissionRepository();
|
const submissionRepository = getSubmissionRepository();
|
||||||
const submissions = await submissionRepository.findByLearningObject(loId);
|
const submissions = await submissionRepository.findByLearningObject(loId);
|
||||||
|
|
||||||
|
@ -52,7 +44,7 @@ export async function createSubmission(submissionDTO: SubmissionDTO): Promise<Su
|
||||||
|
|
||||||
export async function deleteSubmission(loId: LearningObjectIdentifier, submissionNumber: number): Promise<SubmissionDTO> {
|
export async function deleteSubmission(loId: LearningObjectIdentifier, submissionNumber: number): Promise<SubmissionDTO> {
|
||||||
const submission = await fetchSubmission(loId, submissionNumber);
|
const submission = await fetchSubmission(loId, submissionNumber);
|
||||||
|
|
||||||
const submissionRepository = getSubmissionRepository();
|
const submissionRepository = getSubmissionRepository();
|
||||||
await submissionRepository.deleteSubmissionByLearningObjectAndSubmissionNumber(loId, submissionNumber);
|
await submissionRepository.deleteSubmissionByLearningObjectAndSubmissionNumber(loId, submissionNumber);
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ import { Question } from '../entities/questions/question.entity.js';
|
||||||
import { ClassJoinRequestRepository } from '../data/classes/class-join-request-repository.js';
|
import { ClassJoinRequestRepository } from '../data/classes/class-join-request-repository.js';
|
||||||
import { Student } from '../entities/users/student.entity.js';
|
import { Student } from '../entities/users/student.entity.js';
|
||||||
import { NotFoundException } from '../exceptions/not-found-exception.js';
|
import { NotFoundException } from '../exceptions/not-found-exception.js';
|
||||||
import {getClassStudents, getClassStudentsDTO} from './classes.js';
|
import { getClassStudents, getClassStudentsDTO } from './classes.js';
|
||||||
import { TeacherDTO } from '@dwengo-1/common/interfaces/teacher';
|
import { TeacherDTO } from '@dwengo-1/common/interfaces/teacher';
|
||||||
import { ClassDTO } from '@dwengo-1/common/interfaces/class';
|
import { ClassDTO } from '@dwengo-1/common/interfaces/class';
|
||||||
import { StudentDTO } from '@dwengo-1/common/interfaces/student';
|
import { StudentDTO } from '@dwengo-1/common/interfaces/student';
|
||||||
|
@ -102,9 +102,9 @@ export async function getStudentsByTeacher(username: string, full: boolean): Pro
|
||||||
const students: StudentDTO[] = (await Promise.all(classIds.map(async (username) => await getClassStudentsDTO(username)))).flat();
|
const students: StudentDTO[] = (await Promise.all(classIds.map(async (username) => await getClassStudentsDTO(username)))).flat();
|
||||||
|
|
||||||
if (full) {
|
if (full) {
|
||||||
return students
|
return students;
|
||||||
}
|
}
|
||||||
|
|
||||||
return students.map((student) => student.username);
|
return students.map((student) => student.username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ import type { ClassDTO } from "@dwengo-1/common/interfaces/class";
|
||||||
import type { StudentsResponse } from "./students";
|
import type { StudentsResponse } from "./students";
|
||||||
import type { AssignmentsResponse } from "./assignments";
|
import type { AssignmentsResponse } from "./assignments";
|
||||||
import type { TeacherInvitationDTO } from "@dwengo-1/common/interfaces/teacher-invitation";
|
import type { TeacherInvitationDTO } from "@dwengo-1/common/interfaces/teacher-invitation";
|
||||||
import type {TeachersResponse} from "@/controllers/teachers.ts";
|
import type { TeachersResponse } from "@/controllers/teachers.ts";
|
||||||
|
|
||||||
export interface ClassesResponse {
|
export interface ClassesResponse {
|
||||||
classes: ClassDTO[] | string[];
|
classes: ClassDTO[] | string[];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue