style: fix linting issues met Prettier
This commit is contained in:
		
							parent
							
								
									7ddde18d6c
								
							
						
					
					
						commit
						9136ff0313
					
				
					 11 changed files with 60 additions and 78 deletions
				
			
		|  | @ -1,9 +1,9 @@ | |||
| import {Request, Response} from "express"; | ||||
| import {requireFields} from "./error-helper"; | ||||
| import {getLearningObjectId, getQuestionId} from "./questions"; | ||||
| import {createAnswer, deleteAnswer, getAnswer, getAnswersByQuestion, updateAnswer} from "../services/answers"; | ||||
| import {FALLBACK_SEQ_NUM} from "../config"; | ||||
| import {AnswerData} from "@dwengo-1/common/interfaces/answer"; | ||||
| import { Request, Response } from 'express'; | ||||
| import { requireFields } from './error-helper'; | ||||
| import { getLearningObjectId, getQuestionId } from './questions'; | ||||
| import { createAnswer, deleteAnswer, getAnswer, getAnswersByQuestion, updateAnswer } from '../services/answers'; | ||||
| import { FALLBACK_SEQ_NUM } from '../config'; | ||||
| import { AnswerData } from '@dwengo-1/common/interfaces/answer'; | ||||
| 
 | ||||
| export async function getAnswersHandler(req: Request, res: Response): Promise<void> { | ||||
|     const hruid = req.params.hruid; | ||||
|  | @ -11,7 +11,7 @@ export async function getAnswersHandler(req: Request, res: Response): Promise<vo | |||
|     const language = req.query.lang as string; | ||||
|     const seq = req.params.seq; | ||||
|     const full = req.query.full === 'true'; | ||||
|     requireFields({ hruid }) | ||||
|     requireFields({ hruid }); | ||||
| 
 | ||||
|     const learningObjectId = getLearningObjectId(hruid, version, language); | ||||
|     const questionId = getQuestionId(learningObjectId, seq); | ||||
|  | @ -21,13 +21,13 @@ export async function getAnswersHandler(req: Request, res: Response): Promise<vo | |||
|     res.json({ answers }); | ||||
| } | ||||
| 
 | ||||
| export async function getAnswerHandler(req: Request, res: Response): Promise<void>{ | ||||
| export async function getAnswerHandler(req: Request, res: Response): Promise<void> { | ||||
|     const hruid = req.params.hruid; | ||||
|     const version = req.params.version; | ||||
|     const language = req.query.lang as string; | ||||
|     const seq = req.params.seq; | ||||
|     const seqAnswer = req.params.seqAnswer; | ||||
|     requireFields({ hruid }) | ||||
|     requireFields({ hruid }); | ||||
| 
 | ||||
|     const learningObjectId = getLearningObjectId(hruid, version, language); | ||||
|     const questionId = getQuestionId(learningObjectId, seq); | ||||
|  | @ -43,7 +43,7 @@ export async function createAnswerHandler(req: Request, res: Response): Promise< | |||
|     const version = req.params.version; | ||||
|     const language = req.query.lang as string; | ||||
|     const seq = req.params.seq; | ||||
|     requireFields({ hruid }) | ||||
|     requireFields({ hruid }); | ||||
| 
 | ||||
|     const learningObjectId = getLearningObjectId(hruid, version, language); | ||||
|     const questionId = getQuestionId(learningObjectId, seq); | ||||
|  | @ -65,7 +65,7 @@ export async function deleteAnswerHandler(req: Request, res: Response): Promise< | |||
|     const language = req.query.lang as string; | ||||
|     const seq = req.params.seq; | ||||
|     const seqAnswer = req.params.seqAnswer; | ||||
|     requireFields({ hruid }) | ||||
|     requireFields({ hruid }); | ||||
| 
 | ||||
|     const learningObjectId = getLearningObjectId(hruid, version, language); | ||||
|     const questionId = getQuestionId(learningObjectId, seq); | ||||
|  | @ -76,15 +76,13 @@ export async function deleteAnswerHandler(req: Request, res: Response): Promise< | |||
|     res.json({ answer }); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| export async function updateAnswerHandler(req: Request, res: Response): Promise<void> { | ||||
|     const hruid = req.params.hruid; | ||||
|     const version = req.params.version; | ||||
|     const language = req.query.lang as string; | ||||
|     const seq = req.params.seq; | ||||
|     const seqAnswer = req.params.seqAnswer; | ||||
|     requireFields({ hruid }) | ||||
|     requireFields({ hruid }); | ||||
| 
 | ||||
|     const learningObjectId = getLearningObjectId(hruid, version, language); | ||||
|     const questionId = getQuestionId(learningObjectId, seq); | ||||
|  |  | |||
|  | @ -1,15 +1,10 @@ | |||
| import { Request, Response } from 'express'; | ||||
| import { | ||||
|     createQuestion, | ||||
|     deleteQuestion, | ||||
|     getAllQuestions, | ||||
|     getQuestion, updateQuestion | ||||
| } from '../services/questions.js'; | ||||
| import {FALLBACK_LANG, FALLBACK_SEQ_NUM, FALLBACK_VERSION_NUM} from '../config.js'; | ||||
| import { createQuestion, deleteQuestion, getAllQuestions, getQuestion, updateQuestion } from '../services/questions.js'; | ||||
| import { FALLBACK_LANG, FALLBACK_SEQ_NUM, FALLBACK_VERSION_NUM } from '../config.js'; | ||||
| import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; | ||||
| import {QuestionData, QuestionId} from '@dwengo-1/common/interfaces/question'; | ||||
| import { QuestionData, QuestionId } from '@dwengo-1/common/interfaces/question'; | ||||
| import { Language } from '@dwengo-1/common/util/language'; | ||||
| import {requireFields} from "./error-helper"; | ||||
| import { requireFields } from './error-helper'; | ||||
| 
 | ||||
| export function getLearningObjectId(hruid: string, version: string, lang: string): LearningObjectIdentifier { | ||||
|     return { | ||||
|  | @ -31,7 +26,7 @@ export async function getAllQuestionsHandler(req: Request, res: Response): Promi | |||
|     const version = req.params.version; | ||||
|     const language = req.query.lang as string; | ||||
|     const full = req.query.full === 'true'; | ||||
|     requireFields({ hruid }) | ||||
|     requireFields({ hruid }); | ||||
| 
 | ||||
|     const learningObjectId = getLearningObjectId(hruid, version, language); | ||||
| 
 | ||||
|  | @ -45,7 +40,7 @@ export async function getQuestionHandler(req: Request, res: Response): Promise<v | |||
|     const version = req.params.version; | ||||
|     const language = req.query.lang as string; | ||||
|     const seq = req.params.seq; | ||||
|     requireFields({ hruid }) | ||||
|     requireFields({ hruid }); | ||||
| 
 | ||||
|     const learningObjectId = getLearningObjectId(hruid, version, language); | ||||
|     const questionId = getQuestionId(learningObjectId, seq); | ||||
|  | @ -53,14 +48,13 @@ export async function getQuestionHandler(req: Request, res: Response): Promise<v | |||
|     const question = await getQuestion(questionId); | ||||
| 
 | ||||
|     res.json({ question }); | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| export async function createQuestionHandler(req: Request, res: Response): Promise<void> { | ||||
|     const hruid = req.params.hruid; | ||||
|     const version = req.params.version; | ||||
|     const language = req.query.lang as string; | ||||
|     requireFields({ hruid }) | ||||
|     requireFields({ hruid }); | ||||
| 
 | ||||
|     const loId = getLearningObjectId(hruid, version, language); | ||||
| 
 | ||||
|  | @ -73,7 +67,6 @@ export async function createQuestionHandler(req: Request, res: Response): Promis | |||
|     const question = await createQuestion(loId, questionData); | ||||
| 
 | ||||
|     res.json({ question }); | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| export async function deleteQuestionHandler(req: Request, res: Response): Promise<void> { | ||||
|  | @ -81,7 +74,7 @@ export async function deleteQuestionHandler(req: Request, res: Response): Promis | |||
|     const version = req.params.version; | ||||
|     const language = req.query.lang as string; | ||||
|     const seq = req.params.seq; | ||||
|     requireFields({ hruid }) | ||||
|     requireFields({ hruid }); | ||||
| 
 | ||||
|     const learningObjectId = getLearningObjectId(hruid, version, language); | ||||
|     const questionId = getQuestionId(learningObjectId, seq); | ||||
|  | @ -96,7 +89,7 @@ export async function updateQuestionHandler(req: Request, res: Response): Promis | |||
|     const version = req.params.version; | ||||
|     const language = req.query.lang as string; | ||||
|     const seq = req.params.seq; | ||||
|     requireFields({ hruid }) | ||||
|     requireFields({ hruid }); | ||||
| 
 | ||||
|     const learningObjectId = getLearningObjectId(hruid, version, language); | ||||
|     const questionId = getQuestionId(learningObjectId, seq); | ||||
|  |  | |||
|  | @ -21,7 +21,8 @@ export class AnswerRepository extends DwengoEntityRepository<Answer> { | |||
|     } | ||||
|     public async findAnswer(question: Question, sequenceNumber: number) { | ||||
|         return this.findOne({ | ||||
|             toQuestion: question, sequenceNumber | ||||
|             toQuestion: question, | ||||
|             sequenceNumber, | ||||
|         }); | ||||
|     } | ||||
|     public async removeAnswerByQuestionAndSequenceNumber(question: Question, sequenceNumber: number): Promise<void> { | ||||
|  | @ -30,7 +31,7 @@ export class AnswerRepository extends DwengoEntityRepository<Answer> { | |||
|             sequenceNumber: sequenceNumber, | ||||
|         }); | ||||
|     } | ||||
|     public async updateContent(answer: Answer, newContent: string){ | ||||
|     public async updateContent(answer: Answer, newContent: string) { | ||||
|         answer.content = newContent; | ||||
|         await this.save(answer); | ||||
|         return answer; | ||||
|  |  | |||
|  | @ -62,12 +62,12 @@ export class QuestionRepository extends DwengoEntityRepository<Question> { | |||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     public async findByLearningObjectAndSequenceNumber(loId: LearningObjectIdentifier, sequenceNumber: number){ | ||||
|     public async findByLearningObjectAndSequenceNumber(loId: LearningObjectIdentifier, sequenceNumber: number) { | ||||
|         return this.findOne({ | ||||
|             learningObjectHruid: loId.hruid, | ||||
|             learningObjectLanguage: loId.language, | ||||
|             learningObjectVersion: loId.version, | ||||
|             sequenceNumber | ||||
|             sequenceNumber, | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,7 +1,7 @@ | |||
| import {mapToQuestionDTO, mapToQuestionDTOId} from './question.js'; | ||||
| import { mapToQuestionDTO, mapToQuestionDTOId } from './question.js'; | ||||
| import { Answer } from '../entities/questions/answer.entity.js'; | ||||
| import { AnswerDTO, AnswerId } from '@dwengo-1/common/interfaces/answer'; | ||||
| import {mapToTeacherDTO} from "./teacher"; | ||||
| import { mapToTeacherDTO } from './teacher'; | ||||
| 
 | ||||
| /** | ||||
|  * Convert a Question entity to a DTO format. | ||||
|  |  | |||
|  | @ -1,10 +1,9 @@ | |||
| import { Question } from '../entities/questions/question.entity.js'; | ||||
| import { mapToStudentDTO} from './student.js'; | ||||
| import { QuestionDTO, QuestionId} from '@dwengo-1/common/interfaces/question'; | ||||
| import { mapToStudentDTO } from './student.js'; | ||||
| import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | ||||
| import { LearningObjectIdentifierDTO } from '@dwengo-1/common/interfaces/learning-content'; | ||||
| import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; | ||||
| 
 | ||||
| 
 | ||||
| function getLearningObjectIdentifier(question: Question): LearningObjectIdentifierDTO { | ||||
|     return { | ||||
|         hruid: question.learningObjectHruid, | ||||
|  | @ -17,8 +16,8 @@ export function mapToLearningObjectID(loID: LearningObjectIdentifierDTO): Learni | |||
|     return { | ||||
|         hruid: loID.hruid, | ||||
|         language: loID.language, | ||||
|         version: loID.version ?? 1 | ||||
|     } | ||||
|         version: loID.version ?? 1, | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  |  | |||
|  | @ -1,19 +1,13 @@ | |||
| import express from "express"; | ||||
| import { | ||||
|     createAnswerHandler, | ||||
|     deleteAnswerHandler, | ||||
|     getAnswerHandler, | ||||
|     getAnswersHandler, | ||||
|     updateAnswerHandler | ||||
| } from "../controllers/answers"; | ||||
| import express from 'express'; | ||||
| import { createAnswerHandler, deleteAnswerHandler, getAnswerHandler, getAnswersHandler, updateAnswerHandler } from '../controllers/answers'; | ||||
| 
 | ||||
| const router = express.Router({ mergeParams: true }); | ||||
| 
 | ||||
| router.get('/', getAnswersHandler); | ||||
| 
 | ||||
| router.post('/', createAnswerHandler) | ||||
| router.post('/', createAnswerHandler); | ||||
| 
 | ||||
| router.get('/:seqAnswer', getAnswerHandler) | ||||
| router.get('/:seqAnswer', getAnswerHandler); | ||||
| 
 | ||||
| router.delete('/:seqAnswer', deleteAnswerHandler); | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,10 +1,5 @@ | |||
| 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'; | ||||
| 
 | ||||
| const router = express.Router({ mergeParams: true }); | ||||
|  |  | |||
|  | @ -1,11 +1,11 @@ | |||
| import {getAnswerRepository} from "../data/repositories"; | ||||
| import {Answer} from "../entities/questions/answer.entity"; | ||||
| import {mapToAnswerDTO, mapToAnswerDTOId} from "../interfaces/answer"; | ||||
| import {fetchTeacher} from "./teachers"; | ||||
| import {fetchQuestion} from "./questions"; | ||||
| import {QuestionId} from "@dwengo-1/common/interfaces/question"; | ||||
| import {AnswerData, AnswerDTO, AnswerId} from "@dwengo-1/common/interfaces/answer"; | ||||
| import {NotFoundException} from "../exceptions/not-found-exception"; | ||||
| import { getAnswerRepository } from '../data/repositories'; | ||||
| import { Answer } from '../entities/questions/answer.entity'; | ||||
| import { mapToAnswerDTO, mapToAnswerDTOId } from '../interfaces/answer'; | ||||
| import { fetchTeacher } from './teachers'; | ||||
| import { fetchQuestion } from './questions'; | ||||
| import { QuestionId } from '@dwengo-1/common/interfaces/question'; | ||||
| import { AnswerData, AnswerDTO, AnswerId } from '@dwengo-1/common/interfaces/answer'; | ||||
| import { NotFoundException } from '../exceptions/not-found-exception'; | ||||
| 
 | ||||
| export async function getAnswersByQuestion(questionId: QuestionId, full: boolean): Promise<AnswerDTO[] | AnswerId[]> { | ||||
|     const answerRepository = getAnswerRepository(); | ||||
|  | @ -27,7 +27,9 @@ export async function createAnswer(questionId: QuestionId, answerData: AnswerDat | |||
|     const content = answerData.content; | ||||
| 
 | ||||
|     const answer = await answerRepository.createAnswer({ | ||||
|         toQuestion, author, content | ||||
|         toQuestion, | ||||
|         author, | ||||
|         content, | ||||
|     }); | ||||
|     return mapToAnswerDTO(answer); | ||||
| } | ||||
|  | @ -37,7 +39,7 @@ async function fetchAnswer(questionId: QuestionId, sequenceNumber: number): Prom | |||
|     const question = await fetchQuestion(questionId); | ||||
|     const answer = await answerRepository.findAnswer(question, sequenceNumber); | ||||
| 
 | ||||
|     if (!answer){ | ||||
|     if (!answer) { | ||||
|         throw new NotFoundException('Answer with questionID and sequence number not found'); | ||||
|     } | ||||
| 
 | ||||
|  | @ -59,7 +61,7 @@ export async function deleteAnswer(questionId: QuestionId, sequenceNumber: numbe | |||
|     return mapToAnswerDTO(answer); | ||||
| } | ||||
| 
 | ||||
| export async function updateAnswer(questionId: QuestionId, sequenceNumber: number, answerData: AnswerData){ | ||||
| export async function updateAnswer(questionId: QuestionId, sequenceNumber: number, answerData: AnswerData) { | ||||
|     const answerRepository = getAnswerRepository(); | ||||
|     const answer = await fetchAnswer(questionId, sequenceNumber); | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,12 +1,12 @@ | |||
| import { getQuestionRepository } from '../data/repositories.js'; | ||||
| import {mapToLearningObjectID, mapToQuestionDTO, mapToQuestionDTOId} from '../interfaces/question.js'; | ||||
| import { mapToLearningObjectID, mapToQuestionDTO, mapToQuestionDTOId } from '../interfaces/question.js'; | ||||
| import { Question } from '../entities/questions/question.entity.js'; | ||||
| import { QuestionRepository } from '../data/questions/question-repository.js'; | ||||
| import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; | ||||
| import {QuestionData, QuestionDTO, QuestionId} from '@dwengo-1/common/interfaces/question'; | ||||
| import {NotFoundException} from "../exceptions/not-found-exception"; | ||||
| import {FALLBACK_VERSION_NUM} from "../config"; | ||||
| import {fetchStudent} from "./students"; | ||||
| import { QuestionData, QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | ||||
| import { NotFoundException } from '../exceptions/not-found-exception'; | ||||
| import { FALLBACK_VERSION_NUM } from '../config'; | ||||
| import { fetchStudent } from './students'; | ||||
| 
 | ||||
| export async function getAllQuestions(id: LearningObjectIdentifier, full: boolean): Promise<QuestionDTO[] | QuestionId[]> { | ||||
|     const questionRepository: QuestionRepository = getQuestionRepository(); | ||||
|  | @ -26,7 +26,7 @@ export async function fetchQuestion(questionId: QuestionId): Promise<Question> { | |||
|         questionId.sequenceNumber | ||||
|     ); | ||||
| 
 | ||||
|     if (!question){ | ||||
|     if (!question) { | ||||
|         throw new NotFoundException('Question with loID and sequence number not found'); | ||||
|     } | ||||
| 
 | ||||
|  | @ -44,7 +44,9 @@ export async function createQuestion(loId: LearningObjectIdentifier, questionDat | |||
|     const content = questionData.content; | ||||
| 
 | ||||
|     const question = await questionRepository.createQuestion({ | ||||
|         loId, author, content | ||||
|         loId, | ||||
|         author, | ||||
|         content, | ||||
|     }); | ||||
| 
 | ||||
|     return mapToQuestionDTO(question); | ||||
|  | @ -70,5 +72,3 @@ export async function updateQuestion(questionId: QuestionId, questionData: Quest | |||
|     const newQuestion = await questionRepository.updateContent(question, questionData.content); | ||||
|     return mapToQuestionDTO(newQuestion); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| import { QuestionDTO, QuestionId } from './question'; | ||||
| import {TeacherDTO} from "./teacher"; | ||||
| import { TeacherDTO } from './teacher'; | ||||
| 
 | ||||
| export interface AnswerDTO { | ||||
|     author: TeacherDTO; | ||||
|  |  | |||
		Reference in a new issue
	
	 Lint Action
						Lint Action