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,5 +1,5 @@
|
||||||
import { EnvVars, getEnvVar } from './util/envvars.js';
|
import { EnvVars, getEnvVar } from './util/envvars.js';
|
||||||
import {Language} from "./entities/content/language.js";
|
import { Language } from './entities/content/language.js';
|
||||||
|
|
||||||
// API
|
// API
|
||||||
export const DWENGO_API_BASE = getEnvVar(EnvVars.LearningContentRepoApiBaseUrl);
|
export const DWENGO_API_BASE = getEnvVar(EnvVars.LearningContentRepoApiBaseUrl);
|
||||||
|
|
|
@ -9,10 +9,7 @@ interface AssignmentParams {
|
||||||
id: string;
|
id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAllAssignmentsHandler(
|
export async function getAllAssignmentsHandler(req: Request<AssignmentParams>, res: Response): Promise<void> {
|
||||||
req: Request<AssignmentParams>,
|
|
||||||
res: Response
|
|
||||||
): Promise<void> {
|
|
||||||
const classid = req.params.classid;
|
const classid = req.params.classid;
|
||||||
const full = req.query.full === 'true';
|
const full = req.query.full === 'true';
|
||||||
|
|
||||||
|
@ -23,18 +20,11 @@ export async function getAllAssignmentsHandler(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createAssignmentHandler(
|
export async function createAssignmentHandler(req: Request<AssignmentParams>, res: Response): Promise<void> {
|
||||||
req: Request<AssignmentParams>,
|
|
||||||
res: Response,
|
|
||||||
): Promise<void> {
|
|
||||||
const classid = req.params.classid;
|
const classid = req.params.classid;
|
||||||
const assignmentData = req.body as AssignmentDTO;
|
const assignmentData = req.body as AssignmentDTO;
|
||||||
|
|
||||||
if (!assignmentData.description
|
if (!assignmentData.description || !assignmentData.language || !assignmentData.learningPath || !assignmentData.title) {
|
||||||
|| !assignmentData.language
|
|
||||||
|| !assignmentData.learningPath
|
|
||||||
|| !assignmentData.title
|
|
||||||
) {
|
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
error: 'Missing one or more required fields: title, description, learningPath, title',
|
error: 'Missing one or more required fields: title, description, learningPath, title',
|
||||||
});
|
});
|
||||||
|
@ -44,17 +34,14 @@ export async function createAssignmentHandler(
|
||||||
const assignment = createAssignment(classid, assignmentData);
|
const assignment = createAssignment(classid, assignmentData);
|
||||||
|
|
||||||
if (!assignment) {
|
if (!assignment) {
|
||||||
res.status(500).json({ error: "Could not create assignment "});
|
res.status(500).json({ error: 'Could not create assignment ' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(201).json({ assignment: assignment });
|
res.status(201).json({ assignment: assignment });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAssignmentHandler(
|
export async function getAssignmentHandler(req: Request<AssignmentParams>, res: Response): Promise<void> {
|
||||||
req: Request<AssignmentParams>,
|
|
||||||
res: Response
|
|
||||||
): Promise<void> {
|
|
||||||
const id = +req.params.id;
|
const id = +req.params.id;
|
||||||
const classid = req.params.classid;
|
const classid = req.params.classid;
|
||||||
|
|
||||||
|
@ -73,10 +60,7 @@ export async function getAssignmentHandler(
|
||||||
res.json(assignment);
|
res.json(assignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAssignmentsSubmissionsHandler(
|
export async function getAssignmentsSubmissionsHandler(req: Request<AssignmentParams>, res: Response): Promise<void> {
|
||||||
req: Request<AssignmentParams>,
|
|
||||||
res: Response,
|
|
||||||
): Promise<void> {
|
|
||||||
const classid = req.params.classid;
|
const classid = req.params.classid;
|
||||||
const assignmentNumber = +req.params.id;
|
const assignmentNumber = +req.params.id;
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,9 @@
|
||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
import {
|
import { createClass, getAllClasses, getClass, getClassStudents, getClassStudentsIds, getClassTeacherInvitations } from '../services/class.js';
|
||||||
createClass,
|
|
||||||
getAllClasses,
|
|
||||||
getClass,
|
|
||||||
getClassStudents,
|
|
||||||
getClassStudentsIds,
|
|
||||||
getClassTeacherInvitations,
|
|
||||||
} from '../services/class.js';
|
|
||||||
import { ClassDTO, mapToClass } from '../interfaces/class.js';
|
import { ClassDTO, mapToClass } from '../interfaces/class.js';
|
||||||
import { getClassRepository, getStudentRepository, getTeacherRepository } from '../data/repositories.js';
|
import { getClassRepository, getStudentRepository, getTeacherRepository } from '../data/repositories.js';
|
||||||
|
|
||||||
export async function getAllClassesHandler(
|
export async function getAllClassesHandler(req: Request, res: Response): Promise<void> {
|
||||||
req: Request,
|
|
||||||
res: Response
|
|
||||||
): Promise<void> {
|
|
||||||
const full = req.query.full === 'true';
|
const full = req.query.full === 'true';
|
||||||
const classes = await getAllClasses(full);
|
const classes = await getAllClasses(full);
|
||||||
|
|
||||||
|
@ -22,10 +12,7 @@ export async function getAllClassesHandler(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createClassHandler(
|
export async function createClassHandler(req: Request, res: Response): Promise<void> {
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
): Promise<void> {
|
|
||||||
const classData = req.body as ClassDTO;
|
const classData = req.body as ClassDTO;
|
||||||
|
|
||||||
if (!classData.displayName) {
|
if (!classData.displayName) {
|
||||||
|
@ -38,17 +25,14 @@ export async function createClassHandler(
|
||||||
const cls = await createClass(classData);
|
const cls = await createClass(classData);
|
||||||
|
|
||||||
if (!cls) {
|
if (!cls) {
|
||||||
res.status(500).json({ error: "Something went wrong while creating class" });
|
res.status(500).json({ error: 'Something went wrong while creating class' });
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(201).json({ class: cls });
|
res.status(201).json({ class: cls });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getClassHandler(
|
export async function getClassHandler(req: Request, res: Response): Promise<void> {
|
||||||
req: Request,
|
|
||||||
res: Response
|
|
||||||
): Promise<void> {
|
|
||||||
try {
|
try {
|
||||||
const classId = req.params.id;
|
const classId = req.params.id;
|
||||||
const cls = await getClass(classId);
|
const cls = await getClass(classId);
|
||||||
|
@ -71,26 +55,18 @@ export async function getClassHandler(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getClassStudentsHandler(
|
export async function getClassStudentsHandler(req: Request, res: Response): Promise<void> {
|
||||||
req: Request,
|
|
||||||
res: Response
|
|
||||||
): Promise<void> {
|
|
||||||
const classId = req.params.id;
|
const classId = req.params.id;
|
||||||
const full = req.query.full === 'true';
|
const full = req.query.full === 'true';
|
||||||
|
|
||||||
const students = full
|
const students = full ? await getClassStudents(classId) : await getClassStudentsIds(classId);
|
||||||
? await getClassStudents(classId)
|
|
||||||
: await getClassStudentsIds(classId);
|
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
students: students,
|
students: students,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getTeacherInvitationsHandler(
|
export async function getTeacherInvitationsHandler(req: Request, res: Response): Promise<void> {
|
||||||
req: Request,
|
|
||||||
res: Response
|
|
||||||
): Promise<void> {
|
|
||||||
const classId = req.params.id;
|
const classId = req.params.id;
|
||||||
const full = req.query.full === 'true'; // TODO: not implemented yet
|
const full = req.query.full === 'true'; // TODO: not implemented yet
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,7 @@ interface GroupParams {
|
||||||
groupid?: string;
|
groupid?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getGroupHandler(
|
export async function getGroupHandler(req: Request<GroupParams>, res: Response): Promise<void> {
|
||||||
req: Request<GroupParams>,
|
|
||||||
res: Response
|
|
||||||
): Promise<void> {
|
|
||||||
const classId = req.params.classid;
|
const classId = req.params.classid;
|
||||||
const full = req.query.full === 'true';
|
const full = req.query.full === 'true';
|
||||||
const assignmentId = +req.params.assignmentid;
|
const assignmentId = +req.params.assignmentid;
|
||||||
|
@ -34,10 +31,7 @@ export async function getGroupHandler(
|
||||||
res.json(group);
|
res.json(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAllGroupsHandler(
|
export async function getAllGroupsHandler(req: Request, res: Response): Promise<void> {
|
||||||
req: Request,
|
|
||||||
res: Response
|
|
||||||
): Promise<void> {
|
|
||||||
const classId = req.params.classid;
|
const classId = req.params.classid;
|
||||||
const full = req.query.full === 'true';
|
const full = req.query.full === 'true';
|
||||||
|
|
||||||
|
@ -55,10 +49,7 @@ export async function getAllGroupsHandler(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createGroupHandler(
|
export async function createGroupHandler(req: Request, res: Response): Promise<void> {
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
): Promise<void> {
|
|
||||||
const classid = req.params.classid;
|
const classid = req.params.classid;
|
||||||
const assignmentId = +req.params.assignmentid;
|
const assignmentId = +req.params.assignmentid;
|
||||||
|
|
||||||
|
@ -71,17 +62,14 @@ export async function createGroupHandler(
|
||||||
const group = createGroup(groupData, classid, assignmentId);
|
const group = createGroup(groupData, classid, assignmentId);
|
||||||
|
|
||||||
if (!group) {
|
if (!group) {
|
||||||
res.status(500).json({ error: "Something went wrong while creating group" });
|
res.status(500).json({ error: 'Something went wrong while creating group' });
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(201).json({ group: group });
|
res.status(201).json({ group: group });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getGroupSubmissionsHandler(
|
export async function getGroupSubmissionsHandler(req: Request, res: Response): Promise<void> {
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
): Promise<void> {
|
|
||||||
const classId = req.params.classid;
|
const classId = req.params.classid;
|
||||||
// Const full = req.query.full === 'true';
|
// Const full = req.query.full === 'true';
|
||||||
|
|
||||||
|
@ -104,4 +92,4 @@ export async function getGroupSubmissionsHandler(
|
||||||
res.json({
|
res.json({
|
||||||
submissions: submissions,
|
submissions: submissions,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,121 +1,119 @@
|
||||||
import {Request, Response} from "express";
|
import { Request, Response } from 'express';
|
||||||
import {
|
import { createQuestion, deleteQuestion, getAllQuestions, getAnswersByQuestion, getQuestion } from '../services/questions.js';
|
||||||
createQuestion,
|
import { QuestionDTO, QuestionId } from '../interfaces/question.js';
|
||||||
deleteQuestion,
|
import { FALLBACK_LANG, FALLBACK_SEQ_NUM } from '../config.js';
|
||||||
getAllQuestions,
|
import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js';
|
||||||
getAnswersByQuestion,
|
import { Language } from '../entities/content/language.js';
|
||||||
getQuestion
|
|
||||||
} from "../services/questions.js";
|
|
||||||
import {QuestionDTO, QuestionId} from "../interfaces/question.js";
|
|
||||||
import {FALLBACK_LANG, FALLBACK_SEQ_NUM} from "../config.js";
|
|
||||||
import {LearningObjectIdentifier} from "../entities/content/learning-object-identifier.js";
|
|
||||||
import {Language} from "../entities/content/language.js";
|
|
||||||
|
|
||||||
function getObjectId(req: Request, res: Response): LearningObjectIdentifier | null {
|
function getObjectId(req: Request, res: Response): LearningObjectIdentifier | null {
|
||||||
const { hruid, version } = req.params
|
const { hruid, version } = req.params;
|
||||||
const lang = req.query.lang
|
const lang = req.query.lang;
|
||||||
|
|
||||||
if (!hruid || !version ) {
|
if (!hruid || !version) {
|
||||||
res.status(400).json({ error: "Missing required parameters." });
|
res.status(400).json({ error: 'Missing required parameters.' });
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
hruid,
|
hruid,
|
||||||
language: lang as Language || FALLBACK_LANG,
|
language: (lang as Language) || FALLBACK_LANG,
|
||||||
version: +version
|
version: +version,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getQuestionId(req: Request, res: Response): QuestionId | null {
|
function getQuestionId(req: Request, res: Response): QuestionId | null {
|
||||||
const seq = req.params.seq
|
const seq = req.params.seq;
|
||||||
const learningObjectIdentifier = getObjectId(req,res);
|
const learningObjectIdentifier = getObjectId(req, res);
|
||||||
|
|
||||||
if (!learningObjectIdentifier)
|
if (!learningObjectIdentifier) {
|
||||||
{return null}
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
learningObjectIdentifier,
|
learningObjectIdentifier,
|
||||||
sequenceNumber: seq ? Number(seq) : FALLBACK_SEQ_NUM
|
sequenceNumber: seq ? Number(seq) : FALLBACK_SEQ_NUM,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAllQuestionsHandler(
|
export async function getAllQuestionsHandler(req: Request, res: Response): Promise<void> {
|
||||||
req: Request,
|
|
||||||
res: Response
|
|
||||||
): Promise<void> {
|
|
||||||
const objectId = getObjectId(req, res);
|
const objectId = getObjectId(req, res);
|
||||||
const full = req.query.full === 'true';
|
const full = req.query.full === 'true';
|
||||||
|
|
||||||
if (!objectId)
|
if (!objectId) {
|
||||||
{return}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const questions = await getAllQuestions(objectId, full);
|
const questions = await getAllQuestions(objectId, full);
|
||||||
|
|
||||||
if (!questions)
|
if (!questions) {
|
||||||
{res.status(404).json({ error: `Questions not found.` });}
|
res.status(404).json({ error: `Questions not found.` });
|
||||||
else
|
} else {
|
||||||
{res.json(questions);}
|
res.json(questions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getQuestionHandler(req: Request, res: Response): Promise<void> {
|
export async function getQuestionHandler(req: Request, res: Response): Promise<void> {
|
||||||
const questionId = getQuestionId(req, res);
|
const questionId = getQuestionId(req, res);
|
||||||
|
|
||||||
if (!questionId)
|
if (!questionId) {
|
||||||
{return}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const question = await getQuestion(questionId);
|
const question = await getQuestion(questionId);
|
||||||
|
|
||||||
if (!question)
|
if (!question) {
|
||||||
{res.status(404).json({ error: `Question not found.` });}
|
res.status(404).json({ error: `Question not found.` });
|
||||||
else
|
} else {
|
||||||
{res.json(question)}
|
res.json(question);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getQuestionAnswersHandler(req: Request, res: Response): Promise<void> {
|
export async function getQuestionAnswersHandler(req: Request, res: Response): Promise<void> {
|
||||||
const questionId = getQuestionId(req, res);
|
const questionId = getQuestionId(req, res);
|
||||||
const full = req.query.full === 'true';
|
const full = req.query.full === 'true';
|
||||||
|
|
||||||
if (!questionId)
|
if (!questionId) {
|
||||||
{return}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const answers = getAnswersByQuestion(questionId, full);
|
const answers = getAnswersByQuestion(questionId, full);
|
||||||
|
|
||||||
if (!answers)
|
if (!answers) {
|
||||||
{res.status(404).json({ error: `Questions not found.` });}
|
res.status(404).json({ error: `Questions not found.` });
|
||||||
else
|
} else {
|
||||||
{res.json(answers)}
|
res.json(answers);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createQuestionHandler(req: Request, res: Response): Promise<void> {
|
export async function createQuestionHandler(req: Request, res: Response): Promise<void> {
|
||||||
const questionDTO = req.body as QuestionDTO;
|
const questionDTO = req.body as QuestionDTO;
|
||||||
|
|
||||||
if (!questionDTO.learningObjectIdentifier || !questionDTO.author || !questionDTO.content) {
|
if (!questionDTO.learningObjectIdentifier || !questionDTO.author || !questionDTO.content) {
|
||||||
res.status(400).json({error: 'Missing required fields: identifier and content'});
|
res.status(400).json({ error: 'Missing required fields: identifier and content' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const question = await createQuestion(questionDTO);
|
const question = await createQuestion(questionDTO);
|
||||||
|
|
||||||
if (!question)
|
if (!question) {
|
||||||
{res.status(400).json({error: 'Could not add question'});}
|
res.status(400).json({ error: 'Could not add question' });
|
||||||
else
|
} else {
|
||||||
{res.json(question)}
|
res.json(question);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteQuestionHandler(req: Request, res: Response): Promise<void> {
|
export async function deleteQuestionHandler(req: Request, res: Response): Promise<void> {
|
||||||
const questionId = getQuestionId(req, res);
|
const questionId = getQuestionId(req, res);
|
||||||
|
|
||||||
if (!questionId)
|
if (!questionId) {
|
||||||
{return}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const question = await deleteQuestion(questionId);
|
const question = await deleteQuestion(questionId);
|
||||||
|
|
||||||
if (!question)
|
if (!question) {
|
||||||
{res.status(400).json({error: 'Could not find nor delete question'});}
|
res.status(400).json({ error: 'Could not find nor delete question' });
|
||||||
else
|
} else {
|
||||||
{res.json(question)}
|
res.json(question);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,7 @@ import {
|
||||||
} from '../services/students.js';
|
} from '../services/students.js';
|
||||||
import { ClassDTO } from '../interfaces/class.js';
|
import { ClassDTO } from '../interfaces/class.js';
|
||||||
import { getAllAssignments } from '../services/assignments.js';
|
import { getAllAssignments } from '../services/assignments.js';
|
||||||
import {
|
import { getUserHandler } from './users.js';
|
||||||
getUserHandler,
|
|
||||||
} from './users.js';
|
|
||||||
import { Student } from '../entities/users/student.entity.js';
|
import { Student } from '../entities/users/student.entity.js';
|
||||||
import { StudentDTO } from '../interfaces/student.js';
|
import { StudentDTO } from '../interfaces/student.js';
|
||||||
import { getStudentRepository } from '../data/repositories.js';
|
import { getStudentRepository } from '../data/repositories.js';
|
||||||
|
@ -20,17 +18,12 @@ import { UserDTO } from '../interfaces/user.js';
|
||||||
|
|
||||||
// TODO: accept arguments (full, ...)
|
// TODO: accept arguments (full, ...)
|
||||||
// TODO: endpoints
|
// TODO: endpoints
|
||||||
export async function getAllStudentsHandler(
|
export async function getAllStudentsHandler(req: Request, res: Response): Promise<void> {
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
): Promise<void> {
|
|
||||||
const full = req.query.full === 'true';
|
const full = req.query.full === 'true';
|
||||||
|
|
||||||
const studentRepository = getStudentRepository();
|
const studentRepository = getStudentRepository();
|
||||||
|
|
||||||
const students: StudentDTO[] | string[] = full
|
const students: StudentDTO[] | string[] = full ? await getAllStudents() : await getAllStudents();
|
||||||
? await getAllStudents()
|
|
||||||
: await getAllStudents();
|
|
||||||
|
|
||||||
if (!students) {
|
if (!students) {
|
||||||
res.status(404).json({ error: `Student not found.` });
|
res.status(404).json({ error: `Student not found.` });
|
||||||
|
@ -40,11 +33,7 @@ export async function getAllStudentsHandler(
|
||||||
res.status(201).json(students);
|
res.status(201).json(students);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getStudentHandler(req: Request, res: Response): Promise<void> {
|
||||||
export async function getStudentHandler(
|
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
): Promise<void> {
|
|
||||||
const username = req.params.username;
|
const username = req.params.username;
|
||||||
|
|
||||||
if (!username) {
|
if (!username) {
|
||||||
|
@ -64,10 +53,7 @@ export async function getStudentHandler(
|
||||||
res.status(201).json(user);
|
res.status(201).json(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createStudentHandler(
|
export async function createStudentHandler(req: Request, res: Response) {
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
) {
|
|
||||||
const userData = req.body as StudentDTO;
|
const userData = req.body as StudentDTO;
|
||||||
|
|
||||||
if (!userData.username || !userData.firstName || !userData.lastName) {
|
if (!userData.username || !userData.firstName || !userData.lastName) {
|
||||||
|
@ -81,10 +67,7 @@ export async function createStudentHandler(
|
||||||
res.status(201).json(newUser);
|
res.status(201).json(newUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteStudentHandler(
|
export async function deleteStudentHandler(req: Request, res: Response) {
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
) {
|
|
||||||
const username = req.params.username;
|
const username = req.params.username;
|
||||||
|
|
||||||
if (!username) {
|
if (!username) {
|
||||||
|
@ -103,10 +86,7 @@ export async function deleteStudentHandler(
|
||||||
res.status(200).json(deletedUser);
|
res.status(200).json(deletedUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getStudentClassesHandler(
|
export async function getStudentClassesHandler(req: Request, res: Response): Promise<void> {
|
||||||
req: Request,
|
|
||||||
res: Response
|
|
||||||
): Promise<void> {
|
|
||||||
try {
|
try {
|
||||||
const full = req.query.full === 'true';
|
const full = req.query.full === 'true';
|
||||||
const username = req.params.id;
|
const username = req.params.id;
|
||||||
|
@ -132,10 +112,7 @@ export async function getStudentClassesHandler(
|
||||||
// Might not be fully correct depending on if
|
// Might not be fully correct depending on if
|
||||||
// A class has an assignment, that all students
|
// A class has an assignment, that all students
|
||||||
// Have this assignment.
|
// Have this assignment.
|
||||||
export async function getStudentAssignmentsHandler(
|
export async function getStudentAssignmentsHandler(req: Request, res: Response): Promise<void> {
|
||||||
req: Request,
|
|
||||||
res: Response
|
|
||||||
): Promise<void> {
|
|
||||||
const full = req.query.full === 'true';
|
const full = req.query.full === 'true';
|
||||||
const username = req.params.id;
|
const username = req.params.id;
|
||||||
|
|
||||||
|
@ -146,24 +123,18 @@ export async function getStudentAssignmentsHandler(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getStudentGroupsHandler(
|
export async function getStudentGroupsHandler(req: Request, res: Response): Promise<void> {
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
): Promise<void> {
|
|
||||||
const full = req.query.full === 'true';
|
const full = req.query.full === 'true';
|
||||||
const username = req.params.id;
|
const username = req.params.id;
|
||||||
|
|
||||||
const groups = await getStudentGroups(username, full);
|
const groups = await getStudentGroups(username, full);
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
groups: groups,
|
groups: groups,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getStudentSubmissionsHandler(
|
export async function getStudentSubmissionsHandler(req: Request, res: Response): Promise<void> {
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
): Promise<void> {
|
|
||||||
const username = req.params.id;
|
const username = req.params.id;
|
||||||
|
|
||||||
const submissions = await getStudentSubmissions(username);
|
const submissions = await getStudentSubmissions(username);
|
||||||
|
@ -175,4 +146,3 @@ export async function getStudentSubmissionsHandler(
|
||||||
function getAllStudents(): StudentDTO[] | string[] | PromiseLike<StudentDTO[] | string[]> {
|
function getAllStudents(): StudentDTO[] | string[] | PromiseLike<StudentDTO[] | string[]> {
|
||||||
throw new Error('Function not implemented.');
|
throw new Error('Function not implemented.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from 'express';
|
||||||
import {createSubmission, deleteSubmission, getSubmission} from "../services/submissions.js";
|
import { createSubmission, deleteSubmission, getSubmission } from '../services/submissions.js';
|
||||||
import { Language, languageMap } from "../entities/content/language.js";
|
import { Language, languageMap } from '../entities/content/language.js';
|
||||||
import {SubmissionDTO} from "../interfaces/submission";
|
import { SubmissionDTO } from '../interfaces/submission';
|
||||||
|
|
||||||
interface SubmissionParams {
|
interface SubmissionParams {
|
||||||
hruid: string,
|
hruid: string;
|
||||||
id: number;
|
id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getSubmissionHandler(
|
export async function getSubmissionHandler(req: Request<SubmissionParams>, res: Response): Promise<void> {
|
||||||
req: Request<SubmissionParams>,
|
|
||||||
res: Response,
|
|
||||||
): Promise<void> {
|
|
||||||
const lohruid = req.params.hruid;
|
const lohruid = req.params.hruid;
|
||||||
const submissionNumber = +req.params.id;
|
const submissionNumber = +req.params.id;
|
||||||
|
|
||||||
|
@ -33,18 +30,19 @@ export async function getSubmissionHandler(
|
||||||
res.json(submission);
|
res.json(submission);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createSubmissionHandler(req: Request, res: Response){
|
export async function createSubmissionHandler(req: Request, res: Response) {
|
||||||
const submissionDTO = req.body as SubmissionDTO;
|
const submissionDTO = req.body as SubmissionDTO;
|
||||||
|
|
||||||
const submission = await createSubmission(submissionDTO);
|
const submission = await createSubmission(submissionDTO);
|
||||||
|
|
||||||
if (!submission)
|
if (!submission) {
|
||||||
{res.status(404).json({ error: 'Submission not added' });}
|
res.status(404).json({ error: 'Submission not added' });
|
||||||
else
|
} else {
|
||||||
{res.json(submission)}
|
res.json(submission);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteSubmissionHandler(req: Request, res: Response){
|
export async function deleteSubmissionHandler(req: Request, res: Response) {
|
||||||
const hruid = req.params.hruid;
|
const hruid = req.params.hruid;
|
||||||
const submissionNumber = +req.params.id;
|
const submissionNumber = +req.params.id;
|
||||||
|
|
||||||
|
@ -53,8 +51,9 @@ export async function deleteSubmissionHandler(req: Request, res: Response){
|
||||||
|
|
||||||
const submission = await deleteSubmission(hruid, lang, version, submissionNumber);
|
const submission = await deleteSubmission(hruid, lang, version, submissionNumber);
|
||||||
|
|
||||||
if (!submission)
|
if (!submission) {
|
||||||
{res.status(404).json({ error: 'Submission not found' });}
|
res.status(404).json({ error: 'Submission not found' });
|
||||||
else
|
} else {
|
||||||
{res.json(submission)}
|
res.json(submission);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,16 @@
|
||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
import { createTeacher, deleteTeacher, getAllTeachers, getClassesByTeacher, getClassIdsByTeacher, getQuestionIdsByTeacher, getQuestionsByTeacher, getStudentIdsByTeacher, getStudentsByTeacher, getTeacher } from '../services/teachers.js';
|
import {
|
||||||
|
createTeacher,
|
||||||
|
deleteTeacher,
|
||||||
|
getAllTeachers,
|
||||||
|
getClassesByTeacher,
|
||||||
|
getClassIdsByTeacher,
|
||||||
|
getQuestionIdsByTeacher,
|
||||||
|
getQuestionsByTeacher,
|
||||||
|
getStudentIdsByTeacher,
|
||||||
|
getStudentsByTeacher,
|
||||||
|
getTeacher,
|
||||||
|
} from '../services/teachers.js';
|
||||||
import { ClassDTO } from '../interfaces/class.js';
|
import { ClassDTO } from '../interfaces/class.js';
|
||||||
import { StudentDTO } from '../interfaces/student.js';
|
import { StudentDTO } from '../interfaces/student.js';
|
||||||
import { QuestionDTO, QuestionId } from '../interfaces/question.js';
|
import { QuestionDTO, QuestionId } from '../interfaces/question.js';
|
||||||
|
@ -7,17 +18,12 @@ import { Teacher } from '../entities/users/teacher.entity.js';
|
||||||
import { TeacherDTO } from '../interfaces/teacher.js';
|
import { TeacherDTO } from '../interfaces/teacher.js';
|
||||||
import { getTeacherRepository } from '../data/repositories.js';
|
import { getTeacherRepository } from '../data/repositories.js';
|
||||||
|
|
||||||
export async function getAllTeachersHandler(
|
export async function getAllTeachersHandler(req: Request, res: Response): Promise<void> {
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
): Promise<void> {
|
|
||||||
const full = req.query.full === 'true';
|
const full = req.query.full === 'true';
|
||||||
|
|
||||||
const teacherRepository = getTeacherRepository();
|
const teacherRepository = getTeacherRepository();
|
||||||
|
|
||||||
const teachers: TeacherDTO[] | string[] = full
|
const teachers: TeacherDTO[] | string[] = full ? await getAllTeachers() : await getAllTeachers();
|
||||||
? await getAllTeachers()
|
|
||||||
: await getAllTeachers();
|
|
||||||
|
|
||||||
if (!teachers) {
|
if (!teachers) {
|
||||||
res.status(404).json({ error: `Teacher not found.` });
|
res.status(404).json({ error: `Teacher not found.` });
|
||||||
|
@ -27,11 +33,7 @@ export async function getAllTeachersHandler(
|
||||||
res.status(201).json(teachers);
|
res.status(201).json(teachers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getTeacherHandler(req: Request, res: Response): Promise<void> {
|
||||||
export async function getTeacherHandler(
|
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
): Promise<void> {
|
|
||||||
const username = req.params.username;
|
const username = req.params.username;
|
||||||
|
|
||||||
if (!username) {
|
if (!username) {
|
||||||
|
@ -51,10 +53,7 @@ export async function getTeacherHandler(
|
||||||
res.status(201).json(user);
|
res.status(201).json(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createTeacherHandler(
|
export async function createTeacherHandler(req: Request, res: Response) {
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
) {
|
|
||||||
const userData = req.body as TeacherDTO;
|
const userData = req.body as TeacherDTO;
|
||||||
|
|
||||||
if (!userData.username || !userData.firstName || !userData.lastName) {
|
if (!userData.username || !userData.firstName || !userData.lastName) {
|
||||||
|
@ -68,10 +67,7 @@ export async function createTeacherHandler(
|
||||||
res.status(201).json(newUser);
|
res.status(201).json(newUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteTeacherHandler(
|
export async function deleteTeacherHandler(req: Request, res: Response) {
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
) {
|
|
||||||
const username = req.params.username;
|
const username = req.params.username;
|
||||||
|
|
||||||
if (!username) {
|
if (!username) {
|
||||||
|
@ -90,11 +86,7 @@ export async function deleteTeacherHandler(
|
||||||
res.status(200).json(deletedUser);
|
res.status(200).json(deletedUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getTeacherClassHandler(req: Request, res: Response): Promise<void> {
|
||||||
export async function getTeacherClassHandler(
|
|
||||||
req: Request,
|
|
||||||
res: Response
|
|
||||||
): Promise<void> {
|
|
||||||
try {
|
try {
|
||||||
const username = req.params.username as string;
|
const username = req.params.username as string;
|
||||||
const full = req.query.full === 'true';
|
const full = req.query.full === 'true';
|
||||||
|
@ -104,9 +96,7 @@ export async function getTeacherClassHandler(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const classes: ClassDTO[] | string[] = full
|
const classes: ClassDTO[] | string[] = full ? await getClassesByTeacher(username) : await getClassIdsByTeacher(username);
|
||||||
? await getClassesByTeacher(username)
|
|
||||||
: await getClassIdsByTeacher(username);
|
|
||||||
|
|
||||||
res.status(201).json(classes);
|
res.status(201).json(classes);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -115,10 +105,7 @@ export async function getTeacherClassHandler(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getTeacherStudentHandler(
|
export async function getTeacherStudentHandler(req: Request, res: Response): Promise<void> {
|
||||||
req: Request,
|
|
||||||
res: Response
|
|
||||||
): Promise<void> {
|
|
||||||
try {
|
try {
|
||||||
const username = req.params.username as string;
|
const username = req.params.username as string;
|
||||||
const full = req.query.full === 'true';
|
const full = req.query.full === 'true';
|
||||||
|
@ -128,9 +115,7 @@ export async function getTeacherStudentHandler(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const students: StudentDTO[] | string[] = full
|
const students: StudentDTO[] | string[] = full ? await getStudentsByTeacher(username) : await getStudentIdsByTeacher(username);
|
||||||
? await getStudentsByTeacher(username)
|
|
||||||
: await getStudentIdsByTeacher(username);
|
|
||||||
|
|
||||||
res.status(201).json(students);
|
res.status(201).json(students);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -139,10 +124,7 @@ export async function getTeacherStudentHandler(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getTeacherQuestionHandler(
|
export async function getTeacherQuestionHandler(req: Request, res: Response): Promise<void> {
|
||||||
req: Request,
|
|
||||||
res: Response
|
|
||||||
): Promise<void> {
|
|
||||||
try {
|
try {
|
||||||
const username = req.params.username as string;
|
const username = req.params.username as string;
|
||||||
const full = req.query.full === 'true';
|
const full = req.query.full === 'true';
|
||||||
|
@ -152,9 +134,7 @@ export async function getTeacherQuestionHandler(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const questions: QuestionDTO[] | QuestionId[] = full
|
const questions: QuestionDTO[] | QuestionId[] = full ? await getQuestionsByTeacher(username) : await getQuestionIdsByTeacher(username);
|
||||||
? await getQuestionsByTeacher(username)
|
|
||||||
: await getQuestionIdsByTeacher(username);
|
|
||||||
|
|
||||||
res.status(201).json(questions);
|
res.status(201).json(questions);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -3,17 +3,11 @@ import { UserService } from '../services/users.js';
|
||||||
import { UserDTO } from '../interfaces/user.js';
|
import { UserDTO } from '../interfaces/user.js';
|
||||||
import { User } from '../entities/users/user.entity.js';
|
import { User } from '../entities/users/user.entity.js';
|
||||||
|
|
||||||
export async function getAllUsersHandler<T extends User>(
|
export async function getAllUsersHandler<T extends User>(req: Request, res: Response, service: UserService<T>): Promise<void> {
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
service: UserService<T>
|
|
||||||
): Promise<void> {
|
|
||||||
try {
|
try {
|
||||||
const full = req.query.full === 'true';
|
const full = req.query.full === 'true';
|
||||||
|
|
||||||
const users: UserDTO[] | string[] = full
|
const users: UserDTO[] | string[] = full ? await service.getAllUsers() : await service.getAllUserIds();
|
||||||
? await service.getAllUsers()
|
|
||||||
: await service.getAllUserIds();
|
|
||||||
|
|
||||||
if (!users) {
|
if (!users) {
|
||||||
res.status(404).json({ error: `Users not found.` });
|
res.status(404).json({ error: `Users not found.` });
|
||||||
|
@ -27,11 +21,7 @@ export async function getAllUsersHandler<T extends User>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getUserHandler<T extends User>(
|
export async function getUserHandler<T extends User>(req: Request, res: Response, service: UserService<T>): Promise<void> {
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
service: UserService<T>
|
|
||||||
): Promise<void> {
|
|
||||||
try {
|
try {
|
||||||
const username = req.params.username as string;
|
const username = req.params.username as string;
|
||||||
|
|
||||||
|
@ -56,12 +46,7 @@ export async function getUserHandler<T extends User>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createUserHandler<T extends User>(
|
export async function createUserHandler<T extends User>(req: Request, res: Response, service: UserService<T>, UserClass: new () => T) {
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
service: UserService<T>,
|
|
||||||
UserClass: new () => T
|
|
||||||
) {
|
|
||||||
try {
|
try {
|
||||||
console.log('req', req);
|
console.log('req', req);
|
||||||
const userData = req.body as UserDTO;
|
const userData = req.body as UserDTO;
|
||||||
|
@ -81,11 +66,7 @@ export async function createUserHandler<T extends User>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteUserHandler<T extends User>(
|
export async function deleteUserHandler<T extends User>(req: Request, res: Response, service: UserService<T>) {
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
service: UserService<T>
|
|
||||||
) {
|
|
||||||
try {
|
try {
|
||||||
const username = req.params.username;
|
const username = req.params.username;
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,7 @@ import { Assignment } from '../../entities/assignments/assignment.entity.js';
|
||||||
import { Student } from '../../entities/users/student.entity.js';
|
import { Student } from '../../entities/users/student.entity.js';
|
||||||
|
|
||||||
export class GroupRepository extends DwengoEntityRepository<Group> {
|
export class GroupRepository extends DwengoEntityRepository<Group> {
|
||||||
public findByAssignmentAndGroupNumber(
|
public findByAssignmentAndGroupNumber(assignment: Assignment, groupNumber: number): Promise<Group | null> {
|
||||||
assignment: Assignment,
|
|
||||||
groupNumber: number
|
|
||||||
): Promise<Group | null> {
|
|
||||||
return this.findOne(
|
return this.findOne(
|
||||||
{
|
{
|
||||||
assignment: assignment,
|
assignment: assignment,
|
||||||
|
@ -16,26 +13,16 @@ export class GroupRepository extends DwengoEntityRepository<Group> {
|
||||||
{ populate: ['members'] }
|
{ populate: ['members'] }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
public findAllGroupsForAssignment(
|
public findAllGroupsForAssignment(assignment: Assignment): Promise<Group[]> {
|
||||||
assignment: Assignment
|
|
||||||
): Promise<Group[]> {
|
|
||||||
return this.findAll({
|
return this.findAll({
|
||||||
where: { assignment: assignment },
|
where: { assignment: assignment },
|
||||||
populate: ['members'],
|
populate: ['members'],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public findAllGroupsWithStudent(
|
public findAllGroupsWithStudent(student: Student): Promise<Group[]> {
|
||||||
student: Student
|
return this.find({ members: student }, { populate: ['members'] });
|
||||||
): Promise<Group[]> {
|
|
||||||
return this.find(
|
|
||||||
{ members: student },
|
|
||||||
{ populate: ['members'] }
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
public deleteByAssignmentAndGroupNumber(
|
public deleteByAssignmentAndGroupNumber(assignment: Assignment, groupNumber: number) {
|
||||||
assignment: Assignment,
|
|
||||||
groupNumber: number
|
|
||||||
) {
|
|
||||||
return this.deleteWhere({
|
return this.deleteWhere({
|
||||||
assignment: assignment,
|
assignment: assignment,
|
||||||
groupNumber: groupNumber,
|
groupNumber: groupNumber,
|
||||||
|
|
|
@ -5,10 +5,7 @@ import { LearningObjectIdentifier } from '../../entities/content/learning-object
|
||||||
import { Student } from '../../entities/users/student.entity.js';
|
import { Student } from '../../entities/users/student.entity.js';
|
||||||
|
|
||||||
export class SubmissionRepository extends DwengoEntityRepository<Submission> {
|
export class SubmissionRepository extends DwengoEntityRepository<Submission> {
|
||||||
public findSubmissionByLearningObjectAndSubmissionNumber(
|
public findSubmissionByLearningObjectAndSubmissionNumber(loId: LearningObjectIdentifier, submissionNumber: number): Promise<Submission | null> {
|
||||||
loId: LearningObjectIdentifier,
|
|
||||||
submissionNumber: number
|
|
||||||
): Promise<Submission | null> {
|
|
||||||
return this.findOne({
|
return this.findOne({
|
||||||
learningObjectHruid: loId.hruid,
|
learningObjectHruid: loId.hruid,
|
||||||
learningObjectLanguage: loId.language,
|
learningObjectLanguage: loId.language,
|
||||||
|
@ -17,10 +14,7 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public findMostRecentSubmissionForStudent(
|
public findMostRecentSubmissionForStudent(loId: LearningObjectIdentifier, submitter: Student): Promise<Submission | null> {
|
||||||
loId: LearningObjectIdentifier,
|
|
||||||
submitter: Student
|
|
||||||
): Promise<Submission | null> {
|
|
||||||
return this.findOne(
|
return this.findOne(
|
||||||
{
|
{
|
||||||
learningObjectHruid: loId.hruid,
|
learningObjectHruid: loId.hruid,
|
||||||
|
@ -32,10 +26,7 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public findMostRecentSubmissionForGroup(
|
public findMostRecentSubmissionForGroup(loId: LearningObjectIdentifier, group: Group): Promise<Submission | null> {
|
||||||
loId: LearningObjectIdentifier,
|
|
||||||
group: Group
|
|
||||||
): Promise<Submission | null> {
|
|
||||||
return this.findOne(
|
return this.findOne(
|
||||||
{
|
{
|
||||||
learningObjectHruid: loId.hruid,
|
learningObjectHruid: loId.hruid,
|
||||||
|
@ -47,26 +38,15 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public findAllSubmissionsForGroup(
|
public findAllSubmissionsForGroup(group: Group): Promise<Submission[]> {
|
||||||
group: Group,
|
return this.find({ onBehalfOf: group });
|
||||||
): Promise<Submission[]> {
|
|
||||||
return this.find(
|
|
||||||
{ onBehalfOf: group },
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public findAllSubmissionsForStudent(
|
public findAllSubmissionsForStudent(student: Student): Promise<Submission[]> {
|
||||||
student: Student,
|
return this.find({ submitter: student });
|
||||||
): Promise<Submission[]> {
|
|
||||||
return this.find(
|
|
||||||
{ submitter: student },
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public deleteSubmissionByLearningObjectAndSubmissionNumber(
|
public deleteSubmissionByLearningObjectAndSubmissionNumber(loId: LearningObjectIdentifier, submissionNumber: number): Promise<void> {
|
||||||
loId: LearningObjectIdentifier,
|
|
||||||
submissionNumber: number
|
|
||||||
): Promise<void> {
|
|
||||||
return this.deleteWhere({
|
return this.deleteWhere({
|
||||||
learningObjectHruid: loId.hruid,
|
learningObjectHruid: loId.hruid,
|
||||||
learningObjectLanguage: loId.language,
|
learningObjectLanguage: loId.language,
|
||||||
|
|
|
@ -5,10 +5,7 @@ import { Teacher } from '../../entities/users/teacher.entity';
|
||||||
|
|
||||||
export class ClassRepository extends DwengoEntityRepository<Class> {
|
export class ClassRepository extends DwengoEntityRepository<Class> {
|
||||||
public findById(id: string): Promise<Class | null> {
|
public findById(id: string): Promise<Class | null> {
|
||||||
return this.findOne(
|
return this.findOne({ classId: id }, { populate: ['students', 'teachers'] });
|
||||||
{ classId: id },
|
|
||||||
{ populate: ['students', 'teachers'] }
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
public deleteById(id: string): Promise<void> {
|
public deleteById(id: string): Promise<void> {
|
||||||
return this.deleteWhere({ classId: id });
|
return this.deleteWhere({ classId: id });
|
||||||
|
@ -21,9 +18,6 @@ export class ClassRepository extends DwengoEntityRepository<Class> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public findByTeacher(teacher: Teacher): Promise<Class[]> {
|
public findByTeacher(teacher: Teacher): Promise<Class[]> {
|
||||||
return this.find(
|
return this.find({ teachers: teacher }, { populate: ['students', 'teachers'] });
|
||||||
{ teachers: teacher },
|
|
||||||
{ populate: ['students', 'teachers'] }
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,7 @@ export class AnswerRepository extends DwengoEntityRepository<Answer> {
|
||||||
orderBy: { sequenceNumber: 'ASC' },
|
orderBy: { sequenceNumber: 'ASC' },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public removeAnswerByQuestionAndSequenceNumber(
|
public removeAnswerByQuestionAndSequenceNumber(question: Question, sequenceNumber: number): Promise<void> {
|
||||||
question: Question,
|
|
||||||
sequenceNumber: number
|
|
||||||
): Promise<void> {
|
|
||||||
return this.deleteWhere({
|
return this.deleteWhere({
|
||||||
toQuestion: question,
|
toQuestion: question,
|
||||||
sequenceNumber: sequenceNumber,
|
sequenceNumber: sequenceNumber,
|
||||||
|
|
|
@ -21,9 +21,7 @@ export class QuestionRepository extends DwengoEntityRepository<Question> {
|
||||||
questionEntity.content = question.content;
|
questionEntity.content = question.content;
|
||||||
return this.insert(questionEntity);
|
return this.insert(questionEntity);
|
||||||
}
|
}
|
||||||
public findAllQuestionsAboutLearningObject(
|
public findAllQuestionsAboutLearningObject(loId: LearningObjectIdentifier): Promise<Question[]> {
|
||||||
loId: LearningObjectIdentifier
|
|
||||||
): Promise<Question[]> {
|
|
||||||
return this.findAll({
|
return this.findAll({
|
||||||
where: {
|
where: {
|
||||||
learningObjectHruid: loId.hruid,
|
learningObjectHruid: loId.hruid,
|
||||||
|
@ -35,10 +33,7 @@ export class QuestionRepository extends DwengoEntityRepository<Question> {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public removeQuestionByLearningObjectAndSequenceNumber(
|
public removeQuestionByLearningObjectAndSequenceNumber(loId: LearningObjectIdentifier, sequenceNumber: number): Promise<void> {
|
||||||
loId: LearningObjectIdentifier,
|
|
||||||
sequenceNumber: number
|
|
||||||
): Promise<void> {
|
|
||||||
return this.deleteWhere({
|
return this.deleteWhere({
|
||||||
learningObjectHruid: loId.hruid,
|
learningObjectHruid: loId.hruid,
|
||||||
learningObjectLanguage: loId.language,
|
learningObjectLanguage: loId.language,
|
||||||
|
@ -47,14 +42,12 @@ export class QuestionRepository extends DwengoEntityRepository<Question> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async findAllByLearningObjects(
|
public async findAllByLearningObjects(learningObjects: LearningObject[]): Promise<Question[]> {
|
||||||
learningObjects: LearningObject[]
|
|
||||||
): Promise<Question[]> {
|
|
||||||
const objectIdentifiers = learningObjects.map((lo) => ({
|
const objectIdentifiers = learningObjects.map((lo) => ({
|
||||||
learningObjectHruid: lo.hruid,
|
learningObjectHruid: lo.hruid,
|
||||||
learningObjectLanguage: lo.language,
|
learningObjectLanguage: lo.language,
|
||||||
learningObjectVersion: lo.version,
|
learningObjectVersion: lo.version,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return this.findAll({
|
return this.findAll({
|
||||||
where: { $or: objectIdentifiers },
|
where: { $or: objectIdentifiers },
|
||||||
|
|
|
@ -40,9 +40,7 @@ export function transactional<T>(f: () => Promise<T>) {
|
||||||
entityManager?.transactional(f);
|
entityManager?.transactional(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
function repositoryGetter<T extends AnyEntity, R extends EntityRepository<T>>(
|
function repositoryGetter<T extends AnyEntity, R extends EntityRepository<T>>(entity: EntityName<T>): () => R {
|
||||||
entity: EntityName<T>
|
|
||||||
): () => R {
|
|
||||||
let cachedRepo: R | undefined;
|
let cachedRepo: R | undefined;
|
||||||
return (): R => {
|
return (): R => {
|
||||||
if (!cachedRepo) {
|
if (!cachedRepo) {
|
||||||
|
|
|
@ -12,4 +12,4 @@ export class StudentRepository extends DwengoEntityRepository<Student> {
|
||||||
public deleteByUsername(username: string): Promise<void> {
|
public deleteByUsername(username: string): Promise<void> {
|
||||||
return this.deleteWhere({ username: username });
|
return this.deleteWhere({ username: username });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,4 +9,4 @@ export class TeacherRepository extends DwengoEntityRepository<Teacher> {
|
||||||
public deleteByUsername(username: string): Promise<void> {
|
public deleteByUsername(username: string): Promise<void> {
|
||||||
return this.deleteWhere({ username: username });
|
return this.deleteWhere({ username: username });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,4 @@
|
||||||
import {
|
import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
|
||||||
Collection,
|
|
||||||
Entity,
|
|
||||||
Enum,
|
|
||||||
ManyToOne,
|
|
||||||
OneToMany,
|
|
||||||
PrimaryKey,
|
|
||||||
Property,
|
|
||||||
} from '@mikro-orm/core';
|
|
||||||
import { Class } from '../classes/class.entity.js';
|
import { Class } from '../classes/class.entity.js';
|
||||||
import { Group } from './group.entity.js';
|
import { Group } from './group.entity.js';
|
||||||
import { Language } from '../content/language.js';
|
import { Language } from '../content/language.js';
|
||||||
|
|
|
@ -1,10 +1,4 @@
|
||||||
import {
|
import { Collection, Entity, ManyToMany, PrimaryKey, Property } from '@mikro-orm/core';
|
||||||
Collection,
|
|
||||||
Entity,
|
|
||||||
ManyToMany,
|
|
||||||
PrimaryKey,
|
|
||||||
Property,
|
|
||||||
} from '@mikro-orm/core';
|
|
||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
import { Teacher } from '../users/teacher.entity.js';
|
import { Teacher } from '../users/teacher.entity.js';
|
||||||
import { Student } from '../users/student.entity.js';
|
import { Student } from '../users/student.entity.js';
|
||||||
|
|
|
@ -190,4 +190,4 @@ export const languageMap: Record<string, Language> = {
|
||||||
fr: Language.French,
|
fr: Language.French,
|
||||||
en: Language.English,
|
en: Language.English,
|
||||||
de: Language.German,
|
de: Language.German,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,13 +1,4 @@
|
||||||
import {
|
import { Embeddable, Embedded, Entity, Enum, ManyToMany, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
|
||||||
Embeddable,
|
|
||||||
Embedded,
|
|
||||||
Entity,
|
|
||||||
Enum,
|
|
||||||
ManyToMany,
|
|
||||||
OneToMany,
|
|
||||||
PrimaryKey,
|
|
||||||
Property,
|
|
||||||
} from '@mikro-orm/core';
|
|
||||||
import { Language } from './language.js';
|
import { Language } from './language.js';
|
||||||
import { Attachment } from './attachment.entity.js';
|
import { Attachment } from './attachment.entity.js';
|
||||||
import { Teacher } from '../users/teacher.entity.js';
|
import { Teacher } from '../users/teacher.entity.js';
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {mapToUserDTO, UserDTO} from "./user.js";
|
import { mapToUserDTO, UserDTO } from './user.js';
|
||||||
import {mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId} from "./question.js";
|
import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from './question.js';
|
||||||
import {Answer} from "../entities/questions/answer.entity.js";
|
import { Answer } from '../entities/questions/answer.entity.js';
|
||||||
|
|
||||||
export interface AnswerDTO {
|
export interface AnswerDTO {
|
||||||
author: UserDTO;
|
author: UserDTO;
|
||||||
|
@ -33,6 +33,6 @@ export function mapToAnswerId(answer: AnswerDTO): AnswerId {
|
||||||
return {
|
return {
|
||||||
author: answer.author.username,
|
author: answer.author.username,
|
||||||
toQuestion: mapToQuestionId(answer.toQuestion),
|
toQuestion: mapToQuestionId(answer.toQuestion),
|
||||||
sequenceNumber: answer.sequenceNumber
|
sequenceNumber: answer.sequenceNumber,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,15 +27,11 @@ export function mapToClassDTO(cls: Class): ClassDTO {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mapToClass(
|
export function mapToClass(classData: ClassDTO, students: Collection<Student>, teachers: Collection<Teacher>): Class {
|
||||||
classData: ClassDTO,
|
|
||||||
students: Collection<Student>,
|
|
||||||
teachers: Collection<Teacher>
|
|
||||||
): Class {
|
|
||||||
const cls = new Class();
|
const cls = new Class();
|
||||||
cls.displayName = classData.displayName;
|
cls.displayName = classData.displayName;
|
||||||
cls.students = students;
|
cls.students = students;
|
||||||
cls.teachers = teachers;
|
cls.teachers = teachers;
|
||||||
|
|
||||||
return cls;
|
return cls;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { Question } from '../entities/questions/question.entity.js';
|
import { Question } from '../entities/questions/question.entity.js';
|
||||||
import {UserDTO} from "./user.js";
|
import { UserDTO } from './user.js';
|
||||||
import {LearningObjectIdentifier} from "../entities/content/learning-object-identifier.js";
|
import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js';
|
||||||
import { mapToStudentDTO, StudentDTO } from './student.js';
|
import { mapToStudentDTO, StudentDTO } from './student.js';
|
||||||
import { TeacherDTO } from './teacher.js';
|
import { TeacherDTO } from './teacher.js';
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ export function mapToQuestionDTO(question: Question): QuestionDTO {
|
||||||
const learningObjectIdentifier = {
|
const learningObjectIdentifier = {
|
||||||
hruid: question.learningObjectHruid,
|
hruid: question.learningObjectHruid,
|
||||||
language: question.learningObjectLanguage,
|
language: question.learningObjectLanguage,
|
||||||
version: question.learningObjectVersion
|
version: question.learningObjectVersion,
|
||||||
}
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
learningObjectIdentifier,
|
learningObjectIdentifier,
|
||||||
|
@ -42,4 +42,3 @@ export function mapToQuestionId(question: QuestionDTO): QuestionId {
|
||||||
sequenceNumber: question.sequenceNumber!,
|
sequenceNumber: question.sequenceNumber!,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,11 +23,7 @@ export function mapToStudentDTO(student: Student): StudentDTO {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mapToStudent(studentData: StudentDTO): Student {
|
export function mapToStudent(studentData: StudentDTO): Student {
|
||||||
const student = new Student(
|
const student = new Student(studentData.username, studentData.firstName, studentData.lastName);
|
||||||
studentData.username,
|
|
||||||
studentData.firstName,
|
|
||||||
studentData.lastName,
|
|
||||||
);
|
|
||||||
|
|
||||||
return student;
|
return student;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
import { Submission } from "../entities/assignments/submission.entity.js";
|
import { Submission } from '../entities/assignments/submission.entity.js';
|
||||||
import { Language } from "../entities/content/language.js";
|
import { Language } from '../entities/content/language.js';
|
||||||
import { GroupDTO, mapToGroupDTO } from "./group.js";
|
import { GroupDTO, mapToGroupDTO } from './group.js';
|
||||||
import {mapToStudent, mapToStudentDTO, StudentDTO} from "./student.js";
|
import { mapToStudent, mapToStudentDTO, StudentDTO } from './student.js';
|
||||||
import {mapToUser} from "./user";
|
import { mapToUser } from './user';
|
||||||
import {Student} from "../entities/users/student.entity";
|
import { Student } from '../entities/users/student.entity';
|
||||||
|
|
||||||
export interface SubmissionDTO {
|
export interface SubmissionDTO {
|
||||||
learningObjectHruid: string,
|
learningObjectHruid: string;
|
||||||
learningObjectLanguage: Language,
|
learningObjectLanguage: Language;
|
||||||
learningObjectVersion: number,
|
learningObjectVersion: number;
|
||||||
|
|
||||||
submissionNumber?: number,
|
submissionNumber?: number;
|
||||||
submitter: StudentDTO,
|
submitter: StudentDTO;
|
||||||
time?: Date,
|
time?: Date;
|
||||||
group?: GroupDTO,
|
group?: GroupDTO;
|
||||||
content: string,
|
content: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mapToSubmissionDTO(submission: Submission): SubmissionDTO {
|
export function mapToSubmissionDTO(submission: Submission): SubmissionDTO {
|
||||||
|
@ -28,7 +28,7 @@ export function mapToSubmissionDTO(submission: Submission): SubmissionDTO {
|
||||||
time: submission.submissionTime,
|
time: submission.submissionTime,
|
||||||
group: submission.onBehalfOf ? mapToGroupDTO(submission.onBehalfOf) : undefined,
|
group: submission.onBehalfOf ? mapToGroupDTO(submission.onBehalfOf) : undefined,
|
||||||
content: submission.content,
|
content: submission.content,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mapToSubmission(submissionDTO: SubmissionDTO): Submission {
|
export function mapToSubmission(submissionDTO: SubmissionDTO): Submission {
|
||||||
|
@ -37,7 +37,7 @@ export function mapToSubmission(submissionDTO: SubmissionDTO): Submission {
|
||||||
submission.learningObjectLanguage = submissionDTO.learningObjectLanguage;
|
submission.learningObjectLanguage = submissionDTO.learningObjectLanguage;
|
||||||
submission.learningObjectVersion = submissionDTO.learningObjectVersion;
|
submission.learningObjectVersion = submissionDTO.learningObjectVersion;
|
||||||
// Submission.submissionNumber = submissionDTO.submissionNumber;
|
// Submission.submissionNumber = submissionDTO.submissionNumber;
|
||||||
submission.submitter = mapToStudent(submissionDTO.submitter) ;
|
submission.submitter = mapToStudent(submissionDTO.submitter);
|
||||||
// Submission.submissionTime = submissionDTO.time;
|
// Submission.submissionTime = submissionDTO.time;
|
||||||
// Submission.onBehalfOf = submissionDTO.group!;
|
// Submission.onBehalfOf = submissionDTO.group!;
|
||||||
// TODO fix group
|
// TODO fix group
|
||||||
|
|
|
@ -8,9 +8,7 @@ export interface TeacherInvitationDTO {
|
||||||
class: string | ClassDTO;
|
class: string | ClassDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mapToTeacherInvitationDTO(
|
export function mapToTeacherInvitationDTO(invitation: TeacherInvitation): TeacherInvitationDTO {
|
||||||
invitation: TeacherInvitation
|
|
||||||
): TeacherInvitationDTO {
|
|
||||||
return {
|
return {
|
||||||
sender: mapToUserDTO(invitation.sender),
|
sender: mapToUserDTO(invitation.sender),
|
||||||
receiver: mapToUserDTO(invitation.receiver),
|
receiver: mapToUserDTO(invitation.receiver),
|
||||||
|
@ -18,9 +16,7 @@ export function mapToTeacherInvitationDTO(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mapToTeacherInvitationDTOIds(
|
export function mapToTeacherInvitationDTOIds(invitation: TeacherInvitation): TeacherInvitationDTO {
|
||||||
invitation: TeacherInvitation
|
|
||||||
): TeacherInvitationDTO {
|
|
||||||
return {
|
return {
|
||||||
sender: invitation.sender.username,
|
sender: invitation.sender.username,
|
||||||
receiver: invitation.receiver.username,
|
receiver: invitation.receiver.username,
|
||||||
|
|
|
@ -23,11 +23,7 @@ export function mapToTeacherDTO(teacher: Teacher): TeacherDTO {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mapToTeacher(TeacherData: TeacherDTO): Teacher {
|
export function mapToTeacher(TeacherData: TeacherDTO): Teacher {
|
||||||
const teacher = new Teacher(
|
const teacher = new Teacher(TeacherData.username, TeacherData.firstName, TeacherData.lastName);
|
||||||
TeacherData.username,
|
|
||||||
TeacherData.firstName,
|
|
||||||
TeacherData.lastName,
|
|
||||||
);
|
|
||||||
|
|
||||||
return teacher;
|
return teacher;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,10 +22,7 @@ export function mapToUserDTO(user: User): UserDTO {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mapToUser<T extends User>(
|
export function mapToUser<T extends User>(userData: UserDTO, userInstance: T): T {
|
||||||
userData: UserDTO,
|
|
||||||
userInstance: T
|
|
||||||
): T {
|
|
||||||
userInstance.username = userData.username;
|
userInstance.username = userData.username;
|
||||||
userInstance.firstName = userData.firstName;
|
userInstance.firstName = userData.firstName;
|
||||||
userInstance.lastName = userData.lastName;
|
userInstance.lastName = userData.lastName;
|
||||||
|
|
|
@ -1,15 +1,9 @@
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import {
|
import { getAllLearningObjects, getAttachment, getLearningObject, getLearningObjectHTML } from '../controllers/learning-objects.js';
|
||||||
getAllLearningObjects,
|
|
||||||
getAttachment,
|
|
||||||
getLearningObject,
|
|
||||||
getLearningObjectHTML,
|
|
||||||
} from '../controllers/learning-objects.js';
|
|
||||||
|
|
||||||
import submissionRoutes from './submissions.js';
|
import submissionRoutes from './submissions.js';
|
||||||
import questionRoutes from './questions.js';
|
import questionRoutes from './questions.js';
|
||||||
|
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
// DWENGO learning objects
|
// DWENGO learning objects
|
||||||
|
@ -32,7 +26,7 @@ router.get('/:hruid', getLearningObject);
|
||||||
|
|
||||||
router.use('/:hruid/submissions', submissionRoutes);
|
router.use('/:hruid/submissions', submissionRoutes);
|
||||||
|
|
||||||
router.use('/:hruid/:version/questions', questionRoutes)
|
router.use('/:hruid/:version/questions', questionRoutes);
|
||||||
|
|
||||||
// Parameter: hruid of learning object
|
// Parameter: hruid of learning object
|
||||||
// Query: language, version (optional)
|
// Query: language, version (optional)
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import {
|
import {
|
||||||
createQuestionHandler, deleteQuestionHandler,
|
createQuestionHandler,
|
||||||
|
deleteQuestionHandler,
|
||||||
getAllQuestionsHandler,
|
getAllQuestionsHandler,
|
||||||
getQuestionAnswersHandler,
|
getQuestionAnswersHandler,
|
||||||
getQuestionHandler
|
getQuestionHandler,
|
||||||
} from "../controllers/questions.js";
|
} from '../controllers/questions.js';
|
||||||
const router = express.Router({ mergeParams: true });
|
const router = express.Router({ mergeParams: true });
|
||||||
|
|
||||||
// Query language
|
// Query language
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import {createSubmissionHandler, deleteSubmissionHandler, getSubmissionHandler} from '../controllers/submissions.js';
|
import { createSubmissionHandler, deleteSubmissionHandler, getSubmissionHandler } from '../controllers/submissions.js';
|
||||||
const router = express.Router({ mergeParams: true });
|
const router = express.Router({ mergeParams: true });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Root endpoint used to search objects
|
// Root endpoint used to search objects
|
||||||
router.get('/', (req, res) => {
|
router.get('/', (req, res) => {
|
||||||
res.json({
|
res.json({
|
||||||
|
|
|
@ -1,22 +1,9 @@
|
||||||
import {
|
import { getAssignmentRepository, getClassRepository, getGroupRepository, getSubmissionRepository } from '../data/repositories.js';
|
||||||
getAssignmentRepository,
|
|
||||||
getClassRepository,
|
|
||||||
getGroupRepository,
|
|
||||||
getSubmissionRepository,
|
|
||||||
} from '../data/repositories.js';
|
|
||||||
import { Assignment } from '../entities/assignments/assignment.entity.js';
|
import { Assignment } from '../entities/assignments/assignment.entity.js';
|
||||||
import {
|
import { AssignmentDTO, mapToAssignment, mapToAssignmentDTO, mapToAssignmentDTOId } from '../interfaces/assignment.js';
|
||||||
AssignmentDTO,
|
|
||||||
mapToAssignment,
|
|
||||||
mapToAssignmentDTO,
|
|
||||||
mapToAssignmentDTOId,
|
|
||||||
} from '../interfaces/assignment.js';
|
|
||||||
import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js';
|
import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js';
|
||||||
|
|
||||||
export async function getAllAssignments(
|
export async function getAllAssignments(classid: string, full: boolean): Promise<AssignmentDTO[]> {
|
||||||
classid: string,
|
|
||||||
full: boolean
|
|
||||||
): Promise<AssignmentDTO[]> {
|
|
||||||
const classRepository = getClassRepository();
|
const classRepository = getClassRepository();
|
||||||
const cls = await classRepository.findById(classid);
|
const cls = await classRepository.findById(classid);
|
||||||
|
|
||||||
|
@ -25,8 +12,7 @@ export async function getAllAssignments(
|
||||||
}
|
}
|
||||||
|
|
||||||
const assignmentRepository = getAssignmentRepository();
|
const assignmentRepository = getAssignmentRepository();
|
||||||
const assignments =
|
const assignments = await assignmentRepository.findAllAssignmentsInClass(cls);
|
||||||
await assignmentRepository.findAllAssignmentsInClass(cls);
|
|
||||||
|
|
||||||
if (full) {
|
if (full) {
|
||||||
return assignments.map(mapToAssignmentDTO);
|
return assignments.map(mapToAssignmentDTO);
|
||||||
|
@ -35,14 +21,11 @@ export async function getAllAssignments(
|
||||||
return assignments.map(mapToAssignmentDTOId);
|
return assignments.map(mapToAssignmentDTOId);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createAssignment(
|
export async function createAssignment(classid: string, assignmentData: AssignmentDTO): Promise<Assignment | null> {
|
||||||
classid: string,
|
|
||||||
assignmentData: AssignmentDTO,
|
|
||||||
): Promise<Assignment | null> {
|
|
||||||
const classRepository = getClassRepository();
|
const classRepository = getClassRepository();
|
||||||
const cls = await classRepository.findById(classid);
|
const cls = await classRepository.findById(classid);
|
||||||
|
|
||||||
if (!cls) {
|
if (!cls) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,16 +37,12 @@ export async function createAssignment(
|
||||||
await assignmentRepository.save(newAssignment);
|
await assignmentRepository.save(newAssignment);
|
||||||
|
|
||||||
return newAssignment;
|
return newAssignment;
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAssignment(
|
export async function getAssignment(classid: string, id: number): Promise<AssignmentDTO | null> {
|
||||||
classid: string,
|
|
||||||
id: number
|
|
||||||
): Promise<AssignmentDTO | null> {
|
|
||||||
const classRepository = getClassRepository();
|
const classRepository = getClassRepository();
|
||||||
const cls = await classRepository.findById(classid);
|
const cls = await classRepository.findById(classid);
|
||||||
|
|
||||||
|
@ -81,10 +60,7 @@ export async function getAssignment(
|
||||||
return mapToAssignmentDTO(assignment);
|
return mapToAssignmentDTO(assignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAssignmentsSubmissions(
|
export async function getAssignmentsSubmissions(classid: string, assignmentNumber: number): Promise<SubmissionDTO[]> {
|
||||||
classid: string,
|
|
||||||
assignmentNumber: number,
|
|
||||||
): Promise<SubmissionDTO[]> {
|
|
||||||
const classRepository = getClassRepository();
|
const classRepository = getClassRepository();
|
||||||
const cls = await classRepository.findById(classid);
|
const cls = await classRepository.findById(classid);
|
||||||
|
|
||||||
|
@ -103,8 +79,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 =
|
const submissions = (await Promise.all(groups.map((group) => submissionRepository.findAllSubmissionsForGroup(group)))).flat();
|
||||||
(await Promise.all(groups.map(group => submissionRepository.findAllSubmissionsForGroup(group)))).flat();
|
|
||||||
|
|
||||||
return submissions.map(mapToSubmissionDTO);
|
return submissions.map(mapToSubmissionDTO);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +1,12 @@
|
||||||
import {
|
import { getClassRepository, getStudentRepository, getTeacherInvitationRepository, getTeacherRepository } from '../data/repositories.js';
|
||||||
getClassRepository,
|
|
||||||
getStudentRepository,
|
|
||||||
getTeacherInvitationRepository,
|
|
||||||
getTeacherRepository,
|
|
||||||
} from '../data/repositories.js';
|
|
||||||
import { Class } from '../entities/classes/class.entity.js';
|
import { Class } from '../entities/classes/class.entity.js';
|
||||||
import { ClassDTO, mapToClassDTO } from '../interfaces/class.js';
|
import { ClassDTO, mapToClassDTO } from '../interfaces/class.js';
|
||||||
import { mapToStudentDTO, StudentDTO } from '../interfaces/student.js';
|
import { mapToStudentDTO, StudentDTO } from '../interfaces/student.js';
|
||||||
import {
|
import { mapToTeacherInvitationDTO, mapToTeacherInvitationDTOIds, TeacherInvitationDTO } from '../interfaces/teacher-invitation.js';
|
||||||
mapToTeacherInvitationDTO,
|
|
||||||
mapToTeacherInvitationDTOIds,
|
|
||||||
TeacherInvitationDTO,
|
|
||||||
} from '../interfaces/teacher-invitation.js';
|
|
||||||
|
|
||||||
export async function getAllClasses(
|
export async function getAllClasses(full: boolean): Promise<ClassDTO[] | string[]> {
|
||||||
full: boolean
|
|
||||||
): Promise<ClassDTO[] | string[]> {
|
|
||||||
const classRepository = getClassRepository();
|
const classRepository = getClassRepository();
|
||||||
const classes = await classRepository.find(
|
const classes = await classRepository.find({}, { populate: ['students', 'teachers'] });
|
||||||
{},
|
|
||||||
{ populate: ['students', 'teachers'] }
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!classes) {
|
if (!classes) {
|
||||||
return [];
|
return [];
|
||||||
|
@ -35,13 +21,11 @@ export async function getAllClasses(
|
||||||
export async function createClass(classData: ClassDTO): Promise<Class | null> {
|
export async function createClass(classData: ClassDTO): Promise<Class | null> {
|
||||||
const teacherRepository = getTeacherRepository();
|
const teacherRepository = getTeacherRepository();
|
||||||
const teacherUsernames = classData.teachers || [];
|
const teacherUsernames = classData.teachers || [];
|
||||||
const teachers = (await Promise.all(teacherUsernames.map(id => teacherRepository.findByUsername(id))))
|
const teachers = (await Promise.all(teacherUsernames.map((id) => teacherRepository.findByUsername(id)))).filter((teacher) => teacher != null);
|
||||||
.filter(teacher => teacher != null);
|
|
||||||
|
|
||||||
const studentRepository = getStudentRepository();
|
const studentRepository = getStudentRepository();
|
||||||
const studentUsernames = classData.students || [];
|
const studentUsernames = classData.students || [];
|
||||||
const students = (await Promise.all(studentUsernames.map(id => studentRepository.findByUsername(id))))
|
const students = (await Promise.all(studentUsernames.map((id) => studentRepository.findByUsername(id)))).filter((student) => student != null);
|
||||||
.filter(student => student != null);
|
|
||||||
|
|
||||||
//Const cls = mapToClass(classData, teachers, students);
|
//Const cls = mapToClass(classData, teachers, students);
|
||||||
|
|
||||||
|
@ -56,7 +40,7 @@ export async function createClass(classData: ClassDTO): Promise<Class | null> {
|
||||||
await classRepository.save(newClass);
|
await classRepository.save(newClass);
|
||||||
|
|
||||||
return newClass;
|
return newClass;
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,10 +76,7 @@ export async function getClassStudentsIds(classId: string): Promise<string[]> {
|
||||||
return students.map((student) => student.username);
|
return students.map((student) => student.username);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getClassTeacherInvitations(
|
export async function getClassTeacherInvitations(classId: string, full: boolean): Promise<TeacherInvitationDTO[]> {
|
||||||
classId: string,
|
|
||||||
full: boolean
|
|
||||||
): Promise<TeacherInvitationDTO[]> {
|
|
||||||
const classRepository = getClassRepository();
|
const classRepository = getClassRepository();
|
||||||
const cls = await classRepository.findById(classId);
|
const cls = await classRepository.findById(classId);
|
||||||
|
|
||||||
|
@ -104,8 +85,7 @@ export async function getClassTeacherInvitations(
|
||||||
}
|
}
|
||||||
|
|
||||||
const teacherInvitationRepository = getTeacherInvitationRepository();
|
const teacherInvitationRepository = getTeacherInvitationRepository();
|
||||||
const invitations =
|
const invitations = await teacherInvitationRepository.findAllInvitationsForClass(cls);
|
||||||
await teacherInvitationRepository.findAllInvitationsForClass(cls);
|
|
||||||
|
|
||||||
if (full) {
|
if (full) {
|
||||||
return invitations.map(mapToTeacherInvitationDTO);
|
return invitations.map(mapToTeacherInvitationDTO);
|
||||||
|
|
|
@ -7,19 +7,10 @@ import {
|
||||||
getSubmissionRepository,
|
getSubmissionRepository,
|
||||||
} from '../data/repositories.js';
|
} from '../data/repositories.js';
|
||||||
import { Group } from '../entities/assignments/group.entity.js';
|
import { Group } from '../entities/assignments/group.entity.js';
|
||||||
import {
|
import { GroupDTO, mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js';
|
||||||
GroupDTO,
|
|
||||||
mapToGroupDTO,
|
|
||||||
mapToGroupDTOId,
|
|
||||||
} from '../interfaces/group.js';
|
|
||||||
import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js';
|
import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js';
|
||||||
|
|
||||||
export async function getGroup(
|
export async function getGroup(classId: string, assignmentNumber: number, groupNumber: number, full: boolean): Promise<GroupDTO | null> {
|
||||||
classId: string,
|
|
||||||
assignmentNumber: number,
|
|
||||||
groupNumber: number,
|
|
||||||
full: boolean
|
|
||||||
): Promise<GroupDTO | null> {
|
|
||||||
const classRepository = getClassRepository();
|
const classRepository = getClassRepository();
|
||||||
const cls = await classRepository.findById(classId);
|
const cls = await classRepository.findById(classId);
|
||||||
|
|
||||||
|
@ -28,20 +19,14 @@ export async function getGroup(
|
||||||
}
|
}
|
||||||
|
|
||||||
const assignmentRepository = getAssignmentRepository();
|
const assignmentRepository = getAssignmentRepository();
|
||||||
const assignment = await assignmentRepository.findByClassAndId(
|
const assignment = await assignmentRepository.findByClassAndId(cls, assignmentNumber);
|
||||||
cls,
|
|
||||||
assignmentNumber
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!assignment) {
|
if (!assignment) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const groupRepository = getGroupRepository();
|
const groupRepository = getGroupRepository();
|
||||||
const group = await groupRepository.findByAssignmentAndGroupNumber(
|
const group = await groupRepository.findByAssignmentAndGroupNumber(assignment, groupNumber);
|
||||||
assignment,
|
|
||||||
groupNumber
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!group) {
|
if (!group) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -54,16 +39,11 @@ export async function getGroup(
|
||||||
return mapToGroupDTOId(group);
|
return mapToGroupDTOId(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createGroup(
|
export async function createGroup(groupData: GroupDTO, classid: string, assignmentNumber: number): Promise<Group | null> {
|
||||||
groupData: GroupDTO,
|
|
||||||
classid: string,
|
|
||||||
assignmentNumber: number,
|
|
||||||
): Promise<Group | null> {
|
|
||||||
const studentRepository = getStudentRepository();
|
const studentRepository = getStudentRepository();
|
||||||
|
|
||||||
const memberUsernames = groupData.members as string[] || []; // TODO check if groupdata.members is a list
|
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))))
|
const members = (await Promise.all([...memberUsernames].map((id) => studentRepository.findByUsername(id)))).filter((student) => student != null);
|
||||||
.filter(student => student != null);
|
|
||||||
|
|
||||||
console.log(members);
|
console.log(members);
|
||||||
|
|
||||||
|
@ -90,17 +70,13 @@ export async function createGroup(
|
||||||
await groupRepository.save(newGroup);
|
await groupRepository.save(newGroup);
|
||||||
|
|
||||||
return newGroup;
|
return newGroup;
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAllGroups(
|
export async function getAllGroups(classId: string, assignmentNumber: number, full: boolean): Promise<GroupDTO[]> {
|
||||||
classId: string,
|
|
||||||
assignmentNumber: number,
|
|
||||||
full: boolean
|
|
||||||
): Promise<GroupDTO[]> {
|
|
||||||
const classRepository = getClassRepository();
|
const classRepository = getClassRepository();
|
||||||
const cls = await classRepository.findById(classId);
|
const cls = await classRepository.findById(classId);
|
||||||
|
|
||||||
|
@ -109,10 +85,7 @@ export async function getAllGroups(
|
||||||
}
|
}
|
||||||
|
|
||||||
const assignmentRepository = getAssignmentRepository();
|
const assignmentRepository = getAssignmentRepository();
|
||||||
const assignment = await assignmentRepository.findByClassAndId(
|
const assignment = await assignmentRepository.findByClassAndId(cls, assignmentNumber);
|
||||||
cls,
|
|
||||||
assignmentNumber
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!assignment) {
|
if (!assignment) {
|
||||||
return [];
|
return [];
|
||||||
|
@ -130,11 +103,7 @@ export async function getAllGroups(
|
||||||
return groups.map(mapToGroupDTOId);
|
return groups.map(mapToGroupDTOId);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getGroupSubmissions(
|
export async function getGroupSubmissions(classId: string, assignmentNumber: number, groupNumber: number): Promise<SubmissionDTO[]> {
|
||||||
classId: string,
|
|
||||||
assignmentNumber: number,
|
|
||||||
groupNumber: number,
|
|
||||||
): Promise<SubmissionDTO[]> {
|
|
||||||
const classRepository = getClassRepository();
|
const classRepository = getClassRepository();
|
||||||
const cls = await classRepository.findById(classId);
|
const cls = await classRepository.findById(classId);
|
||||||
|
|
||||||
|
@ -143,20 +112,14 @@ export async function getGroupSubmissions(
|
||||||
}
|
}
|
||||||
|
|
||||||
const assignmentRepository = getAssignmentRepository();
|
const assignmentRepository = getAssignmentRepository();
|
||||||
const assignment = await assignmentRepository.findByClassAndId(
|
const assignment = await assignmentRepository.findByClassAndId(cls, assignmentNumber);
|
||||||
cls,
|
|
||||||
assignmentNumber
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!assignment) {
|
if (!assignment) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const groupRepository = getGroupRepository();
|
const groupRepository = getGroupRepository();
|
||||||
const group = await groupRepository.findByAssignmentAndGroupNumber(
|
const group = await groupRepository.findByAssignmentAndGroupNumber(assignment, groupNumber);
|
||||||
assignment,
|
|
||||||
groupNumber
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!group) {
|
if (!group) {
|
||||||
return [];
|
return [];
|
||||||
|
|
|
@ -1,16 +1,8 @@
|
||||||
import { DWENGO_API_BASE } from '../config.js';
|
import { DWENGO_API_BASE } from '../config.js';
|
||||||
import { fetchWithLogging } from '../util/api-helper.js';
|
import { fetchWithLogging } from '../util/api-helper.js';
|
||||||
import {
|
import { FilteredLearningObject, LearningObjectMetadata, LearningObjectNode, LearningPathResponse } from '../interfaces/learning-content.js';
|
||||||
FilteredLearningObject,
|
|
||||||
LearningObjectMetadata,
|
|
||||||
LearningObjectNode,
|
|
||||||
LearningPathResponse,
|
|
||||||
} from '../interfaces/learning-content.js';
|
|
||||||
|
|
||||||
function filterData(
|
function filterData(data: LearningObjectMetadata, htmlUrl: string): FilteredLearningObject {
|
||||||
data: LearningObjectMetadata,
|
|
||||||
htmlUrl: string
|
|
||||||
): FilteredLearningObject {
|
|
||||||
return {
|
return {
|
||||||
key: data.hruid, // Hruid learningObject (not path)
|
key: data.hruid, // Hruid learningObject (not path)
|
||||||
_id: data._id,
|
_id: data._id,
|
||||||
|
@ -37,10 +29,7 @@ function filterData(
|
||||||
/**
|
/**
|
||||||
* Fetches a single learning object by its HRUID
|
* Fetches a single learning object by its HRUID
|
||||||
*/
|
*/
|
||||||
export async function getLearningObjectById(
|
export async function getLearningObjectById(hruid: string, language: string): Promise<FilteredLearningObject | null> {
|
||||||
hruid: string,
|
|
||||||
language: string
|
|
||||||
): Promise<FilteredLearningObject | null> {
|
|
||||||
const metadataUrl = `${DWENGO_API_BASE}/learningObject/getMetadata?hruid=${hruid}&language=${language}`;
|
const metadataUrl = `${DWENGO_API_BASE}/learningObject/getMetadata?hruid=${hruid}&language=${language}`;
|
||||||
const metadata = await fetchWithLogging<LearningObjectMetadata>(
|
const metadata = await fetchWithLogging<LearningObjectMetadata>(
|
||||||
metadataUrl,
|
metadataUrl,
|
||||||
|
@ -59,26 +48,12 @@ export async function getLearningObjectById(
|
||||||
/**
|
/**
|
||||||
* Generic function to fetch learning objects (full data or just HRUIDs)
|
* Generic function to fetch learning objects (full data or just HRUIDs)
|
||||||
*/
|
*/
|
||||||
async function fetchLearningObjects(
|
async function fetchLearningObjects(hruid: string, full: boolean, language: string): Promise<FilteredLearningObject[] | string[]> {
|
||||||
hruid: string,
|
|
||||||
full: boolean,
|
|
||||||
language: string
|
|
||||||
): Promise<FilteredLearningObject[] | string[]> {
|
|
||||||
try {
|
try {
|
||||||
const learningPathResponse: LearningPathResponse =
|
const learningPathResponse: LearningPathResponse = await fetchLearningPaths([hruid], language, `Learning path for HRUID "${hruid}"`);
|
||||||
await fetchLearningPaths(
|
|
||||||
[hruid],
|
|
||||||
language,
|
|
||||||
`Learning path for HRUID "${hruid}"`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (
|
if (!learningPathResponse.success || !learningPathResponse.data?.length) {
|
||||||
!learningPathResponse.success ||
|
console.error(`⚠️ WARNING: Learning path "${hruid}" exists but contains no learning objects.`);
|
||||||
!learningPathResponse.data?.length
|
|
||||||
) {
|
|
||||||
console.error(
|
|
||||||
`⚠️ WARNING: Learning path "${hruid}" exists but contains no learning objects.`
|
|
||||||
);
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,12 +63,9 @@ async function fetchLearningObjects(
|
||||||
return nodes.map((node) => node.learningobject_hruid);
|
return nodes.map((node) => node.learningobject_hruid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await Promise.all(
|
return await Promise.all(nodes.map(async (node) => getLearningObjectById(node.learningobject_hruid, language))).then((objects) =>
|
||||||
nodes.map(async (node) => getLearningObjectById(
|
objects.filter((obj): obj is FilteredLearningObject => obj !== null)
|
||||||
node.learningobject_hruid,
|
);
|
||||||
language
|
|
||||||
))
|
|
||||||
).then((objects) => objects.filter((obj): obj is FilteredLearningObject => obj !== null));
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('❌ Error fetching learning objects:', error);
|
console.error('❌ Error fetching learning objects:', error);
|
||||||
return [];
|
return [];
|
||||||
|
@ -103,27 +75,16 @@ async function fetchLearningObjects(
|
||||||
/**
|
/**
|
||||||
* Fetch full learning object data (metadata)
|
* Fetch full learning object data (metadata)
|
||||||
*/
|
*/
|
||||||
export async function getLearningObjectsFromPath(
|
export async function getLearningObjectsFromPath(hruid: string, language: string): Promise<FilteredLearningObject[]> {
|
||||||
hruid: string,
|
return (await fetchLearningObjects(hruid, true, language)) as FilteredLearningObject[];
|
||||||
language: string
|
|
||||||
): Promise<FilteredLearningObject[]> {
|
|
||||||
return (await fetchLearningObjects(
|
|
||||||
hruid,
|
|
||||||
true,
|
|
||||||
language
|
|
||||||
)) as FilteredLearningObject[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch only learning object HRUIDs
|
* Fetch only learning object HRUIDs
|
||||||
*/
|
*/
|
||||||
export async function getLearningObjectIdsFromPath(
|
export async function getLearningObjectIdsFromPath(hruid: string, language: string): Promise<string[]> {
|
||||||
hruid: string,
|
|
||||||
language: string
|
|
||||||
): Promise<string[]> {
|
|
||||||
return (await fetchLearningObjects(hruid, false, language)) as string[];
|
return (await fetchLearningObjects(hruid, false, language)) as string[];
|
||||||
}
|
}
|
||||||
function fetchLearningPaths(arg0: string[], language: string, arg2: string): LearningPathResponse | PromiseLike<LearningPathResponse> {
|
function fetchLearningPaths(arg0: string[], language: string, arg2: string): LearningPathResponse | PromiseLike<LearningPathResponse> {
|
||||||
throw new Error('Function not implemented.');
|
throw new Error('Function not implemented.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
import {getAnswerRepository, getQuestionRepository} from "../data/repositories.js";
|
import { getAnswerRepository, getQuestionRepository } from '../data/repositories.js';
|
||||||
import {mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId} from "../interfaces/question.js";
|
import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js';
|
||||||
import {Question} from "../entities/questions/question.entity.js";
|
import { Question } from '../entities/questions/question.entity.js';
|
||||||
import {Answer} from "../entities/questions/answer.entity.js";
|
import { Answer } from '../entities/questions/answer.entity.js';
|
||||||
import {mapToAnswerDTO, mapToAnswerId} from "../interfaces/answer.js";
|
import { mapToAnswerDTO, mapToAnswerId } from '../interfaces/answer.js';
|
||||||
import {QuestionRepository} from "../data/questions/question-repository.js";
|
import { QuestionRepository } from '../data/questions/question-repository.js';
|
||||||
import {LearningObjectIdentifier} from "../entities/content/learning-object-identifier.js";
|
import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js';
|
||||||
import {mapToUser} from "../interfaces/user.js";
|
import { mapToUser } from '../interfaces/user.js';
|
||||||
import {Student} from "../entities/users/student.entity.js";
|
import { Student } from '../entities/users/student.entity.js';
|
||||||
import { mapToStudent } from "../interfaces/student.js";
|
import { mapToStudent } from '../interfaces/student.js';
|
||||||
|
|
||||||
export async function getAllQuestions(
|
export async function getAllQuestions(id: LearningObjectIdentifier, full: boolean): Promise<QuestionDTO[] | QuestionId[]> {
|
||||||
id: LearningObjectIdentifier, full: boolean
|
|
||||||
): Promise<QuestionDTO[] | QuestionId[]> {
|
|
||||||
const questionRepository: QuestionRepository = getQuestionRepository();
|
const questionRepository: QuestionRepository = getQuestionRepository();
|
||||||
const questions = await questionRepository.findAllQuestionsAboutLearningObject(id);
|
const questions = await questionRepository.findAllQuestionsAboutLearningObject(id);
|
||||||
|
|
||||||
|
@ -19,7 +17,7 @@ export async function getAllQuestions(
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const questionsDTO: QuestionDTO[] = questions.map(mapToQuestionDTO);
|
const questionsDTO: QuestionDTO[] = questions.map(mapToQuestionDTO);
|
||||||
|
|
||||||
if (full) {
|
if (full) {
|
||||||
return questionsDTO;
|
return questionsDTO;
|
||||||
|
@ -31,21 +29,20 @@ export async function getAllQuestions(
|
||||||
async function fetchQuestion(questionId: QuestionId): Promise<Question | null> {
|
async function fetchQuestion(questionId: QuestionId): Promise<Question | null> {
|
||||||
const questionRepository = getQuestionRepository();
|
const questionRepository = getQuestionRepository();
|
||||||
|
|
||||||
return await questionRepository.findOne(
|
return await questionRepository.findOne({
|
||||||
{
|
learningObjectHruid: questionId.learningObjectIdentifier.hruid,
|
||||||
learningObjectHruid: questionId.learningObjectIdentifier.hruid,
|
learningObjectLanguage: questionId.learningObjectIdentifier.language,
|
||||||
learningObjectLanguage: questionId.learningObjectIdentifier.language,
|
learningObjectVersion: questionId.learningObjectIdentifier.version,
|
||||||
learningObjectVersion: questionId.learningObjectIdentifier.version,
|
sequenceNumber: questionId.sequenceNumber,
|
||||||
sequenceNumber: questionId.sequenceNumber
|
});
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getQuestion(questionId: QuestionId): Promise<QuestionDTO | null> {
|
export async function getQuestion(questionId: QuestionId): Promise<QuestionDTO | null> {
|
||||||
const question = await fetchQuestion(questionId);
|
const question = await fetchQuestion(questionId);
|
||||||
|
|
||||||
if (!question)
|
if (!question) {
|
||||||
{return null}
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return mapToQuestionDTO(question);
|
return mapToQuestionDTO(question);
|
||||||
}
|
}
|
||||||
|
@ -54,18 +51,21 @@ export async function getAnswersByQuestion(questionId: QuestionId, full: boolean
|
||||||
const answerRepository = getAnswerRepository();
|
const answerRepository = getAnswerRepository();
|
||||||
const question = await fetchQuestion(questionId);
|
const question = await fetchQuestion(questionId);
|
||||||
|
|
||||||
if (!question)
|
if (!question) {
|
||||||
{return [];}
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
const answers: Answer[] = await answerRepository.findAllAnswersToQuestion(question);
|
const answers: Answer[] = await answerRepository.findAllAnswersToQuestion(question);
|
||||||
|
|
||||||
if (!answers)
|
if (!answers) {
|
||||||
{return []}
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
const answersDTO = answers.map(mapToAnswerDTO);
|
const answersDTO = answers.map(mapToAnswerDTO);
|
||||||
|
|
||||||
if (full)
|
if (full) {
|
||||||
{return answersDTO}
|
return answersDTO;
|
||||||
|
}
|
||||||
|
|
||||||
return answersDTO.map(mapToAnswerId);
|
return answersDTO.map(mapToAnswerId);
|
||||||
}
|
}
|
||||||
|
@ -79,10 +79,10 @@ export async function createQuestion(questionDTO: QuestionDTO) {
|
||||||
await questionRepository.createQuestion({
|
await questionRepository.createQuestion({
|
||||||
loId: questionDTO.learningObjectIdentifier,
|
loId: questionDTO.learningObjectIdentifier,
|
||||||
author,
|
author,
|
||||||
content: questionDTO.content }
|
content: questionDTO.content,
|
||||||
);
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return null
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return questionDTO;
|
return questionDTO;
|
||||||
|
@ -93,18 +93,15 @@ export async function deleteQuestion(questionId: QuestionId) {
|
||||||
|
|
||||||
const question = await fetchQuestion(questionId);
|
const question = await fetchQuestion(questionId);
|
||||||
|
|
||||||
if (!question)
|
if (!question) {
|
||||||
{return null}
|
return null;
|
||||||
|
|
||||||
try {
|
|
||||||
await questionRepository.removeQuestionByLearningObjectAndSequenceNumber(
|
|
||||||
questionId.learningObjectIdentifier, questionId.sequenceNumber
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return question
|
try {
|
||||||
|
await questionRepository.removeQuestionByLearningObjectAndSequenceNumber(questionId.learningObjectIdentifier, questionId.sequenceNumber);
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return question;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
import {
|
import { getClassRepository, getGroupRepository, getStudentRepository, getSubmissionRepository } from '../data/repositories.js';
|
||||||
getClassRepository,
|
|
||||||
getGroupRepository,
|
|
||||||
getStudentRepository,
|
|
||||||
getSubmissionRepository,
|
|
||||||
} from '../data/repositories.js';
|
|
||||||
import { Class } from '../entities/classes/class.entity.js';
|
import { Class } from '../entities/classes/class.entity.js';
|
||||||
import { Student } from '../entities/users/student.entity.js';
|
import { Student } from '../entities/users/student.entity.js';
|
||||||
import { AssignmentDTO } from '../interfaces/assignment.js';
|
import { AssignmentDTO } from '../interfaces/assignment.js';
|
||||||
|
@ -14,7 +9,6 @@ import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js';
|
||||||
import { getAllAssignments } from './assignments.js';
|
import { getAllAssignments } from './assignments.js';
|
||||||
import { UserService } from './users.js';
|
import { UserService } from './users.js';
|
||||||
|
|
||||||
|
|
||||||
export async function getAllStudents(): Promise<StudentDTO[]> {
|
export async function getAllStudents(): Promise<StudentDTO[]> {
|
||||||
const studentRepository = getStudentRepository();
|
const studentRepository = getStudentRepository();
|
||||||
const users = await studentRepository.findAll();
|
const users = await studentRepository.findAll();
|
||||||
|
@ -38,9 +32,9 @@ export async function createStudent(userData: StudentDTO): Promise<StudentDTO |
|
||||||
try {
|
try {
|
||||||
const newStudent = studentRepository.create(mapToStudent(userData));
|
const newStudent = studentRepository.create(mapToStudent(userData));
|
||||||
await studentRepository.save(newStudent);
|
await studentRepository.save(newStudent);
|
||||||
|
|
||||||
return mapToStudentDTO(newStudent);
|
return mapToStudentDTO(newStudent);
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -57,9 +51,9 @@ export async function deleteStudent(username: string): Promise<StudentDTO | null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await studentRepository.deleteByUsername(username);
|
await studentRepository.deleteByUsername(username);
|
||||||
|
|
||||||
return mapToStudentDTO(user);
|
return mapToStudentDTO(user);
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -94,11 +88,7 @@ export async function getStudentAssignments(username: string, full: boolean): Pr
|
||||||
const classRepository = getClassRepository();
|
const classRepository = getClassRepository();
|
||||||
const classes = await classRepository.findByStudent(student);
|
const classes = await classRepository.findByStudent(student);
|
||||||
|
|
||||||
const assignments = (
|
const assignments = (await Promise.all(classes.map(async (cls) => await getAllAssignments(cls.classId!, full)))).flat();
|
||||||
await Promise.all(
|
|
||||||
classes.map(async (cls) => await getAllAssignments(cls.classId!, full))
|
|
||||||
)
|
|
||||||
).flat();
|
|
||||||
|
|
||||||
return assignments;
|
return assignments;
|
||||||
}
|
}
|
||||||
|
@ -121,9 +111,7 @@ export async function getStudentGroups(username: string, full: boolean): Promise
|
||||||
return groups.map(mapToGroupDTOId);
|
return groups.map(mapToGroupDTOId);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getStudentSubmissions(
|
export async function getStudentSubmissions(username: string): Promise<SubmissionDTO[]> {
|
||||||
username: string
|
|
||||||
): Promise<SubmissionDTO[]> {
|
|
||||||
const studentRepository = getStudentRepository();
|
const studentRepository = getStudentRepository();
|
||||||
const student = await studentRepository.findByUsername(username);
|
const student = await studentRepository.findByUsername(username);
|
||||||
|
|
||||||
|
@ -135,4 +123,4 @@ export async function getStudentSubmissions(
|
||||||
const submissions = await submissionRepository.findAllSubmissionsForStudent(student);
|
const submissions = await submissionRepository.findAllSubmissionsForStudent(student);
|
||||||
|
|
||||||
return submissions.map(mapToSubmissionDTO);
|
return submissions.map(mapToSubmissionDTO);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
import {getGroupRepository, getSubmissionRepository} from "../data/repositories.js";
|
import { getGroupRepository, getSubmissionRepository } from '../data/repositories.js';
|
||||||
import { Language } from "../entities/content/language.js";
|
import { Language } from '../entities/content/language.js';
|
||||||
import { LearningObjectIdentifier } from "../entities/content/learning-object-identifier.js";
|
import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js';
|
||||||
import {mapToSubmission, mapToSubmissionDTO, SubmissionDTO} from "../interfaces/submission.js";
|
import { mapToSubmission, mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js';
|
||||||
|
|
||||||
export async function getSubmission(
|
export async function getSubmission(
|
||||||
learningObjectHruid: string,
|
learningObjectHruid: string,
|
||||||
language: Language,
|
language: Language,
|
||||||
version: number,
|
version: number,
|
||||||
submissionNumber: number,
|
submissionNumber: number
|
||||||
): Promise<SubmissionDTO | null> {
|
): Promise<SubmissionDTO | null> {
|
||||||
const loId = new LearningObjectIdentifier(learningObjectHruid, language, version);
|
const loId = new LearningObjectIdentifier(learningObjectHruid, language, version);
|
||||||
|
|
||||||
|
@ -29,29 +29,23 @@ export async function createSubmission(submissionDTO: SubmissionDTO) {
|
||||||
const newSubmission = await submissionRepository.create(submission);
|
const newSubmission = await submissionRepository.create(submission);
|
||||||
await submissionRepository.save(newSubmission);
|
await submissionRepository.save(newSubmission);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return null
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return submission;
|
return submission;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteSubmission(
|
export async function deleteSubmission(learningObjectHruid: string, language: Language, version: number, submissionNumber: number) {
|
||||||
learningObjectHruid: string,
|
|
||||||
language: Language,
|
|
||||||
version: number,
|
|
||||||
submissionNumber: number
|
|
||||||
) {
|
|
||||||
const submissionRepository = getSubmissionRepository();
|
const submissionRepository = getSubmissionRepository();
|
||||||
|
|
||||||
const submission = getSubmission(learningObjectHruid, language, version, submissionNumber);
|
const submission = getSubmission(learningObjectHruid, language, version, submissionNumber);
|
||||||
|
|
||||||
if (!submission)
|
if (!submission) {
|
||||||
{return null}
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const loId = new LearningObjectIdentifier(learningObjectHruid, language, version);
|
const loId = new LearningObjectIdentifier(learningObjectHruid, language, version);
|
||||||
await submissionRepository.deleteSubmissionByLearningObjectAndSubmissionNumber(loId, submissionNumber);
|
await submissionRepository.deleteSubmissionByLearningObjectAndSubmissionNumber(loId, submissionNumber);
|
||||||
|
|
||||||
return submission;
|
return submission;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,7 @@ import { Teacher } from '../entities/users/teacher.entity.js';
|
||||||
import { ClassDTO, mapToClassDTO } from '../interfaces/class.js';
|
import { ClassDTO, mapToClassDTO } from '../interfaces/class.js';
|
||||||
import { getClassStudents } from './class.js';
|
import { getClassStudents } from './class.js';
|
||||||
import { StudentDTO } from '../interfaces/student.js';
|
import { StudentDTO } from '../interfaces/student.js';
|
||||||
import {
|
import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js';
|
||||||
mapToQuestionDTO,
|
|
||||||
mapToQuestionId,
|
|
||||||
QuestionDTO,
|
|
||||||
QuestionId,
|
|
||||||
} from '../interfaces/question.js';
|
|
||||||
import { UserService } from './users.js';
|
import { UserService } from './users.js';
|
||||||
import { mapToUser } from '../interfaces/user.js';
|
import { mapToUser } from '../interfaces/user.js';
|
||||||
import { mapToTeacher, mapToTeacherDTO, TeacherDTO } from '../interfaces/teacher.js';
|
import { mapToTeacher, mapToTeacherDTO, TeacherDTO } from '../interfaces/teacher.js';
|
||||||
|
@ -42,9 +37,9 @@ export async function createTeacher(userData: TeacherDTO): Promise<TeacherDTO |
|
||||||
try {
|
try {
|
||||||
const newTeacher = teacherRepository.create(mapToTeacher(userData));
|
const newTeacher = teacherRepository.create(mapToTeacher(userData));
|
||||||
await teacherRepository.save(newTeacher);
|
await teacherRepository.save(newTeacher);
|
||||||
|
|
||||||
return mapToTeacherDTO(newTeacher);
|
return mapToTeacherDTO(newTeacher);
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -61,9 +56,9 @@ export async function deleteTeacher(username: string): Promise<TeacherDTO | null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await teacherRepository.deleteByUsername(username);
|
await teacherRepository.deleteByUsername(username);
|
||||||
|
|
||||||
return mapToTeacherDTO(user);
|
return mapToTeacherDTO(user);
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -93,11 +88,7 @@ export async function getClassIdsByTeacher(username: string): Promise<string[]>
|
||||||
export async function fetchStudentsByTeacher(username: string) {
|
export async function fetchStudentsByTeacher(username: string) {
|
||||||
const classes = await getClassIdsByTeacher(username);
|
const classes = await getClassIdsByTeacher(username);
|
||||||
|
|
||||||
return (
|
return (await Promise.all(classes.map(async (id) => getClassStudents(id)))).flat();
|
||||||
await Promise.all(
|
|
||||||
classes.map(async (id) => getClassStudents(id))
|
|
||||||
)
|
|
||||||
).flat();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getStudentsByTeacher(username: string): Promise<StudentDTO[]> {
|
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
|
// Fetch all questions related to these learning objects
|
||||||
const questionRepository = getQuestionRepository();
|
const questionRepository = getQuestionRepository();
|
||||||
const questions =
|
const questions = await questionRepository.findAllByLearningObjects(learningObjects);
|
||||||
await questionRepository.findAllByLearningObjects(
|
|
||||||
learningObjects
|
|
||||||
);
|
|
||||||
|
|
||||||
return questions.map(mapToQuestionDTO);
|
return questions.map(mapToQuestionDTO);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue