fix: fixed linter errors
This commit is contained in:
		
							parent
							
								
									faa2f58145
								
							
						
					
					
						commit
						7f670030a7
					
				
					 13 changed files with 23 additions and 28 deletions
				
			
		|  | @ -1,5 +1,4 @@ | ||||||
| import {authorize} from "./auth-checks"; | import {authorize} from "./auth-checks"; | ||||||
| import {fetchAssignment} from "../../../services/assignments"; |  | ||||||
| import {fetchClass} from "../../../services/classes"; | import {fetchClass} from "../../../services/classes"; | ||||||
| import {fetchAllGroups} from "../../../services/groups"; | import {fetchAllGroups} from "../../../services/groups"; | ||||||
| import {mapToUsername} from "../../../interfaces/user"; | import {mapToUsername} from "../../../interfaces/user"; | ||||||
|  | @ -16,9 +15,9 @@ export const onlyAllowIfHasAccessToAssignment = authorize( | ||||||
|         if (auth.accountType === "teacher") { |         if (auth.accountType === "teacher") { | ||||||
|             const clazz = await fetchClass(classId); |             const clazz = await fetchClass(classId); | ||||||
|             return clazz.teachers.map(mapToUsername).includes(auth.username); |             return clazz.teachers.map(mapToUsername).includes(auth.username); | ||||||
|         } else { |         }  | ||||||
|             const groups = await fetchAllGroups(classId, assignmentId); |             const groups = await fetchAllGroups(classId, assignmentId); | ||||||
|             return groups.some(group => group.members.map((member) => member.username).includes(auth.username) ); |             return groups.some(group => group.members.map((member) => member.username).includes(auth.username) ); | ||||||
|         } |          | ||||||
|     } |     } | ||||||
| ); | ); | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| import {authorize} from "./auth-checks"; | import {authorize} from "./auth-checks"; | ||||||
| import {AuthenticationInfo} from "../authentication-info"; | import {AuthenticationInfo} from "../authentication-info"; | ||||||
| import {AuthenticatedRequest} from "../authenticated-request"; | import {AuthenticatedRequest} from "../authenticated-request"; | ||||||
| import {fetchClass, getClass} from "../../../services/classes"; | import {fetchClass} from "../../../services/classes"; | ||||||
| import {mapToUsername} from "../../../interfaces/user"; | import {mapToUsername} from "../../../interfaces/user"; | ||||||
| 
 | 
 | ||||||
| async function teaches(teacherUsername: string, classId: string): Promise<boolean> { | async function teaches(teacherUsername: string, classId: string): Promise<boolean> { | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| import {authorize} from "./auth-checks"; | import {authorize} from "./auth-checks"; | ||||||
| import {fetchClass, getClass} from "../../../services/classes"; | import {fetchClass} from "../../../services/classes"; | ||||||
| import {fetchGroup, getGroup} from "../../../services/groups"; | import {fetchGroup} from "../../../services/groups"; | ||||||
| import {mapToUsername} from "../../../interfaces/user"; | import {mapToUsername} from "../../../interfaces/user"; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  | @ -17,9 +17,9 @@ export const onlyAllowIfHasAccessToGroup = authorize( | ||||||
|         if (auth.accountType === "teacher") { |         if (auth.accountType === "teacher") { | ||||||
|             const clazz = await fetchClass(classId); |             const clazz = await fetchClass(classId); | ||||||
|             return clazz.teachers.map(mapToUsername).includes(auth.username); |             return clazz.teachers.map(mapToUsername).includes(auth.username); | ||||||
|         } else { // user is student
 |         }  // User is student
 | ||||||
|             const group = await fetchGroup(classId, assignmentId, groupId); |             const group = await fetchGroup(classId, assignmentId, groupId); | ||||||
|             return group.members.map(mapToUsername).includes(auth.username); |             return group.members.map(mapToUsername).includes(auth.username); | ||||||
|         } |          | ||||||
|     } |     } | ||||||
| ); | ); | ||||||
|  |  | ||||||
|  | @ -1,7 +1,6 @@ | ||||||
| import {authorize} from "./auth-checks"; | import {authorize} from "./auth-checks"; | ||||||
| import {AuthenticationInfo} from "../authentication-info"; | import {AuthenticationInfo} from "../authentication-info"; | ||||||
| import {AuthenticatedRequest} from "../authenticated-request"; | import {AuthenticatedRequest} from "../authenticated-request"; | ||||||
| import {fetchGroup, getGroup} from "../../../services/groups"; |  | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Only allows requests whose learning path personalization query parameters ('forGroup' / 'assignmentNo' / 'classId') |  * 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; |         const {forGroup, assignmentNo, classId} = req.params; | ||||||
|         if (auth.accountType === "student" && forGroup && assignmentNo && classId) { |         if (auth.accountType === "student" && forGroup && assignmentNo && classId) { | ||||||
|             // TODO: groupNumber? 
 |             // TODO: groupNumber? 
 | ||||||
|             // const group = await fetchGroup(Number(classId), Number(assignmentNo), )
 |             // Const group = await fetchGroup(Number(classId), Number(assignmentNo), )
 | ||||||
|             return false; |             return false; | ||||||
|         } else { |         }  | ||||||
|             return true; |             return true; | ||||||
|         } |          | ||||||
|     } |     } | ||||||
| ); | ); | ||||||
|  |  | ||||||
|  | @ -25,7 +25,7 @@ export const onlyAllowAuthorRequest = authorize( | ||||||
| 
 | 
 | ||||||
|         const question = await fetchQuestion(questionId); |         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 sequenceNumber = Number(seqAnswer) || FALLBACK_SEQ_NUM; | ||||||
|         const answer = await fetchAnswer(questionId, sequenceNumber); |         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") { |         if (auth.accountType === "teacher") { | ||||||
|             const cls = group.assignment.within; // TODO check if contains full objects
 |             const cls = group.assignment.within; // TODO check if contains full objects
 | ||||||
|             return cls.teachers.map(mapToUsername).includes(auth.username); |             return cls.teachers.map(mapToUsername).includes(auth.username); | ||||||
|         } else { // user is student
 |         }  // User is student
 | ||||||
|             return group.members.map(mapToUsername).includes(auth.username); |             return group.members.map(mapToUsername).includes(auth.username); | ||||||
|         } |          | ||||||
|     } |     } | ||||||
| ); | ); | ||||||
|  |  | ||||||
|  | @ -14,10 +14,10 @@ export const onlyAllowSender = authorize( | ||||||
| 
 | 
 | ||||||
| export const onlyAllowSenderBody = authorize( | export const onlyAllowSenderBody = authorize( | ||||||
|     (auth: AuthenticationInfo, req: AuthenticatedRequest) => |     (auth: AuthenticationInfo, req: AuthenticatedRequest) => | ||||||
|         req.body.sender === auth.username |         (req.body as { sender: string }).sender === auth.username | ||||||
| ); | ); | ||||||
| 
 | 
 | ||||||
| export const onlyAllowReceiverBody = authorize( | export const onlyAllowReceiverBody = authorize( | ||||||
|     (auth: AuthenticationInfo, req: AuthenticatedRequest) => |     (auth: AuthenticationInfo, req: AuthenticatedRequest) => | ||||||
|         req.body.receiver === auth.username |         (req.body as { receiver: string }).receiver === auth.username | ||||||
| ); | ); | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| import express from 'express'; | import express from 'express'; | ||||||
| import { createAnswerHandler, deleteAnswerHandler, getAnswerHandler, getAllAnswersHandler, updateAnswerHandler } from '../controllers/answers.js'; | 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 { | import { | ||||||
|     onlyAllowAuthor, |     onlyAllowAuthor, | ||||||
|     onlyAllowAuthorRequestAnswer, |     onlyAllowAuthorRequestAnswer, | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| import express from 'express'; | import express from 'express'; | ||||||
| import { createQuestionHandler, deleteQuestionHandler, getAllQuestionsHandler, getQuestionHandler } from '../controllers/questions.js'; | import { createQuestionHandler, deleteQuestionHandler, getAllQuestionsHandler, getQuestionHandler } from '../controllers/questions.js'; | ||||||
| import answerRoutes from './answers.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 {updateAnswerHandler} from "../controllers/answers"; | ||||||
| import { | import { | ||||||
|     onlyAllowAuthor, |     onlyAllowAuthor, | ||||||
|  |  | ||||||
|  | @ -102,7 +102,7 @@ export async function createQuestion(loId: LearningObjectIdentifier, questionDat | ||||||
|     const question = await questionRepository.createQuestion({ |     const question = await questionRepository.createQuestion({ | ||||||
|         loId, |         loId, | ||||||
|         author, |         author, | ||||||
|         inGroup: group!, |         inGroup: group, | ||||||
|         content, |         content, | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -59,7 +59,8 @@ export async function getStudent(username: string): Promise<StudentDTO> { | ||||||
|     return mapToStudentDTO(user); |     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 studentRepository = getStudentRepository(); | ||||||
| 
 | 
 | ||||||
|     const newStudent = mapToStudent(userData); |     const newStudent = mapToStudent(userData); | ||||||
|  |  | ||||||
|  | @ -58,7 +58,8 @@ export async function getTeacher(username: string): Promise<TeacherDTO> { | ||||||
|     return mapToTeacherDTO(user); |     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 teacherRepository: TeacherRepository = getTeacherRepository(); | ||||||
| 
 | 
 | ||||||
|     const newTeacher = mapToTeacher(userData); |     const newTeacher = mapToTeacher(userData); | ||||||
|  |  | ||||||
|  | @ -15,7 +15,6 @@ import { | ||||||
| import { BadRequestException } from '../../src/exceptions/bad-request-exception.js'; | import { BadRequestException } from '../../src/exceptions/bad-request-exception.js'; | ||||||
| import { EntityAlreadyExistsException } from '../../src/exceptions/entity-already-exists-exception.js'; | import { EntityAlreadyExistsException } from '../../src/exceptions/entity-already-exists-exception.js'; | ||||||
| import { getStudentRequestsHandler } from '../../src/controllers/students.js'; | import { getStudentRequestsHandler } from '../../src/controllers/students.js'; | ||||||
| import { TeacherDTO } from '@dwengo-1/common/interfaces/teacher'; |  | ||||||
| import { getClassHandler } from '../../src/controllers/classes'; | import { getClassHandler } from '../../src/controllers/classes'; | ||||||
| 
 | 
 | ||||||
| describe('Teacher controllers', () => { | describe('Teacher controllers', () => { | ||||||
|  |  | ||||||
|  | @ -29,10 +29,6 @@ const authState = reactive<AuthState>({ | ||||||
|     activeRole: authStorage.getActiveRole() ?? null, |     activeRole: authStorage.getActiveRole() ?? null, | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| async function sendHello(): Promise<void> { |  | ||||||
|     return apiClient.post("/auth/hello"); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /** | /** | ||||||
|  * Load the information about who is currently logged in from the IDP. |  * Load the information about who is currently logged in from the IDP. | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Adriaan Jacquet
						Adriaan Jacquet