style: fix linting issues met Prettier
This commit is contained in:
		
							parent
							
								
									5cea6929f9
								
							
						
					
					
						commit
						a8895cc429
					
				
					 12 changed files with 104 additions and 121 deletions
				
			
		|  | @ -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<Answer> { | ||||
|     public async createAnswer(answer: { toQuestion: Question; author: Teacher; content: string }): Promise<Answer> { | ||||
|  | @ -22,7 +22,8 @@ export class AnswerRepository extends DwengoEntityRepository<Answer> { | |||
|     } | ||||
|     public async findAnswer(question: Question, sequenceNumber: number): Promise<Loaded<Answer> | null> { | ||||
|         return this.findOne({ | ||||
|             toQuestion: question, sequenceNumber | ||||
|             toQuestion: question, | ||||
|             sequenceNumber, | ||||
|         }); | ||||
|     } | ||||
|     public async removeAnswerByQuestionAndSequenceNumber(question: Question, sequenceNumber: number): Promise<void> { | ||||
|  |  | |||
|  | @ -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<Question> { | ||||
|     public async createQuestion(question: { loId: LearningObjectIdentifier; author: Student; content: string }): Promise<Question> { | ||||
|  | @ -68,7 +68,7 @@ export class QuestionRepository extends DwengoEntityRepository<Question> { | |||
|             learningObjectHruid: loId.hruid, | ||||
|             learningObjectLanguage: loId.language, | ||||
|             learningObjectVersion: loId.version, | ||||
|             sequenceNumber | ||||
|             sequenceNumber, | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -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); | ||||
| 
 | ||||
|  |  | |||
|  | @ -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'); | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -56,11 +56,11 @@ export async function deleteQuestion(questionId: QuestionId): Promise<QuestionDT | |||
|     const questionRepository = getQuestionRepository(); | ||||
|     const question = await fetchQuestion(questionId); // Throws error if not found
 | ||||
| 
 | ||||
|     const loId : LearningObjectIdentifier = { | ||||
|     const loId: LearningObjectIdentifier = { | ||||
|         hruid: questionId.learningObjectIdentifier.hruid, | ||||
|         language: questionId.learningObjectIdentifier.language, | ||||
|         version: questionId.learningObjectIdentifier.version || FALLBACK_VERSION_NUM | ||||
|     } | ||||
|         version: questionId.learningObjectIdentifier.version || FALLBACK_VERSION_NUM, | ||||
|     }; | ||||
| 
 | ||||
|     await questionRepository.removeQuestionByLearningObjectAndSequenceNumber(loId, questionId.sequenceNumber); | ||||
|     return mapToQuestionDTO(question); | ||||
|  |  | |||
|  | @ -1,10 +1,10 @@ | |||
| import {Request, Response} from "express"; | ||||
| import {beforeAll, beforeEach, describe, expect, it, Mock, vi} from "vitest"; | ||||
| import {setupTestApp} from "../setup-tests"; | ||||
| import {Language} from "@dwengo-1/common/util/language"; | ||||
| import {getAllAnswersHandler, getAnswerHandler, updateAnswerHandler} from "../../src/controllers/answers"; | ||||
| import {BadRequestException} from "../../src/exceptions/bad-request-exception"; | ||||
| import {NotFoundException} from "../../src/exceptions/not-found-exception"; | ||||
| import { Request, Response } from 'express'; | ||||
| import { beforeAll, beforeEach, describe, expect, it, Mock, vi } from 'vitest'; | ||||
| import { setupTestApp } from '../setup-tests'; | ||||
| import { Language } from '@dwengo-1/common/util/language'; | ||||
| import { getAllAnswersHandler, getAnswerHandler, updateAnswerHandler } from '../../src/controllers/answers'; | ||||
| import { BadRequestException } from '../../src/exceptions/bad-request-exception'; | ||||
| import { NotFoundException } from '../../src/exceptions/not-found-exception'; | ||||
| 
 | ||||
| describe('Questions controllers', () => { | ||||
|     let req: Partial<Request>; | ||||
|  | @ -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); | ||||
|     }); | ||||
| 
 | ||||
| }); | ||||
|  |  | |||
|  | @ -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<Request>; | ||||
|  | @ -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); | ||||
|  |  | |||
		Reference in a new issue
	
	 Lint Action
						Lint Action