From a8895cc429914e9354836da1f522a4417aaca955 Mon Sep 17 00:00:00 2001 From: Lint Action Date: Mon, 7 Apr 2025 14:44:59 +0000 Subject: [PATCH] style: fix linting issues met Prettier --- .../src/data/questions/answer-repository.ts | 5 +- .../src/data/questions/question-repository.ts | 4 +- backend/src/routes/answers.ts | 14 ++---- backend/src/services/answers.ts | 22 +++++---- backend/src/services/questions.ts | 6 +-- backend/tests/controllers/answers.test.ts | 47 +++++++++---------- backend/tests/controllers/questions.test.ts | 46 ++++++++---------- frontend/src/controllers/answers.ts | 23 +++++---- frontend/src/controllers/base-controller.ts | 4 +- frontend/src/controllers/questions.ts | 16 +++---- frontend/src/queries/answers.ts | 20 +++----- frontend/src/queries/questions.ts | 18 +++---- 12 files changed, 104 insertions(+), 121 deletions(-) diff --git a/backend/src/data/questions/answer-repository.ts b/backend/src/data/questions/answer-repository.ts index 1b353b28..54f67a01 100644 --- a/backend/src/data/questions/answer-repository.ts +++ b/backend/src/data/questions/answer-repository.ts @@ -2,7 +2,7 @@ import { DwengoEntityRepository } from '../dwengo-entity-repository.js'; import { Answer } from '../../entities/questions/answer.entity.js'; import { Question } from '../../entities/questions/question.entity.js'; import { Teacher } from '../../entities/users/teacher.entity.js'; -import {Loaded} from "@mikro-orm/core"; +import { Loaded } from '@mikro-orm/core'; export class AnswerRepository extends DwengoEntityRepository { public async createAnswer(answer: { toQuestion: Question; author: Teacher; content: string }): Promise { @@ -22,7 +22,8 @@ export class AnswerRepository extends DwengoEntityRepository { } public async findAnswer(question: Question, sequenceNumber: number): Promise | null> { return this.findOne({ - toQuestion: question, sequenceNumber + toQuestion: question, + sequenceNumber, }); } public async removeAnswerByQuestionAndSequenceNumber(question: Question, sequenceNumber: number): Promise { diff --git a/backend/src/data/questions/question-repository.ts b/backend/src/data/questions/question-repository.ts index 27a4ac19..cf9ecab0 100644 --- a/backend/src/data/questions/question-repository.ts +++ b/backend/src/data/questions/question-repository.ts @@ -3,7 +3,7 @@ import { Question } from '../../entities/questions/question.entity.js'; import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier.js'; import { Student } from '../../entities/users/student.entity.js'; import { LearningObject } from '../../entities/content/learning-object.entity.js'; -import {Loaded} from "@mikro-orm/core"; +import { Loaded } from '@mikro-orm/core'; export class QuestionRepository extends DwengoEntityRepository { public async createQuestion(question: { loId: LearningObjectIdentifier; author: Student; content: string }): Promise { @@ -68,7 +68,7 @@ export class QuestionRepository extends DwengoEntityRepository { learningObjectHruid: loId.hruid, learningObjectLanguage: loId.language, learningObjectVersion: loId.version, - sequenceNumber + sequenceNumber, }); } diff --git a/backend/src/routes/answers.ts b/backend/src/routes/answers.ts index a6280e49..5800733a 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, - getAllAnswersHandler, - updateAnswerHandler -} from "../controllers/answers"; +import express from 'express'; +import { createAnswerHandler, deleteAnswerHandler, getAnswerHandler, getAllAnswersHandler, updateAnswerHandler } from '../controllers/answers'; const router = express.Router({ mergeParams: true }); router.get('/', getAllAnswersHandler); -router.post('/', createAnswerHandler) +router.post('/', createAnswerHandler); -router.get('/:seqAnswer', getAnswerHandler) +router.get('/:seqAnswer', getAnswerHandler); router.delete('/:seqAnswer', deleteAnswerHandler); diff --git a/backend/src/services/answers.ts b/backend/src/services/answers.ts index 4844ff79..f2abad51 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'); } diff --git a/backend/src/services/questions.ts b/backend/src/services/questions.ts index 64bf4471..d2e6440e 100644 --- a/backend/src/services/questions.ts +++ b/backend/src/services/questions.ts @@ -56,11 +56,11 @@ export async function deleteQuestion(questionId: QuestionId): Promise { let req: Partial; @@ -25,12 +25,12 @@ describe('Questions controllers', () => { it('Get answers list', async () => { req = { - params: {hruid: 'id05', version: '1', seq: '2'}, - query: {lang: Language.English, full: 'true'}, + params: { hruid: 'id05', version: '1', seq: '2' }, + query: { lang: Language.English, full: 'true' }, }; await getAllAnswersHandler(req as Request, res as Response); - expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({answers: expect.anything()})); + expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ answers: expect.anything() })); const result = jsonMock.mock.lastCall?.[0]; // Console.log(result.answers); @@ -39,12 +39,12 @@ describe('Questions controllers', () => { it('Get answer', async () => { req = { - params: {hruid: 'id05', version: '1', seq: '2', seqAnswer: '2'}, - query: {lang: Language.English, full: 'true'}, + params: { hruid: 'id05', version: '1', seq: '2', seqAnswer: '2' }, + query: { lang: Language.English, full: 'true' }, }; await getAnswerHandler(req as Request, res as Response); - expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({answer: expect.anything()})); + expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ answer: expect.anything() })); // Const result = jsonMock.mock.lastCall?.[0]; // Console.log(result.answer); @@ -52,13 +52,12 @@ describe('Questions controllers', () => { it('Get answer hruid does not exist', async () => { req = { - params: { hruid: 'id_not_exist'}, + params: { hruid: 'id_not_exist' }, query: { lang: Language.English, full: 'true' }, }; - await expect( async () => getAnswerHandler(req as Request, res as Response)) - .rejects.toThrow(NotFoundException); - }) + await expect(async () => getAnswerHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException); + }); it('Get answer no hruid given', async () => { req = { @@ -66,16 +65,15 @@ describe('Questions controllers', () => { query: { lang: Language.English, full: 'true' }, }; - await expect( async () => getAnswerHandler(req as Request, res as Response)) - .rejects.toThrow(BadRequestException); - }) + await expect(async () => getAnswerHandler(req as Request, res as Response)).rejects.toThrow(BadRequestException); + }); - it('Update question', async() => { - const newContent = "updated question"; + it('Update question', async () => { + const newContent = 'updated question'; req = { - params: { hruid: 'id05', version: '1', seq: '2', seqAnswer: '2'}, + params: { hruid: 'id05', version: '1', seq: '2', seqAnswer: '2' }, query: { lang: Language.English }, - body: { content: newContent } + body: { content: newContent }, }; await updateAnswerHandler(req as Request, res as Response); @@ -86,5 +84,4 @@ describe('Questions controllers', () => { // Console.log(result.question); expect(result.answer.content).to.eq(newContent); }); - }); diff --git a/backend/tests/controllers/questions.test.ts b/backend/tests/controllers/questions.test.ts index 593445c0..f2612fc7 100644 --- a/backend/tests/controllers/questions.test.ts +++ b/backend/tests/controllers/questions.test.ts @@ -1,14 +1,10 @@ -import {beforeAll, beforeEach, describe, expect, it, Mock, vi} from "vitest"; -import {Request, Response} from "express"; -import {setupTestApp} from "../setup-tests"; -import { - getAllQuestionsHandler, - getQuestionHandler, updateQuestionHandler -} from "../../src/controllers/questions"; -import {Language} from "@dwengo-1/common/util/language"; -import {NotFoundException} from "../../src/exceptions/not-found-exception"; -import {BadRequestException} from "../../src/exceptions/bad-request-exception"; - +import { beforeAll, beforeEach, describe, expect, it, Mock, vi } from 'vitest'; +import { Request, Response } from 'express'; +import { setupTestApp } from '../setup-tests'; +import { getAllQuestionsHandler, getQuestionHandler, updateQuestionHandler } from '../../src/controllers/questions'; +import { Language } from '@dwengo-1/common/util/language'; +import { NotFoundException } from '../../src/exceptions/not-found-exception'; +import { BadRequestException } from '../../src/exceptions/bad-request-exception'; describe('Questions controllers', () => { let req: Partial; @@ -43,7 +39,7 @@ describe('Questions controllers', () => { it('Get question', async () => { req = { - params: { hruid: 'id05', version: '1', seq: '1'}, + params: { hruid: 'id05', version: '1', seq: '1' }, query: { lang: Language.English, full: 'true' }, }; @@ -52,11 +48,11 @@ describe('Questions controllers', () => { // Const result = jsonMock.mock.lastCall?.[0]; // Console.log(result.question); - }) + }); it('Get question with fallback sequence number and version', async () => { req = { - params: { hruid: 'id05'}, + params: { hruid: 'id05' }, query: { lang: Language.English, full: 'true' }, }; @@ -65,17 +61,16 @@ describe('Questions controllers', () => { // Const result = jsonMock.mock.lastCall?.[0]; // Console.log(result.question); - }) + }); it('Get question hruid does not exist', async () => { req = { - params: { hruid: 'id_not_exist'}, + params: { hruid: 'id_not_exist' }, query: { lang: Language.English, full: 'true' }, }; - await expect( async () => getQuestionHandler(req as Request, res as Response)) - .rejects.toThrow(NotFoundException); - }) + await expect(async () => getQuestionHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException); + }); it('Get question no hruid given', async () => { req = { @@ -83,9 +78,8 @@ describe('Questions controllers', () => { query: { lang: Language.English, full: 'true' }, }; - await expect( async () => getQuestionHandler(req as Request, res as Response)) - .rejects.toThrow(BadRequestException); - }) + await expect(async () => getQuestionHandler(req as Request, res as Response)).rejects.toThrow(BadRequestException); + }); /* It('Create and delete question', async() => { @@ -104,12 +98,12 @@ describe('Questions controllers', () => { */ - it('Update question', async() => { - const newContent = "updated question"; + it('Update question', async () => { + const newContent = 'updated question'; req = { - params: { hruid: 'id05', version: '1', seq: '1'}, + params: { hruid: 'id05', version: '1', seq: '1' }, query: { lang: Language.English }, - body: { content: newContent } + body: { content: newContent }, }; await updateQuestionHandler(req as Request, res as Response); diff --git a/frontend/src/controllers/answers.ts b/frontend/src/controllers/answers.ts index b95f27db..04235e77 100644 --- a/frontend/src/controllers/answers.ts +++ b/frontend/src/controllers/answers.ts @@ -1,40 +1,39 @@ -import type {AnswerData, AnswerDTO, AnswerId} from "@dwengo-1/common/interfaces/answer"; -import {BaseController} from "@/controllers/base-controller.ts"; -import type {QuestionId} from "@dwengo-1/common/interfaces/question"; - +import type { AnswerData, AnswerDTO, AnswerId } from "@dwengo-1/common/interfaces/answer"; +import { BaseController } from "@/controllers/base-controller.ts"; +import type { QuestionId } from "@dwengo-1/common/interfaces/question"; export interface AnswersResponse { - answers: AnswerDTO[] | AnswerId[] + answers: AnswerDTO[] | AnswerId[]; } export interface AnswerResponse { - answer: AnswerDTO + answer: AnswerDTO; } export class AnswerController extends BaseController { constructor(questionId: QuestionId) { this.loId = questionId.learningObjectIdentifier; this.sequenceNumber = questionId.sequenceNumber; - super(`learningObject/${loId.hruid}/:${loId.version}/questions/${this.sequenceNumber}/answers`) + super(`learningObject/${loId.hruid}/:${loId.version}/questions/${this.sequenceNumber}/answers`); } async getAll(full = true): Promise { - return this.get("/", {lang: this.loId.lang, full}); + return this.get("/", { lang: this.loId.lang, full }); } async getBy(seq: number): Promise { - return this.get(`/${seq}`, {lang: this.loId.lang}); + return this.get(`/${seq}`, { lang: this.loId.lang }); } async create(answerData: AnswerData): Promise { - return this.post("/", answerData, {lang: this.loId.lang}); + return this.post("/", answerData, { lang: this.loId.lang }); } async remove(seq: number): Promise { - return this.delete(`/${seq}`, {lang: this.loId.lang}); + return this.delete(`/${seq}`, { lang: this.loId.lang }); } async update(seq: number, answerData: AnswerData): Promise { - return this.put(`/${seq}`, answerData,{lang: this.loId.lang}); + return this.put(`/${seq}`, answerData, { lang: this.loId.lang }); } } diff --git a/frontend/src/controllers/base-controller.ts b/frontend/src/controllers/base-controller.ts index f923c84f..54cf6221 100644 --- a/frontend/src/controllers/base-controller.ts +++ b/frontend/src/controllers/base-controller.ts @@ -28,13 +28,13 @@ export abstract class BaseController { } protected async delete(path: string, queryParams?: QueryParams): Promise { - const response = await apiClient.delete(this.absolutePathFor(path), { params: queryParams} ); + const response = await apiClient.delete(this.absolutePathFor(path), { params: queryParams }); BaseController.assertSuccessResponse(response); return response.data; } protected async put(path: string, body: unknown, queryParams?: QueryParams): Promise { - const response = await apiClient.put(this.absolutePathFor(path), body, { params: queryParams}); + const response = await apiClient.put(this.absolutePathFor(path), body, { params: queryParams }); BaseController.assertSuccessResponse(response); return response.data; } diff --git a/frontend/src/controllers/questions.ts b/frontend/src/controllers/questions.ts index 28609e95..60a51d1a 100644 --- a/frontend/src/controllers/questions.ts +++ b/frontend/src/controllers/questions.ts @@ -1,6 +1,6 @@ -import type {QuestionData, QuestionDTO, QuestionId} from "@dwengo-1/common/interfaces/question"; -import {BaseController} from "@/controllers/base-controller.ts"; -import type {LearningObjectIdentifierDTO} from "@dwengo-1/common/interfaces/learning-content"; +import type { QuestionData, QuestionDTO, QuestionId } from "@dwengo-1/common/interfaces/question"; +import { BaseController } from "@/controllers/base-controller.ts"; +import type { LearningObjectIdentifierDTO } from "@dwengo-1/common/interfaces/learning-content"; export interface QuestionsResponse { questions: QuestionDTO[] | QuestionId[]; @@ -17,22 +17,22 @@ export class QuestionController extends BaseController { } async getAll(full = true): Promise { - return this.get("/", {lang: this.loId.lang, full}); + return this.get("/", { lang: this.loId.lang, full }); } async getBy(sequenceNumber: number): Promise { - return this.get(`/${sequenceNumber}`, {lang: this.loId.lang}); + return this.get(`/${sequenceNumber}`, { lang: this.loId.lang }); } async create(questionData: QuestionData): Promise { - return this.post("/", questionData, {lang: this.loId.lang}) + return this.post("/", questionData, { lang: this.loId.lang }); } async remove(sequenceNumber: number): Promise { - return this.delete(`/${sequenceNumber}`, {lang: this.loId.lang}); + return this.delete(`/${sequenceNumber}`, { lang: this.loId.lang }); } async update(sequenceNumber: number, questionData: QuestionData): Promise { - return this.put(`/${sequenceNumber}`, questionData, {lang: this.loId.lang}); + return this.put(`/${sequenceNumber}`, questionData, { lang: this.loId.lang }); } } diff --git a/frontend/src/queries/answers.ts b/frontend/src/queries/answers.ts index 4f599963..f2d0f9c4 100644 --- a/frontend/src/queries/answers.ts +++ b/frontend/src/queries/answers.ts @@ -1,13 +1,8 @@ -import type { QuestionId} from "@dwengo-1/common/dist/interfaces/question.ts"; -import { type MaybeRefOrGetter, toValue} from "vue"; -import { - useMutation, - type UseMutationReturnType, - useQuery, - type UseQueryReturnType -} from "@tanstack/vue-query"; -import {AnswerController, type AnswerResponse, type AnswersResponse} from "@/controllers/answers.ts"; -import type {AnswerData} from "@dwengo-1/common/dist/interfaces/answer.ts"; +import type { QuestionId } from "@dwengo-1/common/dist/interfaces/question.ts"; +import { type MaybeRefOrGetter, toValue } from "vue"; +import { useMutation, type UseMutationReturnType, useQuery, type UseQueryReturnType } from "@tanstack/vue-query"; +import { AnswerController, type AnswerResponse, type AnswersResponse } from "@/controllers/answers.ts"; +import type { AnswerData } from "@dwengo-1/common/dist/interfaces/answer.ts"; // TODO caching @@ -23,7 +18,7 @@ export function useAnswersQuery( export function useAnswerQuery( questionId: MaybeRefOrGetter, - sequenceNumber: MaybeRefOrGetter + sequenceNumber: MaybeRefOrGetter, ): UseQueryReturnType { return useQuery({ queryFn: async () => new AnswerController(toValue(questionId)).getBy(toValue(sequenceNumber)), @@ -49,9 +44,8 @@ export function useDeleteAnswerMutation( export function useUpdateAnswerMutation( questionId: MaybeRefOrGetter, -): UseMutationReturnType { +): UseMutationReturnType { return useMutation({ mutationFn: async (data, seq) => new AnswerController(toValue(questionId)).update(seq, data), }); } - diff --git a/frontend/src/queries/questions.ts b/frontend/src/queries/questions.ts index fa6553de..b69164a4 100644 --- a/frontend/src/queries/questions.ts +++ b/frontend/src/queries/questions.ts @@ -1,17 +1,19 @@ -import {QuestionController, type QuestionResponse, type QuestionsResponse} from "@/controllers/questions.ts"; -import type {QuestionData, QuestionId} from "@dwengo-1/common/interfaces/question"; -import type {LearningObjectIdentifierDTO} from "@dwengo-1/common/interfaces/learning-content"; -import {computed, type MaybeRefOrGetter, toValue} from "vue"; +import { QuestionController, type QuestionResponse, type QuestionsResponse } from "@/controllers/questions.ts"; +import type { QuestionData, QuestionId } from "@dwengo-1/common/interfaces/question"; +import type { LearningObjectIdentifierDTO } from "@dwengo-1/common/interfaces/learning-content"; +import { computed, type MaybeRefOrGetter, toValue } from "vue"; import { useMutation, type UseMutationReturnType, useQuery, useQueryClient, - type UseQueryReturnType + type UseQueryReturnType, } from "@tanstack/vue-query"; - -export function questionsQueryKey(loId: LearningObjectIdentifierDTO, full: boolean): [string, string, number, string, boolean] { +export function questionsQueryKey( + loId: LearningObjectIdentifierDTO, + full: boolean, +): [string, string, number, string, boolean] { return ["questions", loId.hruid, loId.version, loId.language, full]; } @@ -65,7 +67,7 @@ export function useUpdateQuestionMutation( const sequenceNumber = toValue(questionId).sequenceNumber; return useMutation({ - mutationFn: async ( data ) => new QuestionController(loId).update(sequenceNumber, data), + mutationFn: async (data) => new QuestionController(loId).update(sequenceNumber, data), onSuccess: async () => { await queryClient.invalidateQueries({ queryKey: questionsQueryKey(toValue(loId), true) }); await queryClient.invalidateQueries({ queryKey: questionsQueryKey(toValue(loId), false) });