style: fix linting issues met Prettier

This commit is contained in:
Lint Action 2025-03-13 17:45:32 +00:00
parent e78849f568
commit 400a955850
40 changed files with 321 additions and 700 deletions

View file

@ -9,10 +9,7 @@ interface AssignmentParams {
id: string;
}
export async function getAllAssignmentsHandler(
req: Request<AssignmentParams>,
res: Response
): Promise<void> {
export async function getAllAssignmentsHandler(req: Request<AssignmentParams>, res: Response): Promise<void> {
const classid = req.params.classid;
const full = req.query.full === 'true';
@ -23,18 +20,11 @@ export async function getAllAssignmentsHandler(
});
}
export async function createAssignmentHandler(
req: Request<AssignmentParams>,
res: Response,
): Promise<void> {
export async function createAssignmentHandler(req: Request<AssignmentParams>, res: Response): Promise<void> {
const classid = req.params.classid;
const assignmentData = req.body as AssignmentDTO;
if (!assignmentData.description
|| !assignmentData.language
|| !assignmentData.learningPath
|| !assignmentData.title
) {
if (!assignmentData.description || !assignmentData.language || !assignmentData.learningPath || !assignmentData.title) {
res.status(400).json({
error: 'Missing one or more required fields: title, description, learningPath, title',
});
@ -44,17 +34,14 @@ export async function createAssignmentHandler(
const assignment = createAssignment(classid, assignmentData);
if (!assignment) {
res.status(500).json({ error: "Could not create assignment "});
res.status(500).json({ error: 'Could not create assignment ' });
return;
}
res.status(201).json({ assignment: assignment });
}
export async function getAssignmentHandler(
req: Request<AssignmentParams>,
res: Response
): Promise<void> {
export async function getAssignmentHandler(req: Request<AssignmentParams>, res: Response): Promise<void> {
const id = +req.params.id;
const classid = req.params.classid;
@ -73,10 +60,7 @@ export async function getAssignmentHandler(
res.json(assignment);
}
export async function getAssignmentsSubmissionsHandler(
req: Request<AssignmentParams>,
res: Response,
): Promise<void> {
export async function getAssignmentsSubmissionsHandler(req: Request<AssignmentParams>, res: Response): Promise<void> {
const classid = req.params.classid;
const assignmentNumber = +req.params.id;

View file

@ -1,19 +1,9 @@
import { Request, Response } from 'express';
import {
createClass,
getAllClasses,
getClass,
getClassStudents,
getClassStudentsIds,
getClassTeacherInvitations,
} from '../services/class.js';
import { createClass, getAllClasses, getClass, getClassStudents, getClassStudentsIds, getClassTeacherInvitations } from '../services/class.js';
import { ClassDTO, mapToClass } from '../interfaces/class.js';
import { getClassRepository, getStudentRepository, getTeacherRepository } from '../data/repositories.js';
export async function getAllClassesHandler(
req: Request,
res: Response
): Promise<void> {
export async function getAllClassesHandler(req: Request, res: Response): Promise<void> {
const full = req.query.full === 'true';
const classes = await getAllClasses(full);
@ -22,10 +12,7 @@ export async function getAllClassesHandler(
});
}
export async function createClassHandler(
req: Request,
res: Response,
): Promise<void> {
export async function createClassHandler(req: Request, res: Response): Promise<void> {
const classData = req.body as ClassDTO;
if (!classData.displayName) {
@ -38,17 +25,14 @@ export async function createClassHandler(
const cls = await createClass(classData);
if (!cls) {
res.status(500).json({ error: "Something went wrong while creating class" });
return
res.status(500).json({ error: 'Something went wrong while creating class' });
return;
}
res.status(201).json({ class: cls });
}
export async function getClassHandler(
req: Request,
res: Response
): Promise<void> {
export async function getClassHandler(req: Request, res: Response): Promise<void> {
try {
const classId = req.params.id;
const cls = await getClass(classId);
@ -71,26 +55,18 @@ export async function getClassHandler(
}
}
export async function getClassStudentsHandler(
req: Request,
res: Response
): Promise<void> {
export async function getClassStudentsHandler(req: Request, res: Response): Promise<void> {
const classId = req.params.id;
const full = req.query.full === 'true';
const students = full
? await getClassStudents(classId)
: await getClassStudentsIds(classId);
const students = full ? await getClassStudents(classId) : await getClassStudentsIds(classId);
res.json({
students: students,
});
}
export async function getTeacherInvitationsHandler(
req: Request,
res: Response
): Promise<void> {
export async function getTeacherInvitationsHandler(req: Request, res: Response): Promise<void> {
const classId = req.params.id;
const full = req.query.full === 'true'; // TODO: not implemented yet

View file

@ -9,10 +9,7 @@ interface GroupParams {
groupid?: string;
}
export async function getGroupHandler(
req: Request<GroupParams>,
res: Response
): Promise<void> {
export async function getGroupHandler(req: Request<GroupParams>, res: Response): Promise<void> {
const classId = req.params.classid;
const full = req.query.full === 'true';
const assignmentId = +req.params.assignmentid;
@ -34,10 +31,7 @@ export async function getGroupHandler(
res.json(group);
}
export async function getAllGroupsHandler(
req: Request,
res: Response
): Promise<void> {
export async function getAllGroupsHandler(req: Request, res: Response): Promise<void> {
const classId = req.params.classid;
const full = req.query.full === 'true';
@ -55,10 +49,7 @@ export async function getAllGroupsHandler(
});
}
export async function createGroupHandler(
req: Request,
res: Response,
): Promise<void> {
export async function createGroupHandler(req: Request, res: Response): Promise<void> {
const classid = req.params.classid;
const assignmentId = +req.params.assignmentid;
@ -71,17 +62,14 @@ export async function createGroupHandler(
const group = createGroup(groupData, classid, assignmentId);
if (!group) {
res.status(500).json({ error: "Something went wrong while creating group" });
return
res.status(500).json({ error: 'Something went wrong while creating group' });
return;
}
res.status(201).json({ group: group });
}
export async function getGroupSubmissionsHandler(
req: Request,
res: Response,
): Promise<void> {
export async function getGroupSubmissionsHandler(req: Request, res: Response): Promise<void> {
const classId = req.params.classid;
// Const full = req.query.full === 'true';
@ -104,4 +92,4 @@ export async function getGroupSubmissionsHandler(
res.json({
submissions: submissions,
});
}
}

View file

@ -1,121 +1,119 @@
import {Request, Response} from "express";
import {
createQuestion,
deleteQuestion,
getAllQuestions,
getAnswersByQuestion,
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";
import { Request, Response } from 'express';
import { createQuestion, deleteQuestion, getAllQuestions, getAnswersByQuestion, 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 {
const { hruid, version } = req.params
const lang = req.query.lang
const { hruid, version } = req.params;
const lang = req.query.lang;
if (!hruid || !version ) {
res.status(400).json({ error: "Missing required parameters." });
if (!hruid || !version) {
res.status(400).json({ error: 'Missing required parameters.' });
return null;
}
return {
hruid,
language: lang as Language || FALLBACK_LANG,
version: +version
}
language: (lang as Language) || FALLBACK_LANG,
version: +version,
};
}
function getQuestionId(req: Request, res: Response): QuestionId | null {
const seq = req.params.seq
const learningObjectIdentifier = getObjectId(req,res);
const seq = req.params.seq;
const learningObjectIdentifier = getObjectId(req, res);
if (!learningObjectIdentifier)
{return null}
if (!learningObjectIdentifier) {
return null;
}
return {
learningObjectIdentifier,
sequenceNumber: seq ? Number(seq) : FALLBACK_SEQ_NUM
}
sequenceNumber: seq ? Number(seq) : FALLBACK_SEQ_NUM,
};
}
export async function getAllQuestionsHandler(
req: Request,
res: Response
): Promise<void> {
export async function getAllQuestionsHandler(req: Request, res: Response): Promise<void> {
const objectId = getObjectId(req, res);
const full = req.query.full === 'true';
if (!objectId)
{return}
if (!objectId) {
return;
}
const questions = await getAllQuestions(objectId, full);
if (!questions)
{res.status(404).json({ error: `Questions not found.` });}
else
{res.json(questions);}
if (!questions) {
res.status(404).json({ error: `Questions not found.` });
} else {
res.json(questions);
}
}
export async function getQuestionHandler(req: Request, res: Response): Promise<void> {
const questionId = getQuestionId(req, res);
if (!questionId)
{return}
if (!questionId) {
return;
}
const question = await getQuestion(questionId);
if (!question)
{res.status(404).json({ error: `Question not found.` });}
else
{res.json(question)}
if (!question) {
res.status(404).json({ error: `Question not found.` });
} else {
res.json(question);
}
}
export async function getQuestionAnswersHandler(req: Request, res: Response): Promise<void> {
const questionId = getQuestionId(req, res);
const full = req.query.full === 'true';
if (!questionId)
{return}
if (!questionId) {
return;
}
const answers = getAnswersByQuestion(questionId, full);
if (!answers)
{res.status(404).json({ error: `Questions not found.` });}
else
{res.json(answers)}
if (!answers) {
res.status(404).json({ error: `Questions not found.` });
} else {
res.json(answers);
}
}
export async function createQuestionHandler(req: Request, res: Response): Promise<void> {
const questionDTO = req.body as QuestionDTO;
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;
}
const question = await createQuestion(questionDTO);
if (!question)
{res.status(400).json({error: 'Could not add question'});}
else
{res.json(question)}
if (!question) {
res.status(400).json({ error: 'Could not add question' });
} else {
res.json(question);
}
}
export async function deleteQuestionHandler(req: Request, res: Response): Promise<void> {
const questionId = getQuestionId(req, res);
if (!questionId)
{return}
if (!questionId) {
return;
}
const question = await deleteQuestion(questionId);
if (!question)
{res.status(400).json({error: 'Could not find nor delete question'});}
else
{res.json(question)}
if (!question) {
res.status(400).json({ error: 'Could not find nor delete question' });
} else {
res.json(question);
}
}

View file

@ -10,9 +10,7 @@ import {
} from '../services/students.js';
import { ClassDTO } from '../interfaces/class.js';
import { getAllAssignments } from '../services/assignments.js';
import {
getUserHandler,
} from './users.js';
import { getUserHandler } from './users.js';
import { Student } from '../entities/users/student.entity.js';
import { StudentDTO } from '../interfaces/student.js';
import { getStudentRepository } from '../data/repositories.js';
@ -20,17 +18,12 @@ import { UserDTO } from '../interfaces/user.js';
// TODO: accept arguments (full, ...)
// TODO: endpoints
export async function getAllStudentsHandler(
req: Request,
res: Response,
): Promise<void> {
export async function getAllStudentsHandler(req: Request, res: Response): Promise<void> {
const full = req.query.full === 'true';
const studentRepository = getStudentRepository();
const students: StudentDTO[] | string[] = full
? await getAllStudents()
: await getAllStudents();
const students: StudentDTO[] | string[] = full ? await getAllStudents() : await getAllStudents();
if (!students) {
res.status(404).json({ error: `Student not found.` });
@ -40,11 +33,7 @@ export async function getAllStudentsHandler(
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;
if (!username) {
@ -64,10 +53,7 @@ export async function getStudentHandler(
res.status(201).json(user);
}
export async function createStudentHandler(
req: Request,
res: Response,
) {
export async function createStudentHandler(req: Request, res: Response) {
const userData = req.body as StudentDTO;
if (!userData.username || !userData.firstName || !userData.lastName) {
@ -81,10 +67,7 @@ export async function createStudentHandler(
res.status(201).json(newUser);
}
export async function deleteStudentHandler(
req: Request,
res: Response,
) {
export async function deleteStudentHandler(req: Request, res: Response) {
const username = req.params.username;
if (!username) {
@ -103,10 +86,7 @@ export async function deleteStudentHandler(
res.status(200).json(deletedUser);
}
export async function getStudentClassesHandler(
req: Request,
res: Response
): Promise<void> {
export async function getStudentClassesHandler(req: Request, res: Response): Promise<void> {
try {
const full = req.query.full === 'true';
const username = req.params.id;
@ -132,10 +112,7 @@ export async function getStudentClassesHandler(
// Might not be fully correct depending on if
// A class has an assignment, that all students
// Have this assignment.
export async function getStudentAssignmentsHandler(
req: Request,
res: Response
): Promise<void> {
export async function getStudentAssignmentsHandler(req: Request, res: Response): Promise<void> {
const full = req.query.full === 'true';
const username = req.params.id;
@ -146,24 +123,18 @@ export async function getStudentAssignmentsHandler(
});
}
export async function getStudentGroupsHandler(
req: Request,
res: Response,
): Promise<void> {
export async function getStudentGroupsHandler(req: Request, res: Response): Promise<void> {
const full = req.query.full === 'true';
const username = req.params.id;
const groups = await getStudentGroups(username, full);
res.json({
groups: groups,
});
}
export async function getStudentSubmissionsHandler(
req: Request,
res: Response,
): Promise<void> {
export async function getStudentSubmissionsHandler(req: Request, res: Response): Promise<void> {
const username = req.params.id;
const submissions = await getStudentSubmissions(username);
@ -175,4 +146,3 @@ export async function getStudentSubmissionsHandler(
function getAllStudents(): StudentDTO[] | string[] | PromiseLike<StudentDTO[] | string[]> {
throw new Error('Function not implemented.');
}

View file

@ -1,17 +1,14 @@
import { Request, Response } from "express";
import {createSubmission, deleteSubmission, getSubmission} from "../services/submissions.js";
import { Language, languageMap } from "../entities/content/language.js";
import {SubmissionDTO} from "../interfaces/submission";
import { Request, Response } from 'express';
import { createSubmission, deleteSubmission, getSubmission } from '../services/submissions.js';
import { Language, languageMap } from '../entities/content/language.js';
import { SubmissionDTO } from '../interfaces/submission';
interface SubmissionParams {
hruid: string,
hruid: string;
id: number;
}
export async function getSubmissionHandler(
req: Request<SubmissionParams>,
res: Response,
): Promise<void> {
export async function getSubmissionHandler(req: Request<SubmissionParams>, res: Response): Promise<void> {
const lohruid = req.params.hruid;
const submissionNumber = +req.params.id;
@ -33,18 +30,19 @@ export async function getSubmissionHandler(
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 submission = await createSubmission(submissionDTO);
if (!submission)
{res.status(404).json({ error: 'Submission not added' });}
else
{res.json(submission)}
if (!submission) {
res.status(404).json({ error: 'Submission not added' });
} else {
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 submissionNumber = +req.params.id;
@ -53,8 +51,9 @@ export async function deleteSubmissionHandler(req: Request, res: Response){
const submission = await deleteSubmission(hruid, lang, version, submissionNumber);
if (!submission)
{res.status(404).json({ error: 'Submission not found' });}
else
{res.json(submission)}
if (!submission) {
res.status(404).json({ error: 'Submission not found' });
} else {
res.json(submission);
}
}

View file

@ -1,5 +1,16 @@
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 { StudentDTO } from '../interfaces/student.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 { getTeacherRepository } from '../data/repositories.js';
export async function getAllTeachersHandler(
req: Request,
res: Response,
): Promise<void> {
export async function getAllTeachersHandler(req: Request, res: Response): Promise<void> {
const full = req.query.full === 'true';
const teacherRepository = getTeacherRepository();
const teachers: TeacherDTO[] | string[] = full
? await getAllTeachers()
: await getAllTeachers();
const teachers: TeacherDTO[] | string[] = full ? await getAllTeachers() : await getAllTeachers();
if (!teachers) {
res.status(404).json({ error: `Teacher not found.` });
@ -27,11 +33,7 @@ export async function getAllTeachersHandler(
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;
if (!username) {
@ -51,10 +53,7 @@ export async function getTeacherHandler(
res.status(201).json(user);
}
export async function createTeacherHandler(
req: Request,
res: Response,
) {
export async function createTeacherHandler(req: Request, res: Response) {
const userData = req.body as TeacherDTO;
if (!userData.username || !userData.firstName || !userData.lastName) {
@ -68,10 +67,7 @@ export async function createTeacherHandler(
res.status(201).json(newUser);
}
export async function deleteTeacherHandler(
req: Request,
res: Response,
) {
export async function deleteTeacherHandler(req: Request, res: Response) {
const username = req.params.username;
if (!username) {
@ -90,11 +86,7 @@ export async function deleteTeacherHandler(
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 {
const username = req.params.username as string;
const full = req.query.full === 'true';
@ -104,9 +96,7 @@ export async function getTeacherClassHandler(
return;
}
const classes: ClassDTO[] | string[] = full
? await getClassesByTeacher(username)
: await getClassIdsByTeacher(username);
const classes: ClassDTO[] | string[] = full ? await getClassesByTeacher(username) : await getClassIdsByTeacher(username);
res.status(201).json(classes);
} catch (error) {
@ -115,10 +105,7 @@ export async function getTeacherClassHandler(
}
}
export async function getTeacherStudentHandler(
req: Request,
res: Response
): Promise<void> {
export async function getTeacherStudentHandler(req: Request, res: Response): Promise<void> {
try {
const username = req.params.username as string;
const full = req.query.full === 'true';
@ -128,9 +115,7 @@ export async function getTeacherStudentHandler(
return;
}
const students: StudentDTO[] | string[] = full
? await getStudentsByTeacher(username)
: await getStudentIdsByTeacher(username);
const students: StudentDTO[] | string[] = full ? await getStudentsByTeacher(username) : await getStudentIdsByTeacher(username);
res.status(201).json(students);
} catch (error) {
@ -139,10 +124,7 @@ export async function getTeacherStudentHandler(
}
}
export async function getTeacherQuestionHandler(
req: Request,
res: Response
): Promise<void> {
export async function getTeacherQuestionHandler(req: Request, res: Response): Promise<void> {
try {
const username = req.params.username as string;
const full = req.query.full === 'true';
@ -152,9 +134,7 @@ export async function getTeacherQuestionHandler(
return;
}
const questions: QuestionDTO[] | QuestionId[] = full
? await getQuestionsByTeacher(username)
: await getQuestionIdsByTeacher(username);
const questions: QuestionDTO[] | QuestionId[] = full ? await getQuestionsByTeacher(username) : await getQuestionIdsByTeacher(username);
res.status(201).json(questions);
} catch (error) {

View file

@ -3,17 +3,11 @@ import { UserService } from '../services/users.js';
import { UserDTO } from '../interfaces/user.js';
import { User } from '../entities/users/user.entity.js';
export async function getAllUsersHandler<T extends User>(
req: Request,
res: Response,
service: UserService<T>
): Promise<void> {
export async function getAllUsersHandler<T extends User>(req: Request, res: Response, service: UserService<T>): Promise<void> {
try {
const full = req.query.full === 'true';
const users: UserDTO[] | string[] = full
? await service.getAllUsers()
: await service.getAllUserIds();
const users: UserDTO[] | string[] = full ? await service.getAllUsers() : await service.getAllUserIds();
if (!users) {
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>(
req: Request,
res: Response,
service: UserService<T>
): Promise<void> {
export async function getUserHandler<T extends User>(req: Request, res: Response, service: UserService<T>): Promise<void> {
try {
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>(
req: Request,
res: Response,
service: UserService<T>,
UserClass: new () => T
) {
export async function createUserHandler<T extends User>(req: Request, res: Response, service: UserService<T>, UserClass: new () => T) {
try {
console.log('req', req);
const userData = req.body as UserDTO;
@ -81,11 +66,7 @@ export async function createUserHandler<T extends User>(
}
}
export async function deleteUserHandler<T extends User>(
req: Request,
res: Response,
service: UserService<T>
) {
export async function deleteUserHandler<T extends User>(req: Request, res: Response, service: UserService<T>) {
try {
const username = req.params.username;