style: fix linting issues met ESLint
This commit is contained in:
parent
b5390258e3
commit
e78849f568
21 changed files with 64 additions and 116 deletions
|
@ -83,7 +83,7 @@ export async function getGroupSubmissionsHandler(
|
|||
res: Response,
|
||||
): Promise<void> {
|
||||
const classId = req.params.classid;
|
||||
// const full = req.query.full === 'true';
|
||||
// Const full = req.query.full === 'true';
|
||||
|
||||
const assignmentId = +req.params.assignmentid;
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ function getQuestionId(req: Request, res: Response): QuestionId | null {
|
|||
const learningObjectIdentifier = getObjectId(req,res);
|
||||
|
||||
if (!learningObjectIdentifier)
|
||||
return null
|
||||
{return null}
|
||||
|
||||
return {
|
||||
learningObjectIdentifier,
|
||||
|
@ -48,28 +48,28 @@ export async function getAllQuestionsHandler(
|
|||
const full = req.query.full === 'true';
|
||||
|
||||
if (!objectId)
|
||||
return
|
||||
{return}
|
||||
|
||||
const questions = await getAllQuestions(objectId, full);
|
||||
|
||||
if (!questions)
|
||||
res.status(404).json({ error: `Questions not found.` });
|
||||
{res.status(404).json({ error: `Questions not found.` });}
|
||||
else
|
||||
res.json(questions);
|
||||
{res.json(questions);}
|
||||
}
|
||||
|
||||
export async function getQuestionHandler(req: Request, res: Response): Promise<void> {
|
||||
const questionId = getQuestionId(req, res);
|
||||
|
||||
if (!questionId)
|
||||
return
|
||||
{return}
|
||||
|
||||
const question = await getQuestion(questionId);
|
||||
|
||||
if (!question)
|
||||
res.status(404).json({ error: `Question not found.` });
|
||||
{res.status(404).json({ error: `Question not found.` });}
|
||||
else
|
||||
res.json(question)
|
||||
{res.json(question)}
|
||||
}
|
||||
|
||||
export async function getQuestionAnswersHandler(req: Request, res: Response): Promise<void> {
|
||||
|
@ -77,14 +77,14 @@ export async function getQuestionAnswersHandler(req: Request, res: Response): Pr
|
|||
const full = req.query.full === 'true';
|
||||
|
||||
if (!questionId)
|
||||
return
|
||||
{return}
|
||||
|
||||
const answers = getAnswersByQuestion(questionId, full);
|
||||
|
||||
if (!answers)
|
||||
res.status(404).json({ error: `Questions not found.` });
|
||||
{res.status(404).json({ error: `Questions not found.` });}
|
||||
else
|
||||
res.json(answers)
|
||||
{res.json(answers)}
|
||||
}
|
||||
|
||||
export async function createQuestionHandler(req: Request, res: Response): Promise<void> {
|
||||
|
@ -98,23 +98,23 @@ export async function createQuestionHandler(req: Request, res: Response): Promis
|
|||
const question = await createQuestion(questionDTO);
|
||||
|
||||
if (!question)
|
||||
res.status(400).json({error: 'Could not add question'});
|
||||
{res.status(400).json({error: 'Could not add question'});}
|
||||
else
|
||||
res.json(question)
|
||||
{res.json(question)}
|
||||
}
|
||||
|
||||
export async function deleteQuestionHandler(req: Request, res: Response): Promise<void> {
|
||||
const questionId = getQuestionId(req, res);
|
||||
|
||||
if (!questionId)
|
||||
return
|
||||
{return}
|
||||
|
||||
const question = await deleteQuestion(questionId);
|
||||
|
||||
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
|
||||
res.json(question)
|
||||
{res.json(question)}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@ export async function getSubmissionHandler(
|
|||
return;
|
||||
}
|
||||
|
||||
let lang = languageMap[req.query.language as string] || Language.Dutch;
|
||||
let version = (req.query.version || 1) as number;
|
||||
const lang = languageMap[req.query.language as string] || Language.Dutch;
|
||||
const version = (req.query.version || 1) as number;
|
||||
|
||||
const submission = await getSubmission(lohruid, lang, version, submissionNumber);
|
||||
|
||||
|
@ -39,22 +39,22 @@ export async function createSubmissionHandler(req: Request, res: Response){
|
|||
const submission = await createSubmission(submissionDTO);
|
||||
|
||||
if (!submission)
|
||||
res.status(404).json({ error: 'Submission not added' });
|
||||
{res.status(404).json({ error: 'Submission not added' });}
|
||||
else
|
||||
res.json(submission)
|
||||
{res.json(submission)}
|
||||
}
|
||||
|
||||
export async function deleteSubmissionHandler(req: Request, res: Response){
|
||||
const hruid = req.params.hruid;
|
||||
const submissionNumber = +req.params.id;
|
||||
|
||||
let lang = languageMap[req.query.language as string] || Language.Dutch;
|
||||
let version = (req.query.version || 1) as number;
|
||||
const lang = languageMap[req.query.language as string] || Language.Dutch;
|
||||
const version = (req.query.version || 1) as number;
|
||||
|
||||
const submission = await deleteSubmission(hruid, lang, version, submissionNumber);
|
||||
|
||||
if (!submission)
|
||||
res.status(404).json({ error: 'Submission not found' });
|
||||
{res.status(404).json({ error: 'Submission not found' });}
|
||||
else
|
||||
res.json(submission)
|
||||
{res.json(submission)}
|
||||
}
|
||||
|
|
|
@ -50,13 +50,11 @@ export class QuestionRepository extends DwengoEntityRepository<Question> {
|
|||
public async findAllByLearningObjects(
|
||||
learningObjects: LearningObject[]
|
||||
): Promise<Question[]> {
|
||||
const objectIdentifiers = learningObjects.map((lo) => {
|
||||
return {
|
||||
const objectIdentifiers = learningObjects.map((lo) => ({
|
||||
learningObjectHruid: lo.hruid,
|
||||
learningObjectLanguage: lo.language,
|
||||
learningObjectVersion: lo.version,
|
||||
};
|
||||
});
|
||||
}));
|
||||
|
||||
return this.findAll({
|
||||
where: { $or: objectIdentifiers },
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { Student } from '../../entities/users/student.entity.js';
|
||||
import { User } from '../../entities/users/user.entity.js';
|
||||
import { DwengoEntityRepository } from '../dwengo-entity-repository.js';
|
||||
// import { UserRepository } from './user-repository.js';
|
||||
// Import { UserRepository } from './user-repository.js';
|
||||
|
||||
// export class StudentRepository extends UserRepository<Student> {}
|
||||
// Export class StudentRepository extends UserRepository<Student> {}
|
||||
|
||||
export class StudentRepository extends DwengoEntityRepository<Student> {
|
||||
public findByUsername(username: string): Promise<Student | null> {
|
||||
|
|
|
@ -13,15 +13,11 @@ import { Language } from '../content/language.js';
|
|||
import { AssignmentRepository } from '../../data/assignments/assignment-repository.js';
|
||||
|
||||
@Entity({
|
||||
repository: () => {
|
||||
return AssignmentRepository;
|
||||
},
|
||||
repository: () => AssignmentRepository,
|
||||
})
|
||||
export class Assignment {
|
||||
@ManyToOne({
|
||||
entity: () => {
|
||||
return Class;
|
||||
},
|
||||
entity: () => Class,
|
||||
primary: true,
|
||||
})
|
||||
within!: Class;
|
||||
|
@ -39,16 +35,12 @@ export class Assignment {
|
|||
learningPathHruid!: string;
|
||||
|
||||
@Enum({
|
||||
items: () => {
|
||||
return Language;
|
||||
},
|
||||
items: () => Language,
|
||||
})
|
||||
learningPathLanguage!: Language;
|
||||
|
||||
@OneToMany({
|
||||
entity: () => {
|
||||
return Group;
|
||||
},
|
||||
entity: () => Group,
|
||||
mappedBy: 'assignment',
|
||||
})
|
||||
groups!: Group[];
|
||||
|
|
|
@ -4,9 +4,7 @@ import { Student } from '../users/student.entity.js';
|
|||
import { GroupRepository } from '../../data/assignments/group-repository.js';
|
||||
|
||||
@Entity({
|
||||
repository: () => {
|
||||
return GroupRepository;
|
||||
},
|
||||
repository: () => GroupRepository,
|
||||
})
|
||||
export class Group {
|
||||
@ManyToOne({
|
||||
|
|
|
@ -4,9 +4,7 @@ import { Class } from './class.entity.js';
|
|||
import { ClassJoinRequestRepository } from '../../data/classes/class-join-request-repository.js';
|
||||
|
||||
@Entity({
|
||||
repository: () => {
|
||||
return ClassJoinRequestRepository;
|
||||
},
|
||||
repository: () => ClassJoinRequestRepository,
|
||||
})
|
||||
export class ClassJoinRequest {
|
||||
@ManyToOne({
|
||||
|
|
|
@ -11,9 +11,7 @@ import { Student } from '../users/student.entity.js';
|
|||
import { ClassRepository } from '../../data/classes/class-repository.js';
|
||||
|
||||
@Entity({
|
||||
repository: () => {
|
||||
return ClassRepository;
|
||||
},
|
||||
repository: () => ClassRepository,
|
||||
})
|
||||
export class Class {
|
||||
@PrimaryKey()
|
||||
|
|
|
@ -3,15 +3,11 @@ import { LearningObject } from './learning-object.entity.js';
|
|||
import { AttachmentRepository } from '../../data/content/attachment-repository.js';
|
||||
|
||||
@Entity({
|
||||
repository: () => {
|
||||
return AttachmentRepository;
|
||||
},
|
||||
repository: () => AttachmentRepository,
|
||||
})
|
||||
export class Attachment {
|
||||
@ManyToOne({
|
||||
entity: () => {
|
||||
return LearningObject;
|
||||
},
|
||||
entity: () => LearningObject,
|
||||
primary: true,
|
||||
})
|
||||
learningObject!: LearningObject;
|
||||
|
|
|
@ -21,12 +21,8 @@ export function mapToClassDTO(cls: Class): ClassDTO {
|
|||
return {
|
||||
id: cls.classId!,
|
||||
displayName: cls.displayName,
|
||||
teachers: cls.teachers.map((teacher) => {
|
||||
return teacher.username;
|
||||
}),
|
||||
students: cls.students.map((student) => {
|
||||
return student.username;
|
||||
}),
|
||||
teachers: cls.teachers.map((teacher) => teacher.username),
|
||||
students: cls.students.map((student) => student.username),
|
||||
joinRequests: [], // TODO
|
||||
};
|
||||
}
|
||||
|
|
|
@ -20,8 +20,6 @@ export function mapToGroupDTOId(group: Group): GroupDTO {
|
|||
return {
|
||||
assignment: group.assignment.id!,
|
||||
groupNumber: group.groupNumber!,
|
||||
members: group.members.map((member) => {
|
||||
return member.username;
|
||||
}),
|
||||
members: group.members.map((member) => member.username),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -36,10 +36,10 @@ export function mapToSubmission(submissionDTO: SubmissionDTO): Submission {
|
|||
submission.learningObjectHruid = submissionDTO.learningObjectHruid;
|
||||
submission.learningObjectLanguage = submissionDTO.learningObjectLanguage;
|
||||
submission.learningObjectVersion = submissionDTO.learningObjectVersion;
|
||||
// submission.submissionNumber = submissionDTO.submissionNumber;
|
||||
// Submission.submissionNumber = submissionDTO.submissionNumber;
|
||||
submission.submitter = mapToStudent(submissionDTO.submitter) ;
|
||||
// submission.submissionTime = submissionDTO.time;
|
||||
// submission.onBehalfOf = submissionDTO.group!;
|
||||
// Submission.submissionTime = submissionDTO.time;
|
||||
// Submission.onBehalfOf = submissionDTO.group!;
|
||||
// TODO fix group
|
||||
submission.content = submissionDTO.content;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import {
|
|||
} from "../controllers/questions.js";
|
||||
const router = express.Router({ mergeParams: true });
|
||||
|
||||
// query language
|
||||
// Query language
|
||||
|
||||
// Root endpoint used to search objects
|
||||
router.get('/', getAllQuestionsHandler);
|
||||
|
|
|
@ -29,9 +29,7 @@ export async function getAllClasses(
|
|||
if (full) {
|
||||
return classes.map(mapToClassDTO);
|
||||
}
|
||||
return classes.map((cls) => {
|
||||
return cls.classId!;
|
||||
});
|
||||
return classes.map((cls) => cls.classId!);
|
||||
}
|
||||
|
||||
export async function createClass(classData: ClassDTO): Promise<Class | null> {
|
||||
|
@ -45,7 +43,7 @@ export async function createClass(classData: ClassDTO): Promise<Class | null> {
|
|||
const students = (await Promise.all(studentUsernames.map(id => studentRepository.findByUsername(id))))
|
||||
.filter(student => student != null);
|
||||
|
||||
//const cls = mapToClass(classData, teachers, students);
|
||||
//Const cls = mapToClass(classData, teachers, students);
|
||||
|
||||
const classRepository = getClassRepository();
|
||||
|
||||
|
@ -91,9 +89,7 @@ export async function getClassStudents(classId: string): Promise<StudentDTO[]> {
|
|||
|
||||
export async function getClassStudentsIds(classId: string): Promise<string[]> {
|
||||
const students: StudentDTO[] = await fetchClassStudents(classId);
|
||||
return students.map((student) => {
|
||||
return student.username;
|
||||
});
|
||||
return students.map((student) => student.username);
|
||||
}
|
||||
|
||||
export async function getClassTeacherInvitations(
|
||||
|
|
|
@ -85,23 +85,15 @@ async function fetchLearningObjects(
|
|||
const nodes: LearningObjectNode[] = learningPathResponse.data[0].nodes;
|
||||
|
||||
if (!full) {
|
||||
return nodes.map((node) => {
|
||||
return node.learningobject_hruid;
|
||||
});
|
||||
return nodes.map((node) => node.learningobject_hruid);
|
||||
}
|
||||
|
||||
return await Promise.all(
|
||||
nodes.map(async (node) => {
|
||||
return getLearningObjectById(
|
||||
nodes.map(async (node) => getLearningObjectById(
|
||||
node.learningobject_hruid,
|
||||
language
|
||||
);
|
||||
})
|
||||
).then((objects) => {
|
||||
return objects.filter((obj): obj is FilteredLearningObject => {
|
||||
return obj !== null;
|
||||
});
|
||||
});
|
||||
))
|
||||
).then((objects) => objects.filter((obj): obj is FilteredLearningObject => obj !== null));
|
||||
} catch (error) {
|
||||
console.error('❌ Error fetching learning objects:', error);
|
||||
return [];
|
||||
|
|
|
@ -45,7 +45,7 @@ export async function getQuestion(questionId: QuestionId): Promise<QuestionDTO |
|
|||
const question = await fetchQuestion(questionId);
|
||||
|
||||
if (!question)
|
||||
return null
|
||||
{return null}
|
||||
|
||||
return mapToQuestionDTO(question);
|
||||
}
|
||||
|
@ -55,17 +55,17 @@ export async function getAnswersByQuestion(questionId: QuestionId, full: boolean
|
|||
const question = await fetchQuestion(questionId);
|
||||
|
||||
if (!question)
|
||||
return [];
|
||||
{return [];}
|
||||
|
||||
const answers: Answer[] = await answerRepository.findAllAnswersToQuestion(question);
|
||||
|
||||
if (!answers)
|
||||
return []
|
||||
{return []}
|
||||
|
||||
const answersDTO = answers.map(mapToAnswerDTO);
|
||||
|
||||
if (full)
|
||||
return answersDTO
|
||||
{return answersDTO}
|
||||
|
||||
return answersDTO.map(mapToAnswerId);
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ export async function deleteQuestion(questionId: QuestionId) {
|
|||
const question = await fetchQuestion(questionId);
|
||||
|
||||
if (!question)
|
||||
return null
|
||||
{return null}
|
||||
|
||||
try {
|
||||
await questionRepository.removeQuestionByLearningObjectAndSequenceNumber(
|
||||
|
|
|
@ -23,9 +23,7 @@ export async function getAllStudents(): Promise<StudentDTO[]> {
|
|||
|
||||
export async function getAllStudentIds(): Promise<string[]> {
|
||||
const users = await getAllStudents();
|
||||
return users.map((user) => {
|
||||
return user.username;
|
||||
});
|
||||
return users.map((user) => user.username);
|
||||
}
|
||||
|
||||
export async function getStudent(username: string): Promise<StudentDTO | null> {
|
||||
|
@ -98,9 +96,7 @@ export async function getStudentAssignments(username: string, full: boolean): Pr
|
|||
|
||||
const assignments = (
|
||||
await Promise.all(
|
||||
classes.map(async (cls) => {
|
||||
return await getAllAssignments(cls.classId!, full);
|
||||
})
|
||||
classes.map(async (cls) => await getAllAssignments(cls.classId!, full))
|
||||
)
|
||||
).flat();
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ export async function deleteSubmission(
|
|||
const submission = getSubmission(learningObjectHruid, language, version, submissionNumber);
|
||||
|
||||
if (!submission)
|
||||
return null
|
||||
{return null}
|
||||
|
||||
const loId = new LearningObjectIdentifier(learningObjectHruid, language, version);
|
||||
await submissionRepository.deleteSubmissionByLearningObjectAndSubmissionNumber(loId, submissionNumber);
|
||||
|
|
|
@ -27,9 +27,7 @@ export async function getAllTeachers(): Promise<TeacherDTO[]> {
|
|||
|
||||
export async function getAllTeacherIds(): Promise<string[]> {
|
||||
const users = await getAllTeachers();
|
||||
return users.map((user) => {
|
||||
return user.username;
|
||||
});
|
||||
return users.map((user) => user.username);
|
||||
}
|
||||
|
||||
export async function getTeacher(username: string): Promise<TeacherDTO | null> {
|
||||
|
@ -89,9 +87,7 @@ export async function getClassesByTeacher(username: string): Promise<ClassDTO[]>
|
|||
|
||||
export async function getClassIdsByTeacher(username: string): Promise<string[]> {
|
||||
const classes = await fetchClassesByTeacher(username);
|
||||
return classes.map((cls) => {
|
||||
return cls.id;
|
||||
});
|
||||
return classes.map((cls) => cls.id);
|
||||
}
|
||||
|
||||
export async function fetchStudentsByTeacher(username: string) {
|
||||
|
@ -99,9 +95,7 @@ export async function fetchStudentsByTeacher(username: string) {
|
|||
|
||||
return (
|
||||
await Promise.all(
|
||||
classes.map(async (id) => {
|
||||
return getClassStudents(id);
|
||||
})
|
||||
classes.map(async (id) => getClassStudents(id))
|
||||
)
|
||||
).flat();
|
||||
}
|
||||
|
@ -112,9 +106,7 @@ export async function getStudentsByTeacher(username: string): Promise<StudentDTO
|
|||
|
||||
export async function getStudentIdsByTeacher(username: string): Promise<string[]> {
|
||||
const students = await fetchStudentsByTeacher(username);
|
||||
return students.map((student) => {
|
||||
return student.username;
|
||||
});
|
||||
return students.map((student) => student.username);
|
||||
}
|
||||
|
||||
export async function fetchTeacherQuestions(username: string): Promise<QuestionDTO[]> {
|
||||
|
|
|
@ -16,9 +16,7 @@ export class UserService<T extends User> {
|
|||
|
||||
async getAllUserIds(): Promise<string[]> {
|
||||
const users = await this.getAllUsers();
|
||||
return users.map((user) => {
|
||||
return user.username;
|
||||
});
|
||||
return users.map((user) => user.username);
|
||||
}
|
||||
|
||||
async getUserByUsername(username: string): Promise<UserDTO | null> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue