style: fix linting issues met Prettier
This commit is contained in:
		
							parent
							
								
									fc5a40ba40
								
							
						
					
					
						commit
						9b0c0c9889
					
				
					 11 changed files with 43 additions and 45 deletions
				
			
		|  | @ -1,18 +1,19 @@ | ||||||
| import { Request, Response } from 'express'; | import { Request, Response } from 'express'; | ||||||
| import { | import { | ||||||
|     createStudent, |     createStudent, | ||||||
|     deleteStudent, getAllStudentIds, |     deleteStudent, | ||||||
|  |     getAllStudentIds, | ||||||
|     getAllStudents, |     getAllStudents, | ||||||
|     getStudent, |     getStudent, | ||||||
|     getStudentAssignments, |     getStudentAssignments, | ||||||
|     getStudentClasses, |     getStudentClasses, | ||||||
|     getStudentGroups, getStudentQuestions, |     getStudentGroups, | ||||||
|  |     getStudentQuestions, | ||||||
|     getStudentSubmissions, |     getStudentSubmissions, | ||||||
| } from '../services/students.js'; | } from '../services/students.js'; | ||||||
| import {MISSING_FIELDS_ERROR, MISSING_USERNAME_ERROR, NAME_NOT_FOUND_ERROR} from './users.js'; | import { MISSING_FIELDS_ERROR, MISSING_USERNAME_ERROR, NAME_NOT_FOUND_ERROR } from './users.js'; | ||||||
| import { StudentDTO } from '../interfaces/student.js'; | import { StudentDTO } from '../interfaces/student.js'; | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 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 full = req.query.full === 'true'; | ||||||
| 
 | 
 | ||||||
|  | @ -23,7 +24,7 @@ export async function getAllStudentsHandler(req: Request, res: Response): Promis | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     res.json({students}); |     res.json({ students }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function getStudentHandler(req: Request, res: Response): Promise<void> { | export async function getStudentHandler(req: Request, res: Response): Promise<void> { | ||||||
|  | @ -152,5 +153,5 @@ export async function getStudentQuestionsHandler(req: Request, res: Response): P | ||||||
| 
 | 
 | ||||||
|     res.json({ |     res.json({ | ||||||
|         questions, |         questions, | ||||||
|     }) |     }); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,17 +1,10 @@ | ||||||
| import { Request, Response } from 'express'; | import { Request, Response } from 'express'; | ||||||
| import { | import { createTeacher, deleteTeacher, getAllTeachers, getClassesByTeacher, getStudentsByTeacher, getTeacher } from '../services/teachers.js'; | ||||||
|     createTeacher, |  | ||||||
|     deleteTeacher, |  | ||||||
|     getAllTeachers, |  | ||||||
|     getClassesByTeacher, |  | ||||||
|     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'; | ||||||
| import { TeacherDTO } from '../interfaces/teacher.js'; | import { TeacherDTO } from '../interfaces/teacher.js'; | ||||||
| import {MISSING_FIELDS_ERROR, MISSING_USERNAME_ERROR, NAME_NOT_FOUND_ERROR} from "./users"; | import { MISSING_FIELDS_ERROR, MISSING_USERNAME_ERROR, NAME_NOT_FOUND_ERROR } from './users'; | ||||||
| 
 | 
 | ||||||
| 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 full = req.query.full === 'true'; | ||||||
|  | @ -23,7 +16,7 @@ export async function getAllTeachersHandler(req: Request, res: Response): Promis | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     res.json({teachers}); |     res.json({ teachers }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function getTeacherHandler(req: Request, res: Response): Promise<void> { | export async function getTeacherHandler(req: Request, res: Response): Promise<void> { | ||||||
|  | @ -98,7 +91,7 @@ export async function getTeacherStudentHandler(req: Request, res: Response): Pro | ||||||
| 
 | 
 | ||||||
|     const students: StudentDTO[] | string[] = await getStudentsByTeacher(username, full); |     const students: StudentDTO[] | string[] = await getStudentsByTeacher(username, full); | ||||||
| 
 | 
 | ||||||
|     res.json({students}); |     res.json({ students }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function getTeacherQuestionHandler(req: Request, res: Response): Promise<void> { | export async function getTeacherQuestionHandler(req: Request, res: Response): Promise<void> { | ||||||
|  | @ -112,5 +105,5 @@ export async function getTeacherQuestionHandler(req: Request, res: Response): Pr | ||||||
| 
 | 
 | ||||||
|     const questions: QuestionDTO[] | QuestionId[] = await getQuestionsByTeacher(username, full); |     const questions: QuestionDTO[] | QuestionId[] = await getQuestionsByTeacher(username, full); | ||||||
| 
 | 
 | ||||||
|     res.json({questions}); |     res.json({ questions }); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| export const MISSING_USERNAME_ERROR = { error: 'Missing required field: username' }; | export const MISSING_USERNAME_ERROR = { error: 'Missing required field: username' }; | ||||||
| 
 | 
 | ||||||
| export function NAME_NOT_FOUND_ERROR(username: string){ | export function NAME_NOT_FOUND_ERROR(username: string) { | ||||||
|     return {error: `User with username '${username}' not found.`}; |     return { error: `User with username '${username}' not found.` }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export const MISSING_FIELDS_ERROR = { error: 'Missing required fields: username, firstName, lastName'} | export const MISSING_FIELDS_ERROR = { error: 'Missing required fields: username, firstName, lastName' }; | ||||||
|  |  | ||||||
|  | @ -61,5 +61,4 @@ export class QuestionRepository extends DwengoEntityRepository<Question> { | ||||||
|             orderBy: { timestamp: 'DESC' }, // New to old
 |             orderBy: { timestamp: 'DESC' }, // New to old
 | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
| 
 |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -6,7 +6,8 @@ import { | ||||||
|     getStudentAssignmentsHandler, |     getStudentAssignmentsHandler, | ||||||
|     getStudentClassesHandler, |     getStudentClassesHandler, | ||||||
|     getStudentGroupsHandler, |     getStudentGroupsHandler, | ||||||
|     getStudentHandler, getStudentQuestionsHandler, |     getStudentHandler, | ||||||
|  |     getStudentQuestionsHandler, | ||||||
|     getStudentSubmissionsHandler, |     getStudentSubmissionsHandler, | ||||||
| } from '../controllers/students.js'; | } from '../controllers/students.js'; | ||||||
| import { getStudentGroups } from '../services/students.js'; | import { getStudentGroups } from '../services/students.js'; | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ import { | ||||||
|     getGroupRepository, |     getGroupRepository, | ||||||
|     getQuestionRepository, |     getQuestionRepository, | ||||||
|     getStudentRepository, |     getStudentRepository, | ||||||
|     getSubmissionRepository |     getSubmissionRepository, | ||||||
| } from '../data/repositories.js'; | } from '../data/repositories.js'; | ||||||
| import { AssignmentDTO } from '../interfaces/assignment.js'; | import { AssignmentDTO } from '../interfaces/assignment.js'; | ||||||
| import { ClassDTO, mapToClassDTO } from '../interfaces/class.js'; | import { ClassDTO, mapToClassDTO } from '../interfaces/class.js'; | ||||||
|  | @ -11,7 +11,7 @@ import { GroupDTO, mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js | ||||||
| import { mapToStudent, mapToStudentDTO, StudentDTO } from '../interfaces/student.js'; | import { mapToStudent, mapToStudentDTO, StudentDTO } from '../interfaces/student.js'; | ||||||
| import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js'; | import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js'; | ||||||
| import { getAllAssignments } from './assignments.js'; | import { getAllAssignments } from './assignments.js'; | ||||||
| import {mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId} from "../interfaces/question"; | import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question'; | ||||||
| 
 | 
 | ||||||
| export async function getAllStudents(): Promise<StudentDTO[]> { | export async function getAllStudents(): Promise<StudentDTO[]> { | ||||||
|     const studentRepository = getStudentRepository(); |     const studentRepository = getStudentRepository(); | ||||||
|  | @ -138,8 +138,9 @@ export async function getStudentQuestions(username: string, full: boolean): Prom | ||||||
|     const questionRepository = getQuestionRepository(); |     const questionRepository = getQuestionRepository(); | ||||||
|     const questions = await questionRepository.findAllByAuthor(student); |     const questions = await questionRepository.findAllByAuthor(student); | ||||||
| 
 | 
 | ||||||
|     if (full) |     if (full) { | ||||||
|         {return questions.map(mapToQuestionDTO)} |         return questions.map(mapToQuestionDTO); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     return questions.map(mapToQuestionId); |     return questions.map(mapToQuestionId); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -14,8 +14,9 @@ export async function getAllTeachers(full: boolean): Promise<TeacherDTO[]> { | ||||||
|     const teacherRepository = getTeacherRepository(); |     const teacherRepository = getTeacherRepository(); | ||||||
|     const users = await teacherRepository.findAll(); |     const users = await teacherRepository.findAll(); | ||||||
| 
 | 
 | ||||||
|     if (full) |     if (full) { | ||||||
|         {return users.map(mapToTeacherDTO);} |         return users.map(mapToTeacherDTO); | ||||||
|  |     } | ||||||
|     return users.map((user) => user.username); |     return users.map((user) => user.username); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -73,17 +74,19 @@ async function fetchClassesByTeacher(username: string): Promise<ClassDTO[]> { | ||||||
| export async function getClassesByTeacher(username: string, full: boolean): Promise<ClassDTO[] | string[]> { | export async function getClassesByTeacher(username: string, full: boolean): Promise<ClassDTO[] | string[]> { | ||||||
|     const classes = await fetchClassesByTeacher(username); |     const classes = await fetchClassesByTeacher(username); | ||||||
| 
 | 
 | ||||||
|     if (full) |     if (full) { | ||||||
|         {return classes;} |         return classes; | ||||||
|  |     } | ||||||
|     return classes.map((cls) => cls.id); |     return classes.map((cls) => cls.id); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function getStudentsByTeacher(username: string, full: boolean) { | export async function getStudentsByTeacher(username: string, full: boolean) { | ||||||
|     const classes = await getClassesByTeacher(username, false); |     const classes = await getClassesByTeacher(username, false); | ||||||
| 
 | 
 | ||||||
|     const students =  (await Promise.all(classes.map(async (id) => getClassStudents(id)))).flat(); |     const students = (await Promise.all(classes.map(async (id) => getClassStudents(id)))).flat(); | ||||||
|     if (full) |     if (full) { | ||||||
|         {return students} |         return students; | ||||||
|  |     } | ||||||
|     return students.map((student) => student.username); |     return students.map((student) => student.username); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -102,9 +105,9 @@ export async function getTeacherQuestions(username: string, full: boolean): Prom | ||||||
|     const questionRepository = getQuestionRepository(); |     const questionRepository = getQuestionRepository(); | ||||||
|     const questions = await questionRepository.findAllByLearningObjects(learningObjects); |     const questions = await questionRepository.findAllByLearningObjects(learningObjects); | ||||||
| 
 | 
 | ||||||
|     if (full) |     if (full) { | ||||||
|         {return questions.map(mapToQuestionDTO);} |         return questions.map(mapToQuestionDTO); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     return questions.map(mapToQuestionId); |     return questions.map(mapToQuestionId); | ||||||
| } | } | ||||||
| 
 |  | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import {API_BASE} from "../../config.ts"; | import { API_BASE } from "../../config.ts"; | ||||||
| 
 | 
 | ||||||
| export class BaseController { | export class BaseController { | ||||||
|     protected baseUrl: string; |     protected baseUrl: string; | ||||||
|  | @ -12,7 +12,9 @@ export class BaseController { | ||||||
|         if (queryParams) { |         if (queryParams) { | ||||||
|             const query = new URLSearchParams(); |             const query = new URLSearchParams(); | ||||||
|             Object.entries(queryParams).forEach(([key, value]) => { |             Object.entries(queryParams).forEach(([key, value]) => { | ||||||
|                 if (value !== undefined && value !== null) {query.append(key, value.toString());} |                 if (value !== undefined && value !== null) { | ||||||
|  |                     query.append(key, value.toString()); | ||||||
|  |                 } | ||||||
|             }); |             }); | ||||||
|             url += `?${query.toString()}`; |             url += `?${query.toString()}`; | ||||||
|         } |         } | ||||||
|  | @ -68,5 +70,4 @@ export class BaseController { | ||||||
| 
 | 
 | ||||||
|         return res.json(); |         return res.json(); | ||||||
|     } |     } | ||||||
| 
 |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| import {StudentController} from "@/controllers/student-controller.ts"; | import { StudentController } from "@/controllers/student-controller.ts"; | ||||||
| import {TeacherController} from "@/controllers/teacher-controller.ts"; | import { TeacherController } from "@/controllers/teacher-controller.ts"; | ||||||
| 
 | 
 | ||||||
| export function controllerGetter<T>(Factory: new () => T): () => T { | export function controllerGetter<T>(Factory: new () => T): () => T { | ||||||
|     let instance: T | undefined; |     let instance: T | undefined; | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import {BaseController} from "@/controllers/base-controller.ts"; | import { BaseController } from "@/controllers/base-controller.ts"; | ||||||
| 
 | 
 | ||||||
| export class StudentController extends BaseController { | export class StudentController extends BaseController { | ||||||
|     constructor() { |     constructor() { | ||||||
|  | @ -40,5 +40,4 @@ export class StudentController extends BaseController { | ||||||
|     getQuestions(username: string, full = true) { |     getQuestions(username: string, full = true) { | ||||||
|         return this.get<{ questions: any[] }>(`/${username}/questions`, { full }); |         return this.get<{ questions: any[] }>(`/${username}/questions`, { full }); | ||||||
|     } |     } | ||||||
| 
 |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import {BaseController} from "@/controllers/base-controller.ts"; | import { BaseController } from "@/controllers/base-controller.ts"; | ||||||
| 
 | 
 | ||||||
| export class TeacherController extends BaseController { | export class TeacherController extends BaseController { | ||||||
|     constructor() { |     constructor() { | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Lint Action
						Lint Action