style: fix linting issues met Prettier
This commit is contained in:
parent
e78849f568
commit
400a955850
40 changed files with 321 additions and 700 deletions
|
@ -1,17 +1,15 @@
|
|||
import {getAnswerRepository, getQuestionRepository} from "../data/repositories.js";
|
||||
import {mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId} from "../interfaces/question.js";
|
||||
import {Question} from "../entities/questions/question.entity.js";
|
||||
import {Answer} from "../entities/questions/answer.entity.js";
|
||||
import {mapToAnswerDTO, mapToAnswerId} from "../interfaces/answer.js";
|
||||
import {QuestionRepository} from "../data/questions/question-repository.js";
|
||||
import {LearningObjectIdentifier} from "../entities/content/learning-object-identifier.js";
|
||||
import {mapToUser} from "../interfaces/user.js";
|
||||
import {Student} from "../entities/users/student.entity.js";
|
||||
import { mapToStudent } from "../interfaces/student.js";
|
||||
import { getAnswerRepository, getQuestionRepository } from '../data/repositories.js';
|
||||
import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js';
|
||||
import { Question } from '../entities/questions/question.entity.js';
|
||||
import { Answer } from '../entities/questions/answer.entity.js';
|
||||
import { mapToAnswerDTO, mapToAnswerId } from '../interfaces/answer.js';
|
||||
import { QuestionRepository } from '../data/questions/question-repository.js';
|
||||
import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js';
|
||||
import { mapToUser } from '../interfaces/user.js';
|
||||
import { Student } from '../entities/users/student.entity.js';
|
||||
import { mapToStudent } from '../interfaces/student.js';
|
||||
|
||||
export async function getAllQuestions(
|
||||
id: LearningObjectIdentifier, full: boolean
|
||||
): Promise<QuestionDTO[] | QuestionId[]> {
|
||||
export async function getAllQuestions(id: LearningObjectIdentifier, full: boolean): Promise<QuestionDTO[] | QuestionId[]> {
|
||||
const questionRepository: QuestionRepository = getQuestionRepository();
|
||||
const questions = await questionRepository.findAllQuestionsAboutLearningObject(id);
|
||||
|
||||
|
@ -19,7 +17,7 @@ export async function getAllQuestions(
|
|||
return [];
|
||||
}
|
||||
|
||||
const questionsDTO: QuestionDTO[] = questions.map(mapToQuestionDTO);
|
||||
const questionsDTO: QuestionDTO[] = questions.map(mapToQuestionDTO);
|
||||
|
||||
if (full) {
|
||||
return questionsDTO;
|
||||
|
@ -31,21 +29,20 @@ export async function getAllQuestions(
|
|||
async function fetchQuestion(questionId: QuestionId): Promise<Question | null> {
|
||||
const questionRepository = getQuestionRepository();
|
||||
|
||||
return await questionRepository.findOne(
|
||||
{
|
||||
learningObjectHruid: questionId.learningObjectIdentifier.hruid,
|
||||
learningObjectLanguage: questionId.learningObjectIdentifier.language,
|
||||
learningObjectVersion: questionId.learningObjectIdentifier.version,
|
||||
sequenceNumber: questionId.sequenceNumber
|
||||
}
|
||||
)
|
||||
return await questionRepository.findOne({
|
||||
learningObjectHruid: questionId.learningObjectIdentifier.hruid,
|
||||
learningObjectLanguage: questionId.learningObjectIdentifier.language,
|
||||
learningObjectVersion: questionId.learningObjectIdentifier.version,
|
||||
sequenceNumber: questionId.sequenceNumber,
|
||||
});
|
||||
}
|
||||
|
||||
export async function getQuestion(questionId: QuestionId): Promise<QuestionDTO | null> {
|
||||
const question = await fetchQuestion(questionId);
|
||||
|
||||
if (!question)
|
||||
{return null}
|
||||
if (!question) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return mapToQuestionDTO(question);
|
||||
}
|
||||
|
@ -54,18 +51,21 @@ export async function getAnswersByQuestion(questionId: QuestionId, full: boolean
|
|||
const answerRepository = getAnswerRepository();
|
||||
const question = await fetchQuestion(questionId);
|
||||
|
||||
if (!question)
|
||||
{return [];}
|
||||
if (!question) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const answers: Answer[] = await answerRepository.findAllAnswersToQuestion(question);
|
||||
|
||||
if (!answers)
|
||||
{return []}
|
||||
if (!answers) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const answersDTO = answers.map(mapToAnswerDTO);
|
||||
|
||||
if (full)
|
||||
{return answersDTO}
|
||||
if (full) {
|
||||
return answersDTO;
|
||||
}
|
||||
|
||||
return answersDTO.map(mapToAnswerId);
|
||||
}
|
||||
|
@ -79,10 +79,10 @@ export async function createQuestion(questionDTO: QuestionDTO) {
|
|||
await questionRepository.createQuestion({
|
||||
loId: questionDTO.learningObjectIdentifier,
|
||||
author,
|
||||
content: questionDTO.content }
|
||||
);
|
||||
content: questionDTO.content,
|
||||
});
|
||||
} catch (e) {
|
||||
return null
|
||||
return null;
|
||||
}
|
||||
|
||||
return questionDTO;
|
||||
|
@ -93,18 +93,15 @@ export async function deleteQuestion(questionId: QuestionId) {
|
|||
|
||||
const question = await fetchQuestion(questionId);
|
||||
|
||||
if (!question)
|
||||
{return null}
|
||||
|
||||
try {
|
||||
await questionRepository.removeQuestionByLearningObjectAndSequenceNumber(
|
||||
questionId.learningObjectIdentifier, questionId.sequenceNumber
|
||||
);
|
||||
} catch (e) {
|
||||
return null
|
||||
if (!question) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return question
|
||||
try {
|
||||
await questionRepository.removeQuestionByLearningObjectAndSequenceNumber(questionId.learningObjectIdentifier, questionId.sequenceNumber);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return question;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue