From 9136ff031301b02bfd7ec4cfec31ed9f24001ef5 Mon Sep 17 00:00:00 2001 From: Lint Action Date: Sun, 6 Apr 2025 21:41:42 +0000 Subject: [PATCH] style: fix linting issues met Prettier --- backend/src/controllers/answers.ts | 26 +++++++++---------- backend/src/controllers/questions.ts | 25 +++++++----------- .../src/data/questions/answer-repository.ts | 5 ++-- .../src/data/questions/question-repository.ts | 4 +-- backend/src/interfaces/answer.ts | 4 +-- backend/src/interfaces/question.ts | 9 +++---- backend/src/routes/answers.ts | 14 +++------- backend/src/routes/questions.ts | 7 +---- backend/src/services/answers.ts | 24 +++++++++-------- backend/src/services/questions.ts | 18 ++++++------- common/src/interfaces/answer.ts | 2 +- 11 files changed, 60 insertions(+), 78 deletions(-) diff --git a/backend/src/controllers/answers.ts b/backend/src/controllers/answers.ts index 1bb53019..4167e746 100644 --- a/backend/src/controllers/answers.ts +++ b/backend/src/controllers/answers.ts @@ -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 { const hruid = req.params.hruid; @@ -11,7 +11,7 @@ export async function getAnswersHandler(req: Request, res: Response): Promise{ +export async function getAnswerHandler(req: Request, res: Response): Promise { 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 { 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); diff --git a/backend/src/controllers/questions.ts b/backend/src/controllers/questions.ts index e239d9ca..1158e041 100644 --- a/backend/src/controllers/questions.ts +++ b/backend/src/controllers/questions.ts @@ -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 { 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 { @@ -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); diff --git a/backend/src/data/questions/answer-repository.ts b/backend/src/data/questions/answer-repository.ts index 94798248..93af06dd 100644 --- a/backend/src/data/questions/answer-repository.ts +++ b/backend/src/data/questions/answer-repository.ts @@ -21,7 +21,8 @@ export class AnswerRepository extends DwengoEntityRepository { } public async findAnswer(question: Question, sequenceNumber: number) { return this.findOne({ - toQuestion: question, sequenceNumber + toQuestion: question, + sequenceNumber, }); } public async removeAnswerByQuestionAndSequenceNumber(question: Question, sequenceNumber: number): Promise { @@ -30,7 +31,7 @@ export class AnswerRepository extends DwengoEntityRepository { 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; diff --git a/backend/src/data/questions/question-repository.ts b/backend/src/data/questions/question-repository.ts index 31a856a6..b4e13ae9 100644 --- a/backend/src/data/questions/question-repository.ts +++ b/backend/src/data/questions/question-repository.ts @@ -62,12 +62,12 @@ export class QuestionRepository extends DwengoEntityRepository { }); } - 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, }); } diff --git a/backend/src/interfaces/answer.ts b/backend/src/interfaces/answer.ts index 87464a0b..b78c579f 100644 --- a/backend/src/interfaces/answer.ts +++ b/backend/src/interfaces/answer.ts @@ -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. diff --git a/backend/src/interfaces/question.ts b/backend/src/interfaces/question.ts index 46f61825..40642ae7 100644 --- a/backend/src/interfaces/question.ts +++ b/backend/src/interfaces/question.ts @@ -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, + }; } /** diff --git a/backend/src/routes/answers.ts b/backend/src/routes/answers.ts index edb27813..78b87061 100644 --- a/backend/src/routes/answers.ts +++ b/backend/src/routes/answers.ts @@ -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); diff --git a/backend/src/routes/questions.ts b/backend/src/routes/questions.ts index ba39435c..e3651ba3 100644 --- a/backend/src/routes/questions.ts +++ b/backend/src/routes/questions.ts @@ -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 }); diff --git a/backend/src/services/answers.ts b/backend/src/services/answers.ts index 27b9cb13..8f3d6c9f 100644 --- a/backend/src/services/answers.ts +++ b/backend/src/services/answers.ts @@ -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 { 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); diff --git a/backend/src/services/questions.ts b/backend/src/services/questions.ts index 21794ff5..5e5dd599 100644 --- a/backend/src/services/questions.ts +++ b/backend/src/services/questions.ts @@ -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 { const questionRepository: QuestionRepository = getQuestionRepository(); @@ -26,7 +26,7 @@ export async function fetchQuestion(questionId: QuestionId): Promise { 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); } - - diff --git a/common/src/interfaces/answer.ts b/common/src/interfaces/answer.ts index efba9437..8510ac7b 100644 --- a/common/src/interfaces/answer.ts +++ b/common/src/interfaces/answer.ts @@ -1,5 +1,5 @@ import { QuestionDTO, QuestionId } from './question'; -import {TeacherDTO} from "./teacher"; +import { TeacherDTO } from './teacher'; export interface AnswerDTO { author: TeacherDTO;