merge: merged into feat/error-flow-backend
This commit is contained in:
commit
effaeb0277
249 changed files with 6832 additions and 3679 deletions
|
@ -1,10 +1,13 @@
|
|||
import { AssignmentDTO } from '@dwengo-1/common/interfaces/assignment';
|
||||
import { getAssignmentRepository, getClassRepository, getGroupRepository, getQuestionRepository, getSubmissionRepository } from '../data/repositories.js';
|
||||
import { Assignment } from '../entities/assignments/assignment.entity.js';
|
||||
import { NotFoundException } from '../exceptions/not-found-exception.js';
|
||||
import { AssignmentDTO, mapToAssignment, mapToAssignmentDTO, mapToAssignmentDTOId } from '../interfaces/assignment.js';
|
||||
import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js';
|
||||
import { mapToSubmissionDTO, mapToSubmissionDTOId, SubmissionDTO, SubmissionDTOId } from '../interfaces/submission.js';
|
||||
import { mapToAssignment, mapToAssignmentDTO, mapToAssignmentDTOId } from '../interfaces/assignment.js';
|
||||
import { mapToQuestionDTO } from '../interfaces/question.js';
|
||||
import { mapToSubmissionDTO, mapToSubmissionDTOId } from '../interfaces/submission.js';
|
||||
import { fetchClass } from './classes.js';
|
||||
import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question';
|
||||
import { SubmissionDTO, SubmissionDTOId } from '@dwengo-1/common/interfaces/submission';
|
||||
|
||||
export async function fetchAssignment(classid: string, assignmentNumber: number): Promise<Assignment> {
|
||||
const classRepository = getClassRepository();
|
||||
|
@ -37,35 +40,21 @@ export async function getAllAssignments(classid: string, full: boolean): Promise
|
|||
return assignments.map(mapToAssignmentDTOId);
|
||||
}
|
||||
|
||||
export async function createAssignment(classid: string, assignmentData: AssignmentDTO): Promise<AssignmentDTO | null> {
|
||||
const classRepository = getClassRepository();
|
||||
const cls = await classRepository.findById(classid);
|
||||
|
||||
if (!cls) {
|
||||
return null;
|
||||
}
|
||||
export async function createAssignment(classid: string, assignmentData: AssignmentDTO): Promise<AssignmentDTO> {
|
||||
const cls = await fetchClass(classid);
|
||||
|
||||
const assignment = mapToAssignment(assignmentData, cls);
|
||||
const assignmentRepository = getAssignmentRepository();
|
||||
|
||||
try {
|
||||
const newAssignment = assignmentRepository.create(assignment);
|
||||
await assignmentRepository.save(newAssignment);
|
||||
const newAssignment = assignmentRepository.create(assignment);
|
||||
await assignmentRepository.save(newAssignment, {preventOverwrite: true});
|
||||
|
||||
return mapToAssignmentDTO(newAssignment);
|
||||
|
||||
return mapToAssignmentDTO(newAssignment);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getAssignment(classid: string, id: number): Promise<AssignmentDTO | null> {
|
||||
export async function getAssignment(classid: string, id: number): Promise<AssignmentDTO> {
|
||||
const assignment = await fetchAssignment(classid, id);
|
||||
|
||||
if (!assignment) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return mapToAssignmentDTO(assignment);
|
||||
}
|
||||
|
||||
|
@ -76,15 +65,15 @@ export async function getAssignmentsSubmissions(
|
|||
): Promise<SubmissionDTO[] | SubmissionDTOId[]> {
|
||||
const assignment = await fetchAssignment(classid, assignmentNumber);
|
||||
|
||||
if (!assignment) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const groupRepository = getGroupRepository();
|
||||
const groups = await groupRepository.findAllGroupsForAssignment(assignment);
|
||||
|
||||
if (groups.length === 0){
|
||||
throw new NotFoundException('No groups for assignment found');
|
||||
}
|
||||
|
||||
const submissionRepository = getSubmissionRepository();
|
||||
const submissions = (await Promise.all(groups.map((group) => submissionRepository.findAllSubmissionsForGroup(group)))).flat();
|
||||
const submissions = (await Promise.all(groups.map(async (group) => submissionRepository.findAllSubmissionsForGroup(group)))).flat();
|
||||
|
||||
if (full) {
|
||||
return submissions.map(mapToSubmissionDTO);
|
||||
|
@ -100,10 +89,6 @@ export async function getAssignmentsQuestions(
|
|||
): Promise<QuestionDTO[] | QuestionId[]> {
|
||||
const assignment = await fetchAssignment(classid, assignmentNumber);
|
||||
|
||||
if (!assignment) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const questionRepository = getQuestionRepository();
|
||||
const questions = await questionRepository.findAllByAssignment(assignment);
|
||||
|
||||
|
@ -111,5 +96,5 @@ export async function getAssignmentsQuestions(
|
|||
return questions.map(mapToQuestionDTO);
|
||||
}
|
||||
|
||||
return questions.map(mapToQuestionDTO).map(mapToQuestionId); // mapToQuestionId should be updated
|
||||
return questions.map(mapToQuestionDTO); // mapToQuestionId should be updated
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue