Merge branch 'dev' into feat/class-functionality
This commit is contained in:
		
						commit
						bddcf4e0e8
					
				
					 30 changed files with 282 additions and 1180 deletions
				
			
		|  | @ -69,8 +69,8 @@ export async function getAllGroupsHandler(req: Request, res: Response): Promise< | |||
| export async function createGroupHandler(req: Request, res: Response): Promise<void> { | ||||
|     const classid = req.params.classid; | ||||
|     const assignmentId = Number(req.params.assignmentid); | ||||
| 
 | ||||
|     requireFields({ classid, assignmentId }); | ||||
|     const members = req.body.members; | ||||
|     requireFields({ classid, assignmentId, members }); | ||||
| 
 | ||||
|     if (isNaN(assignmentId)) { | ||||
|         throw new BadRequestException('Assignment id must be a number'); | ||||
|  |  | |||
|  | @ -4,7 +4,7 @@ import { Class } from '../../entities/classes/class.entity.js'; | |||
| 
 | ||||
| export class AssignmentRepository extends DwengoEntityRepository<Assignment> { | ||||
|     public async findByClassAndId(within: Class, id: number): Promise<Assignment | null> { | ||||
|         return this.findOne({ within: within, id: id }); | ||||
|         return this.findOne({ within: within, id: id }, { populate: ['groups', 'groups.members'] }); | ||||
|     } | ||||
|     public async findByClassIdAndAssignmentId(withinClass: string, id: number): Promise<Assignment | null> { | ||||
|         return this.findOne({ within: { classId: withinClass }, id: id }); | ||||
|  | @ -23,7 +23,7 @@ export class AssignmentRepository extends DwengoEntityRepository<Assignment> { | |||
|         }); | ||||
|     } | ||||
|     public async findAllAssignmentsInClass(within: Class): Promise<Assignment[]> { | ||||
|         return this.findAll({ where: { within: within } }); | ||||
|         return this.findAll({ where: { within: within }, populate: ['groups', 'groups.members'] }); | ||||
|     } | ||||
|     public async deleteByClassAndId(within: Class, id: number): Promise<void> { | ||||
|         return this.deleteWhere({ within: within, id: id }); | ||||
|  |  | |||
|  | @ -14,7 +14,7 @@ export class Assignment { | |||
|     }) | ||||
|     within!: Class; | ||||
| 
 | ||||
|     @PrimaryKey({ type: 'number', autoincrement: true }) | ||||
|     @PrimaryKey({ type: 'integer', autoincrement: true }) | ||||
|     id?: number; | ||||
| 
 | ||||
|     @Property({ type: 'string' }) | ||||
|  | @ -35,5 +35,5 @@ export class Assignment { | |||
|         entity: () => Group, | ||||
|         mappedBy: 'assignment', | ||||
|     }) | ||||
|     groups!: Collection<Group>; | ||||
|     groups: Collection<Group> = new Collection<Group>(this); | ||||
| } | ||||
|  |  | |||
|  | @ -7,17 +7,23 @@ import { GroupRepository } from '../../data/assignments/group-repository.js'; | |||
|     repository: () => GroupRepository, | ||||
| }) | ||||
| export class Group { | ||||
|     /* | ||||
|      WARNING: Don't move the definition of groupNumber! If it does not come before the definition of assignment, | ||||
|      creating groups fails because of a MikroORM bug! | ||||
|      */ | ||||
|     @PrimaryKey({ type: 'integer', autoincrement: true }) | ||||
|     groupNumber?: number; | ||||
| 
 | ||||
|     @ManyToOne({ | ||||
|         entity: () => Assignment, | ||||
|         primary: true, | ||||
|     }) | ||||
|     assignment!: Assignment; | ||||
| 
 | ||||
|     @PrimaryKey({ type: 'integer', autoincrement: true }) | ||||
|     groupNumber?: number; | ||||
| 
 | ||||
|     @ManyToMany({ | ||||
|         entity: () => Student, | ||||
|         owner: true, | ||||
|         inversedBy: 'groups', | ||||
|     }) | ||||
|     members!: Collection<Student>; | ||||
|     members: Collection<Student> = new Collection<Student>(this); | ||||
| } | ||||
|  |  | |||
|  | @ -14,9 +14,9 @@ export class Class { | |||
|     @Property({ type: 'string' }) | ||||
|     displayName!: string; | ||||
| 
 | ||||
|     @ManyToMany(() => Teacher) | ||||
|     @ManyToMany({ entity: () => Teacher, owner: true, inversedBy: 'classes' }) | ||||
|     teachers!: Collection<Teacher>; | ||||
| 
 | ||||
|     @ManyToMany(() => Student) | ||||
|     @ManyToMany({ entity: () => Student, owner: true, inversedBy: 'classes' }) | ||||
|     students!: Collection<Student>; | ||||
| } | ||||
|  |  | |||
|  | @ -8,9 +8,9 @@ import { StudentRepository } from '../../data/users/student-repository.js'; | |||
|     repository: () => StudentRepository, | ||||
| }) | ||||
| export class Student extends User { | ||||
|     @ManyToMany(() => Class) | ||||
|     @ManyToMany({ entity: () => Class, mappedBy: 'students' }) | ||||
|     classes!: Collection<Class>; | ||||
| 
 | ||||
|     @ManyToMany(() => Group) | ||||
|     groups!: Collection<Group>; | ||||
|     @ManyToMany({ entity: () => Group, mappedBy: 'members' }) | ||||
|     groups: Collection<Group> = new Collection<Group>(this); | ||||
| } | ||||
|  |  | |||
|  | @ -5,6 +5,6 @@ import { TeacherRepository } from '../../data/users/teacher-repository.js'; | |||
| 
 | ||||
| @Entity({ repository: () => TeacherRepository }) | ||||
| export class Teacher extends User { | ||||
|     @ManyToMany(() => Class) | ||||
|     @ManyToMany({ entity: () => Class, mappedBy: 'teachers' }) | ||||
|     classes!: Collection<Class>; | ||||
| } | ||||
|  |  | |||
							
								
								
									
										12
									
								
								backend/src/exceptions/server-error-exception.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								backend/src/exceptions/server-error-exception.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,12 @@ | |||
| import { ExceptionWithHttpState } from './exception-with-http-state.js'; | ||||
| 
 | ||||
| /** | ||||
|  * Exception for HTTP 500 Internal Server Error | ||||
|  */ | ||||
| export class ServerErrorException extends ExceptionWithHttpState { | ||||
|     status = 500; | ||||
| 
 | ||||
|     constructor(message = 'Internal server error, something went wrong') { | ||||
|         super(500, message); | ||||
|     } | ||||
| } | ||||
|  | @ -1,18 +1,14 @@ | |||
| import { languageMap } from '@dwengo-1/common/util/language'; | ||||
| import { FALLBACK_LANG } from '../config.js'; | ||||
| import { Assignment } from '../entities/assignments/assignment.entity.js'; | ||||
| import { Class } from '../entities/classes/class.entity.js'; | ||||
| import { getLogger } from '../logging/initalize.js'; | ||||
| import { AssignmentDTO } from '@dwengo-1/common/interfaces/assignment'; | ||||
| import { AssignmentDTO, AssignmentDTOId } from '@dwengo-1/common/interfaces/assignment'; | ||||
| import { mapToGroupDTO } from './group.js'; | ||||
| import { getAssignmentRepository } from '../data/repositories.js'; | ||||
| 
 | ||||
| export function mapToAssignmentDTOId(assignment: Assignment): AssignmentDTO { | ||||
| export function mapToAssignmentDTOId(assignment: Assignment): AssignmentDTOId { | ||||
|     return { | ||||
|         id: assignment.id!, | ||||
|         within: assignment.within.classId!, | ||||
|         title: assignment.title, | ||||
|         description: assignment.description, | ||||
|         learningPath: assignment.learningPathHruid, | ||||
|         language: assignment.learningPathLanguage, | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
|  | @ -24,19 +20,17 @@ export function mapToAssignmentDTO(assignment: Assignment): AssignmentDTO { | |||
|         description: assignment.description, | ||||
|         learningPath: assignment.learningPathHruid, | ||||
|         language: assignment.learningPathLanguage, | ||||
|         // Groups: assignment.groups.map(mapToGroupDTO),
 | ||||
|         groups: assignment.groups.map((group) => mapToGroupDTO(group, assignment.within)), | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| export function mapToAssignment(assignmentData: AssignmentDTO, cls: Class): Assignment { | ||||
|     const assignment = new Assignment(); | ||||
|     assignment.title = assignmentData.title; | ||||
|     assignment.description = assignmentData.description; | ||||
|     assignment.learningPathHruid = assignmentData.learningPath; | ||||
|     assignment.learningPathLanguage = languageMap[assignmentData.language] || FALLBACK_LANG; | ||||
|     assignment.within = cls; | ||||
| 
 | ||||
|     getLogger().debug(assignment); | ||||
| 
 | ||||
|     return assignment; | ||||
|     return getAssignmentRepository().create({ | ||||
|         within: cls, | ||||
|         title: assignmentData.title, | ||||
|         description: assignmentData.description, | ||||
|         learningPathHruid: assignmentData.learningPath, | ||||
|         learningPathLanguage: languageMap[assignmentData.language], | ||||
|         groups: [], | ||||
|     }); | ||||
| } | ||||
|  |  | |||
|  | @ -1,14 +1,12 @@ | |||
| import { Group } from '../entities/assignments/group.entity.js'; | ||||
| import { mapToAssignment } from './assignment.js'; | ||||
| import { mapToStudent } from './student.js'; | ||||
| import { mapToAssignmentDTO } from './assignment.js'; | ||||
| import { mapToStudentDTO } from './student.js'; | ||||
| import { GroupDTO } from '@dwengo-1/common/interfaces/group'; | ||||
| import { GroupDTO, GroupDTOId } from '@dwengo-1/common/interfaces/group'; | ||||
| import { getGroupRepository } from '../data/repositories.js'; | ||||
| import { AssignmentDTO } from '@dwengo-1/common/interfaces/assignment'; | ||||
| import { Class } from '../entities/classes/class.entity.js'; | ||||
| import { StudentDTO } from '@dwengo-1/common/interfaces/student'; | ||||
| import { mapToClassDTO } from './class.js'; | ||||
| 
 | ||||
| export function mapToGroup(groupDto: GroupDTO, clazz: Class): Group { | ||||
|     const assignmentDto = groupDto.assignment as AssignmentDTO; | ||||
|  | @ -20,18 +18,18 @@ export function mapToGroup(groupDto: GroupDTO, clazz: Class): Group { | |||
|     }); | ||||
| } | ||||
| 
 | ||||
| export function mapToGroupDTO(group: Group): GroupDTO { | ||||
| export function mapToGroupDTO(group: Group, cls: Class): GroupDTO { | ||||
|     return { | ||||
|         class: mapToClassDTO(group.assignment.within), | ||||
|         assignment: mapToAssignmentDTO(group.assignment), | ||||
|         class: cls.classId!, | ||||
|         assignment: group.assignment.id!, | ||||
|         groupNumber: group.groupNumber!, | ||||
|         members: group.members.map(mapToStudentDTO), | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| export function mapToGroupDTOId(group: Group): GroupDTO { | ||||
| export function mapToGroupDTOId(group: Group, cls: Class): GroupDTOId { | ||||
|     return { | ||||
|         class: group.assignment.within.classId!, | ||||
|         class: cls.classId!, | ||||
|         assignment: group.assignment.id!, | ||||
|         groupNumber: group.groupNumber!, | ||||
|     }; | ||||
|  |  | |||
|  | @ -31,7 +31,7 @@ export function mapToQuestionDTO(question: Question): QuestionDTO { | |||
|         learningObjectIdentifier, | ||||
|         sequenceNumber: question.sequenceNumber!, | ||||
|         author: mapToStudentDTO(question.author), | ||||
|         inGroup: mapToGroupDTOId(question.inGroup), | ||||
|         inGroup: mapToGroupDTOId(question.inGroup, question.inGroup.assignment?.within), | ||||
|         timestamp: question.timestamp.toISOString(), | ||||
|         content: question.content, | ||||
|     }; | ||||
|  |  | |||
|  | @ -16,7 +16,7 @@ export function mapToSubmissionDTO(submission: Submission): SubmissionDTO { | |||
|         submissionNumber: submission.submissionNumber, | ||||
|         submitter: mapToStudentDTO(submission.submitter), | ||||
|         time: submission.submissionTime, | ||||
|         group: mapToGroupDTOId(submission.onBehalfOf), | ||||
|         group: submission.onBehalfOf ? mapToGroupDTOId(submission.onBehalfOf, submission.onBehalfOf.assignment.within) : undefined, | ||||
|         content: submission.content, | ||||
|     }; | ||||
| } | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| import { AssignmentDTO } from '@dwengo-1/common/interfaces/assignment'; | ||||
| import { AssignmentDTO, AssignmentDTOId } from '@dwengo-1/common/interfaces/assignment'; | ||||
| import { | ||||
|     getAssignmentRepository, | ||||
|     getClassRepository, | ||||
|  | @ -16,6 +16,8 @@ import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | |||
| import { SubmissionDTO, SubmissionDTOId } from '@dwengo-1/common/interfaces/submission'; | ||||
| import { EntityDTO } from '@mikro-orm/core'; | ||||
| import { putObject } from './service-helper.js'; | ||||
| import { fetchStudents } from './students.js'; | ||||
| import { ServerErrorException } from '../exceptions/server-error-exception.js'; | ||||
| 
 | ||||
| export async function fetchAssignment(classid: string, assignmentNumber: number): Promise<Assignment> { | ||||
|     const classRepository = getClassRepository(); | ||||
|  | @ -35,7 +37,7 @@ export async function fetchAssignment(classid: string, assignmentNumber: number) | |||
|     return assignment; | ||||
| } | ||||
| 
 | ||||
| export async function getAllAssignments(classid: string, full: boolean): Promise<AssignmentDTO[]> { | ||||
| export async function getAllAssignments(classid: string, full: boolean): Promise<AssignmentDTO[] | AssignmentDTOId[]> { | ||||
|     const cls = await fetchClass(classid); | ||||
| 
 | ||||
|     const assignmentRepository = getAssignmentRepository(); | ||||
|  | @ -51,13 +53,39 @@ export async function getAllAssignments(classid: string, full: boolean): Promise | |||
| export async function createAssignment(classid: string, assignmentData: AssignmentDTO): Promise<AssignmentDTO> { | ||||
|     const cls = await fetchClass(classid); | ||||
| 
 | ||||
|     const assignment = mapToAssignment(assignmentData, cls); | ||||
| 
 | ||||
|     const assignmentRepository = getAssignmentRepository(); | ||||
|     const newAssignment = assignmentRepository.create(assignment); | ||||
|     await assignmentRepository.save(newAssignment, { preventOverwrite: true }); | ||||
|     const assignment = mapToAssignment(assignmentData, cls); | ||||
|     await assignmentRepository.save(assignment); | ||||
| 
 | ||||
|     return mapToAssignmentDTO(newAssignment); | ||||
|     if (assignmentData.groups) { | ||||
|         /* | ||||
|         For some reason when trying to add groups, it does not work when using the original assignment variable.  | ||||
|         The assignment needs to be refetched in order for it to work. | ||||
|         */ | ||||
| 
 | ||||
|         const assignmentCopy = await assignmentRepository.findByClassAndId(cls, assignment.id!); | ||||
| 
 | ||||
|         if (assignmentCopy === null) { | ||||
|             throw new ServerErrorException('Something has gone horribly wrong. Could not find newly added assignment which is needed to add groups.'); | ||||
|         } | ||||
| 
 | ||||
|         const groupRepository = getGroupRepository(); | ||||
| 
 | ||||
|         (assignmentData.groups as string[][]).forEach(async (memberUsernames) => { | ||||
|             const members = await fetchStudents(memberUsernames); | ||||
| 
 | ||||
|             const newGroup = groupRepository.create({ | ||||
|                 assignment: assignmentCopy, | ||||
|                 members: members, | ||||
|             }); | ||||
|             await groupRepository.save(newGroup); | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     /* Need to refetch the assignment here again such that the groups are added. */ | ||||
|     const assignmentWithGroups = await fetchAssignment(classid, assignment.id!); | ||||
| 
 | ||||
|     return mapToAssignmentDTO(assignmentWithGroups); | ||||
| } | ||||
| 
 | ||||
| export async function getAssignment(classid: string, id: number): Promise<AssignmentDTO> { | ||||
|  |  | |||
|  | @ -1,13 +1,14 @@ | |||
| import { EntityDTO } from '@mikro-orm/core'; | ||||
| import { getGroupRepository, getStudentRepository, getSubmissionRepository } from '../data/repositories.js'; | ||||
| import { getGroupRepository, getSubmissionRepository } from '../data/repositories.js'; | ||||
| import { Group } from '../entities/assignments/group.entity.js'; | ||||
| import { mapToGroupDTO, mapToShallowGroupDTO } from '../interfaces/group.js'; | ||||
| import { mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js'; | ||||
| import { mapToSubmissionDTO, mapToSubmissionDTOId } from '../interfaces/submission.js'; | ||||
| import { GroupDTO } from '@dwengo-1/common/interfaces/group'; | ||||
| import { GroupDTO, GroupDTOId } from '@dwengo-1/common/interfaces/group'; | ||||
| import { SubmissionDTO, SubmissionDTOId } from '@dwengo-1/common/interfaces/submission'; | ||||
| import { fetchAssignment } from './assignments.js'; | ||||
| import { NotFoundException } from '../exceptions/not-found-exception.js'; | ||||
| import { putObject } from './service-helper.js'; | ||||
| import { fetchStudents } from './students.js'; | ||||
| 
 | ||||
| export async function fetchGroup(classId: string, assignmentNumber: number, groupNumber: number): Promise<Group> { | ||||
|     const assignment = await fetchAssignment(classId, assignmentNumber); | ||||
|  | @ -24,7 +25,7 @@ export async function fetchGroup(classId: string, assignmentNumber: number, grou | |||
| 
 | ||||
| export async function getGroup(classId: string, assignmentNumber: number, groupNumber: number): Promise<GroupDTO> { | ||||
|     const group = await fetchGroup(classId, assignmentNumber, groupNumber); | ||||
|     return mapToGroupDTO(group); | ||||
|     return mapToGroupDTO(group, group.assignment.within); | ||||
| } | ||||
| 
 | ||||
| export async function putGroup( | ||||
|  | @ -37,7 +38,7 @@ export async function putGroup( | |||
| 
 | ||||
|     await putObject<Group>(group, groupData, getGroupRepository()); | ||||
| 
 | ||||
|     return mapToGroupDTO(group); | ||||
|     return mapToGroupDTO(group, group.assignment.within); | ||||
| } | ||||
| 
 | ||||
| export async function deleteGroup(classId: string, assignmentNumber: number, groupNumber: number): Promise<GroupDTO> { | ||||
|  | @ -47,7 +48,7 @@ export async function deleteGroup(classId: string, assignmentNumber: number, gro | |||
|     const groupRepository = getGroupRepository(); | ||||
|     await groupRepository.deleteByAssignmentAndGroupNumber(assignment, groupNumber); | ||||
| 
 | ||||
|     return mapToGroupDTO(group); | ||||
|     return mapToGroupDTO(group, assignment.within); | ||||
| } | ||||
| 
 | ||||
| export async function getExistingGroupFromGroupDTO(groupData: GroupDTO): Promise<Group> { | ||||
|  | @ -59,12 +60,8 @@ export async function getExistingGroupFromGroupDTO(groupData: GroupDTO): Promise | |||
| } | ||||
| 
 | ||||
| export async function createGroup(groupData: GroupDTO, classid: string, assignmentNumber: number): Promise<GroupDTO> { | ||||
|     const studentRepository = getStudentRepository(); | ||||
| 
 | ||||
|     const memberUsernames = (groupData.members as string[]) || []; | ||||
|     const members = (await Promise.all([...memberUsernames].map(async (id) => studentRepository.findByUsername(id)))).filter( | ||||
|         (student) => student !== null | ||||
|     ); | ||||
|     const members = await fetchStudents(memberUsernames); | ||||
| 
 | ||||
|     const assignment = await fetchAssignment(classid, assignmentNumber); | ||||
| 
 | ||||
|  | @ -73,22 +70,23 @@ export async function createGroup(groupData: GroupDTO, classid: string, assignme | |||
|         assignment: assignment, | ||||
|         members: members, | ||||
|     }); | ||||
| 
 | ||||
|     await groupRepository.save(newGroup); | ||||
| 
 | ||||
|     return mapToGroupDTO(newGroup); | ||||
|     return mapToGroupDTO(newGroup, newGroup.assignment.within); | ||||
| } | ||||
| 
 | ||||
| export async function getAllGroups(classId: string, assignmentNumber: number, full: boolean): Promise<GroupDTO[]> { | ||||
| export async function getAllGroups(classId: string, assignmentNumber: number, full: boolean): Promise<GroupDTO[] | GroupDTOId[]> { | ||||
|     const assignment = await fetchAssignment(classId, assignmentNumber); | ||||
| 
 | ||||
|     const groupRepository = getGroupRepository(); | ||||
|     const groups = await groupRepository.findAllGroupsForAssignment(assignment); | ||||
| 
 | ||||
|     if (full) { | ||||
|         return groups.map(mapToGroupDTO); | ||||
|         return groups.map((group) => mapToGroupDTO(group, assignment.within)); | ||||
|     } | ||||
| 
 | ||||
|     return groups.map(mapToShallowGroupDTO); | ||||
|     return groups.map((group) => mapToGroupDTOId(group, assignment.within)); | ||||
| } | ||||
| 
 | ||||
| export async function getGroupSubmissions( | ||||
|  |  | |||
|  | @ -7,7 +7,7 @@ import { | |||
|     getSubmissionRepository, | ||||
| } from '../data/repositories.js'; | ||||
| import { mapToClassDTO } from '../interfaces/class.js'; | ||||
| import { mapToGroupDTO, mapToShallowGroupDTO } from '../interfaces/group.js'; | ||||
| import { mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js'; | ||||
| import { mapToStudent, mapToStudentDTO } from '../interfaces/student.js'; | ||||
| import { mapToSubmissionDTO, mapToSubmissionDTOId } from '../interfaces/submission.js'; | ||||
| import { getAllAssignments } from './assignments.js'; | ||||
|  | @ -18,8 +18,8 @@ import { NotFoundException } from '../exceptions/not-found-exception.js'; | |||
| import { fetchClass } from './classes.js'; | ||||
| import { StudentDTO } from '@dwengo-1/common/interfaces/student'; | ||||
| import { ClassDTO } from '@dwengo-1/common/interfaces/class'; | ||||
| import { AssignmentDTO } from '@dwengo-1/common/interfaces/assignment'; | ||||
| import { GroupDTO } from '@dwengo-1/common/interfaces/group'; | ||||
| import { AssignmentDTO, AssignmentDTOId } from '@dwengo-1/common/interfaces/assignment'; | ||||
| import { GroupDTO, GroupDTOId } from '@dwengo-1/common/interfaces/group'; | ||||
| import { SubmissionDTO, SubmissionDTOId } from '@dwengo-1/common/interfaces/submission'; | ||||
| import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | ||||
| import { ClassJoinRequestDTO } from '@dwengo-1/common/interfaces/class-join-request'; | ||||
|  | @ -48,6 +48,11 @@ export async function fetchStudent(username: string): Promise<Student> { | |||
|     return user; | ||||
| } | ||||
| 
 | ||||
| export async function fetchStudents(usernames: string[]): Promise<Student[]> { | ||||
|     const members = await Promise.all(usernames.map(async (username) => await fetchStudent(username))); | ||||
|     return members; | ||||
| } | ||||
| 
 | ||||
| export async function getStudent(username: string): Promise<StudentDTO> { | ||||
|     const user = await fetchStudent(username); | ||||
|     return mapToStudentDTO(user); | ||||
|  | @ -83,7 +88,7 @@ export async function getStudentClasses(username: string, full: boolean): Promis | |||
|     return classes.map((cls) => cls.classId!); | ||||
| } | ||||
| 
 | ||||
| export async function getStudentAssignments(username: string, full: boolean): Promise<AssignmentDTO[]> { | ||||
| export async function getStudentAssignments(username: string, full: boolean): Promise<AssignmentDTO[] | AssignmentDTOId[]> { | ||||
|     const student = await fetchStudent(username); | ||||
| 
 | ||||
|     const classRepository = getClassRepository(); | ||||
|  | @ -92,17 +97,17 @@ export async function getStudentAssignments(username: string, full: boolean): Pr | |||
|     return (await Promise.all(classes.map(async (cls) => await getAllAssignments(cls.classId!, full)))).flat(); | ||||
| } | ||||
| 
 | ||||
| export async function getStudentGroups(username: string, full: boolean): Promise<GroupDTO[]> { | ||||
| export async function getStudentGroups(username: string, full: boolean): Promise<GroupDTO[] | GroupDTOId[]> { | ||||
|     const student = await fetchStudent(username); | ||||
| 
 | ||||
|     const groupRepository = getGroupRepository(); | ||||
|     const groups = await groupRepository.findAllGroupsWithStudent(student); | ||||
| 
 | ||||
|     if (full) { | ||||
|         return groups.map(mapToGroupDTO); | ||||
|         return groups.map((group) => mapToGroupDTO(group, group.assignment.within)); | ||||
|     } | ||||
| 
 | ||||
|     return groups.map(mapToShallowGroupDTO); | ||||
|     return groups.map((group) => mapToGroupDTOId(group, group.assignment.within)); | ||||
| } | ||||
| 
 | ||||
| export async function getStudentSubmissions(username: string, full: boolean): Promise<SubmissionDTO[] | SubmissionDTOId[]> { | ||||
|  |  | |||
|  | @ -33,7 +33,7 @@ export async function getAllSubmissions(loId: LearningObjectIdentifier): Promise | |||
| 
 | ||||
| export async function createSubmission(submissionDTO: SubmissionDTO): Promise<SubmissionDTO> { | ||||
|     const submitter = await fetchStudent(submissionDTO.submitter.username); | ||||
|     const group = await getExistingGroupFromGroupDTO(submissionDTO.group); | ||||
|     const group = await getExistingGroupFromGroupDTO(submissionDTO.group!); | ||||
| 
 | ||||
|     const submissionRepository = getSubmissionRepository(); | ||||
|     const submission = mapToSubmission(submissionDTO, submitter, group); | ||||
|  |  | |||
		Reference in a new issue
	
	 laurejablonski
						laurejablonski