fix: lint
This commit is contained in:
		
							parent
							
								
									42526900d3
								
							
						
					
					
						commit
						c07db3d999
					
				
					 6 changed files with 18 additions and 16 deletions
				
			
		|  | @ -2,6 +2,7 @@ import { DwengoEntityRepository } from '../dwengo-entity-repository.js'; | ||||||
| import { Answer } from '../../entities/questions/answer.entity.js'; | import { Answer } from '../../entities/questions/answer.entity.js'; | ||||||
| import { Question } from '../../entities/questions/question.entity.js'; | import { Question } from '../../entities/questions/question.entity.js'; | ||||||
| import { Teacher } from '../../entities/users/teacher.entity.js'; | import { Teacher } from '../../entities/users/teacher.entity.js'; | ||||||
|  | import {Loaded} from "@mikro-orm/core"; | ||||||
| 
 | 
 | ||||||
| export class AnswerRepository extends DwengoEntityRepository<Answer> { | export class AnswerRepository extends DwengoEntityRepository<Answer> { | ||||||
|     public async createAnswer(answer: { toQuestion: Question; author: Teacher; content: string }): Promise<Answer> { |     public async createAnswer(answer: { toQuestion: Question; author: Teacher; content: string }): Promise<Answer> { | ||||||
|  | @ -19,7 +20,7 @@ export class AnswerRepository extends DwengoEntityRepository<Answer> { | ||||||
|             orderBy: { sequenceNumber: 'ASC' }, |             orderBy: { sequenceNumber: 'ASC' }, | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|     public async findAnswer(question: Question, sequenceNumber: number) { |     public async findAnswer(question: Question, sequenceNumber: number): Promise<Loaded<Answer, never, "*", never> | null> { | ||||||
|         return this.findOne({ |         return this.findOne({ | ||||||
|             toQuestion: question, sequenceNumber |             toQuestion: question, sequenceNumber | ||||||
|         }); |         }); | ||||||
|  | @ -30,7 +31,7 @@ export class AnswerRepository extends DwengoEntityRepository<Answer> { | ||||||
|             sequenceNumber: sequenceNumber, |             sequenceNumber: sequenceNumber, | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|     public async updateContent(answer: Answer, newContent: string){ |     public async updateContent(answer: Answer, newContent: string): Promise<Answer> { | ||||||
|         answer.content = newContent; |         answer.content = newContent; | ||||||
|         await this.save(answer); |         await this.save(answer); | ||||||
|         return answer; |         return answer; | ||||||
|  |  | ||||||
|  | @ -3,6 +3,7 @@ import { Question } from '../../entities/questions/question.entity.js'; | ||||||
| import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier.js'; | import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier.js'; | ||||||
| import { Student } from '../../entities/users/student.entity.js'; | import { Student } from '../../entities/users/student.entity.js'; | ||||||
| import { LearningObject } from '../../entities/content/learning-object.entity.js'; | import { LearningObject } from '../../entities/content/learning-object.entity.js'; | ||||||
|  | import {Loaded} from "@mikro-orm/core"; | ||||||
| 
 | 
 | ||||||
| export class QuestionRepository extends DwengoEntityRepository<Question> { | export class QuestionRepository extends DwengoEntityRepository<Question> { | ||||||
|     public async createQuestion(question: { loId: LearningObjectIdentifier; author: Student; content: string }): Promise<Question> { |     public async createQuestion(question: { loId: LearningObjectIdentifier; author: Student; content: string }): Promise<Question> { | ||||||
|  | @ -62,7 +63,7 @@ export class QuestionRepository extends DwengoEntityRepository<Question> { | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public async findByLearningObjectAndSequenceNumber(loId: LearningObjectIdentifier, sequenceNumber: number){ |     public async findByLearningObjectAndSequenceNumber(loId: LearningObjectIdentifier, sequenceNumber: number): Promise<Loaded<Question, never, "*", never> | null> { | ||||||
|         return this.findOne({ |         return this.findOne({ | ||||||
|             learningObjectHruid: loId.hruid, |             learningObjectHruid: loId.hruid, | ||||||
|             learningObjectLanguage: loId.language, |             learningObjectLanguage: loId.language, | ||||||
|  |  | ||||||
|  | @ -59,7 +59,7 @@ export async function deleteAnswer(questionId: QuestionId, sequenceNumber: numbe | ||||||
|     return mapToAnswerDTO(answer); |     return mapToAnswerDTO(answer); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function updateAnswer(questionId: QuestionId, sequenceNumber: number, answerData: AnswerData){ | export async function updateAnswer(questionId: QuestionId, sequenceNumber: number, answerData: AnswerData): Promise<AnswerDTO> { | ||||||
|     const answerRepository = getAnswerRepository(); |     const answerRepository = getAnswerRepository(); | ||||||
|     const answer = await fetchAnswer(questionId, sequenceNumber); |     const answer = await fetchAnswer(questionId, sequenceNumber); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -52,7 +52,7 @@ export async function createQuestion(loId: LearningObjectIdentifier, questionDat | ||||||
| 
 | 
 | ||||||
| export async function deleteQuestion(questionId: QuestionId): Promise<QuestionDTO> { | export async function deleteQuestion(questionId: QuestionId): Promise<QuestionDTO> { | ||||||
|     const questionRepository = getQuestionRepository(); |     const questionRepository = getQuestionRepository(); | ||||||
|     const question = await fetchQuestion(questionId); // throws error if not found
 |     const question = await fetchQuestion(questionId); // Throws error if not found
 | ||||||
| 
 | 
 | ||||||
|     const loId : LearningObjectIdentifier = { |     const loId : LearningObjectIdentifier = { | ||||||
|         hruid: questionId.learningObjectIdentifier.hruid, |         hruid: questionId.learningObjectIdentifier.hruid, | ||||||
|  |  | ||||||
|  | @ -33,7 +33,7 @@ describe('Questions controllers', () => { | ||||||
|         expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({answers: expect.anything()})); |         expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({answers: expect.anything()})); | ||||||
| 
 | 
 | ||||||
|         const result = jsonMock.mock.lastCall?.[0]; |         const result = jsonMock.mock.lastCall?.[0]; | ||||||
|         // console.log(result.answers);
 |         // Console.log(result.answers);
 | ||||||
|         expect(result.questions).to.have.length.greaterThan(1); |         expect(result.questions).to.have.length.greaterThan(1); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|  | @ -46,8 +46,8 @@ describe('Questions controllers', () => { | ||||||
|         await getAnswerHandler(req as Request, res as Response); |         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];
 |         // Const result = jsonMock.mock.lastCall?.[0];
 | ||||||
|         // console.log(result.answer);
 |         // Console.log(result.answer);
 | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     it('Get answer hruid does not exist', async () => { |     it('Get answer hruid does not exist', async () => { | ||||||
|  | @ -83,7 +83,7 @@ describe('Questions controllers', () => { | ||||||
|         expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ answer: expect.anything() })); |         expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ answer: expect.anything() })); | ||||||
| 
 | 
 | ||||||
|         const result = jsonMock.mock.lastCall?.[0]; |         const result = jsonMock.mock.lastCall?.[0]; | ||||||
|         // console.log(result.question);
 |         // Console.log(result.question);
 | ||||||
|         expect(result.answer.content).to.eq(newContent); |         expect(result.answer.content).to.eq(newContent); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -37,7 +37,7 @@ describe('Questions controllers', () => { | ||||||
|         expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ questions: expect.anything() })); |         expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ questions: expect.anything() })); | ||||||
| 
 | 
 | ||||||
|         const result = jsonMock.mock.lastCall?.[0]; |         const result = jsonMock.mock.lastCall?.[0]; | ||||||
|         // console.log(result.questions);
 |         // Console.log(result.questions);
 | ||||||
|         expect(result.questions).to.have.length.greaterThan(1); |         expect(result.questions).to.have.length.greaterThan(1); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|  | @ -50,8 +50,8 @@ describe('Questions controllers', () => { | ||||||
|         await getQuestionHandler(req as Request, res as Response); |         await getQuestionHandler(req as Request, res as Response); | ||||||
|         expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ question: expect.anything() })); |         expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ question: expect.anything() })); | ||||||
| 
 | 
 | ||||||
|         // const result = jsonMock.mock.lastCall?.[0];
 |         // Const result = jsonMock.mock.lastCall?.[0];
 | ||||||
|         // console.log(result.question);
 |         // Console.log(result.question);
 | ||||||
|     }) |     }) | ||||||
| 
 | 
 | ||||||
|     it('Get question with fallback sequence number and version', async () => { |     it('Get question with fallback sequence number and version', async () => { | ||||||
|  | @ -63,8 +63,8 @@ describe('Questions controllers', () => { | ||||||
|         await getQuestionHandler(req as Request, res as Response); |         await getQuestionHandler(req as Request, res as Response); | ||||||
|         expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ question: expect.anything() })); |         expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ question: expect.anything() })); | ||||||
| 
 | 
 | ||||||
|         // const result = jsonMock.mock.lastCall?.[0];
 |         // Const result = jsonMock.mock.lastCall?.[0];
 | ||||||
|         // console.log(result.question);
 |         // Console.log(result.question);
 | ||||||
|     }) |     }) | ||||||
| 
 | 
 | ||||||
|     it('Get question hruid does not exist', async () => { |     it('Get question hruid does not exist', async () => { | ||||||
|  | @ -88,7 +88,7 @@ describe('Questions controllers', () => { | ||||||
|     }) |     }) | ||||||
| 
 | 
 | ||||||
|     /* |     /* | ||||||
|     it('Create and delete question', async() => { |     It('Create and delete question', async() => { | ||||||
|         req = { |         req = { | ||||||
|             params: { hruid: 'id05', version: '1', seq: '2'}, |             params: { hruid: 'id05', version: '1', seq: '2'}, | ||||||
|             query: { lang: Language.English }, |             query: { lang: Language.English }, | ||||||
|  | @ -117,7 +117,7 @@ describe('Questions controllers', () => { | ||||||
|         expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ question: expect.anything() })); |         expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ question: expect.anything() })); | ||||||
| 
 | 
 | ||||||
|         const result = jsonMock.mock.lastCall?.[0]; |         const result = jsonMock.mock.lastCall?.[0]; | ||||||
|         // console.log(result.question);
 |         // Console.log(result.question);
 | ||||||
|         expect(result.question.content).to.eq(newContent); |         expect(result.question.content).to.eq(newContent); | ||||||
|     }); |     }); | ||||||
| }); | }); | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Gabriellvl
						Gabriellvl