fix: fixed linter errors

This commit is contained in:
Adriaan Jacquet 2025-04-22 17:57:18 +02:00
parent faa2f58145
commit 7f670030a7
13 changed files with 23 additions and 28 deletions

View file

@ -1,5 +1,4 @@
import {authorize} from "./auth-checks";
import {fetchAssignment} from "../../../services/assignments";
import {fetchClass} from "../../../services/classes";
import {fetchAllGroups} from "../../../services/groups";
import {mapToUsername} from "../../../interfaces/user";
@ -16,9 +15,9 @@ export const onlyAllowIfHasAccessToAssignment = authorize(
if (auth.accountType === "teacher") {
const clazz = await fetchClass(classId);
return clazz.teachers.map(mapToUsername).includes(auth.username);
} else {
}
const groups = await fetchAllGroups(classId, assignmentId);
return groups.some(group => group.members.map((member) => member.username).includes(auth.username) );
}
}
);

View file

@ -1,7 +1,7 @@
import {authorize} from "./auth-checks";
import {AuthenticationInfo} from "../authentication-info";
import {AuthenticatedRequest} from "../authenticated-request";
import {fetchClass, getClass} from "../../../services/classes";
import {fetchClass} from "../../../services/classes";
import {mapToUsername} from "../../../interfaces/user";
async function teaches(teacherUsername: string, classId: string): Promise<boolean> {

View file

@ -1,6 +1,6 @@
import {authorize} from "./auth-checks";
import {fetchClass, getClass} from "../../../services/classes";
import {fetchGroup, getGroup} from "../../../services/groups";
import {fetchClass} from "../../../services/classes";
import {fetchGroup} from "../../../services/groups";
import {mapToUsername} from "../../../interfaces/user";
/**
@ -17,9 +17,9 @@ export const onlyAllowIfHasAccessToGroup = authorize(
if (auth.accountType === "teacher") {
const clazz = await fetchClass(classId);
return clazz.teachers.map(mapToUsername).includes(auth.username);
} else { // user is student
} // User is student
const group = await fetchGroup(classId, assignmentId, groupId);
return group.members.map(mapToUsername).includes(auth.username);
}
}
);

View file

@ -1,7 +1,6 @@
import {authorize} from "./auth-checks";
import {AuthenticationInfo} from "../authentication-info";
import {AuthenticatedRequest} from "../authenticated-request";
import {fetchGroup, getGroup} from "../../../services/groups";
/**
* Only allows requests whose learning path personalization query parameters ('forGroup' / 'assignmentNo' / 'classId')
@ -15,10 +14,10 @@ export const onlyAllowPersonalizationForOwnGroup = authorize(
const {forGroup, assignmentNo, classId} = req.params;
if (auth.accountType === "student" && forGroup && assignmentNo && classId) {
// TODO: groupNumber?
// const group = await fetchGroup(Number(classId), Number(assignmentNo), )
// Const group = await fetchGroup(Number(classId), Number(assignmentNo), )
return false;
} else {
}
return true;
}
}
);

View file

@ -25,7 +25,7 @@ export const onlyAllowAuthorRequest = authorize(
const question = await fetchQuestion(questionId);
return question.author.username == auth.username;
return question.author.username === auth.username;
}
);
@ -44,7 +44,7 @@ export const onlyAllowAuthorRequestAnswer = authorize(
const sequenceNumber = Number(seqAnswer) || FALLBACK_SEQ_NUM;
const answer = await fetchAnswer(questionId, sequenceNumber);
return answer.author.username == auth.username;
return answer.author.username === auth.username;
}
);
@ -65,8 +65,8 @@ export const onlyAllowIfHasAccessToQuestion = authorize(
if (auth.accountType === "teacher") {
const cls = group.assignment.within; // TODO check if contains full objects
return cls.teachers.map(mapToUsername).includes(auth.username);
} else { // user is student
} // User is student
return group.members.map(mapToUsername).includes(auth.username);
}
}
);

View file

@ -14,10 +14,10 @@ export const onlyAllowSender = authorize(
export const onlyAllowSenderBody = authorize(
(auth: AuthenticationInfo, req: AuthenticatedRequest) =>
req.body.sender === auth.username
(req.body as { sender: string }).sender === auth.username
);
export const onlyAllowReceiverBody = authorize(
(auth: AuthenticationInfo, req: AuthenticatedRequest) =>
req.body.receiver === auth.username
(req.body as { receiver: string }).receiver === auth.username
);

View file

@ -1,6 +1,6 @@
import express from 'express';
import { createAnswerHandler, deleteAnswerHandler, getAnswerHandler, getAllAnswersHandler, updateAnswerHandler } from '../controllers/answers.js';
import {adminOnly, authenticatedOnly, teachersOnly} from "../middleware/auth/checks/auth-checks";
import {adminOnly, teachersOnly} from "../middleware/auth/checks/auth-checks";
import {
onlyAllowAuthor,
onlyAllowAuthorRequestAnswer,

View file

@ -1,7 +1,7 @@
import express from 'express';
import { createQuestionHandler, deleteQuestionHandler, getAllQuestionsHandler, getQuestionHandler } from '../controllers/questions.js';
import answerRoutes from './answers.js';
import {adminOnly, authenticatedOnly, studentsOnly} from "../middleware/auth/checks/auth-checks";
import {adminOnly, studentsOnly} from "../middleware/auth/checks/auth-checks";
import {updateAnswerHandler} from "../controllers/answers";
import {
onlyAllowAuthor,

View file

@ -102,7 +102,7 @@ export async function createQuestion(loId: LearningObjectIdentifier, questionDat
const question = await questionRepository.createQuestion({
loId,
author,
inGroup: group!,
inGroup: group,
content,
});

View file

@ -59,7 +59,8 @@ export async function getStudent(username: string): Promise<StudentDTO> {
return mapToStudentDTO(user);
}
export async function createStudent(userData: StudentDTO, allowUpdate = false): Promise<StudentDTO> {
// TODO allowupdate parameter?
export async function createStudent(userData: StudentDTO, _allowUpdate = false): Promise<StudentDTO> {
const studentRepository = getStudentRepository();
const newStudent = mapToStudent(userData);

View file

@ -58,7 +58,8 @@ export async function getTeacher(username: string): Promise<TeacherDTO> {
return mapToTeacherDTO(user);
}
export async function createTeacher(userData: TeacherDTO, update?: boolean): Promise<TeacherDTO> {
// TODO update parameter
export async function createTeacher(userData: TeacherDTO, _update?: boolean): Promise<TeacherDTO> {
const teacherRepository: TeacherRepository = getTeacherRepository();
const newTeacher = mapToTeacher(userData);