fix: gebruik create question functie
This commit is contained in:
parent
70ba819e46
commit
e3e1fc3f05
4 changed files with 23 additions and 23 deletions
|
@ -5,6 +5,10 @@
|
||||||
// Load .env file
|
// Load .env file
|
||||||
// Dotenv.config();
|
// Dotenv.config();
|
||||||
|
|
||||||
|
import {Language} from "./entities/content/language.js";
|
||||||
|
|
||||||
export const DWENGO_API_BASE = 'https://dwengo.org/backend/api';
|
export const DWENGO_API_BASE = 'https://dwengo.org/backend/api';
|
||||||
|
|
||||||
export const FALLBACK_LANG = 'nl';
|
export const FALLBACK_LANG: Language = Language.Dutch;
|
||||||
|
|
||||||
|
export const FALLBACK_SEQ_NUM = 1;
|
||||||
|
|
|
@ -104,7 +104,10 @@ export async function createQuestionHandler(req: Request, res: Response): Promis
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteQuestionHandler(req: Request, res: Response): Promise<void> {
|
export async function deleteQuestionHandler(req: Request, res: Response): Promise<void> {
|
||||||
const questionId = getQuestionId(res, req)
|
const questionId = getQuestionId(req, res);
|
||||||
|
|
||||||
|
if (!questionId)
|
||||||
|
return
|
||||||
|
|
||||||
const question = await deleteQuestion(questionId);
|
const question = await deleteQuestion(questionId);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { Question } from '../entities/questions/question.entity.js';
|
import { Question } from '../entities/questions/question.entity.js';
|
||||||
import {mapToUserDTO, UserDTO} from "./user.js";
|
import {UserDTO} from "./user.js";
|
||||||
import {LearningObjectIdentifier} from "../entities/content/learning-object-identifier.js";
|
import {LearningObjectIdentifier} from "../entities/content/learning-object-identifier.js";
|
||||||
import {Teacher} from "../entities/users/teacher.entity";
|
|
||||||
|
|
||||||
export interface QuestionDTO {
|
export interface QuestionDTO {
|
||||||
learningObjectIdentifier: LearningObjectIdentifier;
|
learningObjectIdentifier: LearningObjectIdentifier;
|
||||||
|
@ -23,7 +22,7 @@ export function mapToQuestionDTO(question: Question): QuestionDTO {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
learningObjectIdentifier,
|
learningObjectIdentifier,
|
||||||
sequenceNumber: question.sequenceNumber,
|
sequenceNumber: question.sequenceNumber!,
|
||||||
author: question.author,
|
author: question.author,
|
||||||
timestamp: question.timestamp.toISOString(),
|
timestamp: question.timestamp.toISOString(),
|
||||||
content: question.content,
|
content: question.content,
|
||||||
|
@ -38,19 +37,7 @@ export interface QuestionId {
|
||||||
export function mapToQuestionId(question: QuestionDTO): QuestionId {
|
export function mapToQuestionId(question: QuestionDTO): QuestionId {
|
||||||
return {
|
return {
|
||||||
learningObjectIdentifier: question.learningObjectIdentifier,
|
learningObjectIdentifier: question.learningObjectIdentifier,
|
||||||
sequenceNumber: question.sequenceNumber,
|
sequenceNumber: question.sequenceNumber!,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mapToQuestion(questionDTO: QuestionDTO): Question {
|
|
||||||
const question = new Question();
|
|
||||||
question.author = mapToUserDTO<Teacher>(questionDTO.author);
|
|
||||||
question.learningObjectHruid = questionDTO.learningObjectIdentifier.hruid;
|
|
||||||
question.learningObjectLanguage = questionDTO.learningObjectIdentifier.language;
|
|
||||||
question.learningObjectVersion = questionDTO.learningObjectIdentifier.version;
|
|
||||||
question.content = questionDTO.content;
|
|
||||||
question.sequenceNumber = questionDTO.sequenceNumber;
|
|
||||||
question.timestamp = questionDTO.timestamp;
|
|
||||||
|
|
||||||
return question;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
import {getAnswerRepository, getQuestionRepository} from "../data/repositories.js";
|
import {getAnswerRepository, getQuestionRepository} from "../data/repositories.js";
|
||||||
import {mapToQuestion, mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId} from "../interfaces/question.js";
|
import {mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId} from "../interfaces/question.js";
|
||||||
import {Question} from "../entities/questions/question.entity.js";
|
import {Question} from "../entities/questions/question.entity.js";
|
||||||
import {Answer} from "../entities/questions/answer.entity.js";
|
import {Answer} from "../entities/questions/answer.entity.js";
|
||||||
import {mapToAnswerDTO, mapToAnswerId} from "../interfaces/answer.js";
|
import {mapToAnswerDTO, mapToAnswerId} from "../interfaces/answer.js";
|
||||||
import {QuestionRepository} from "../data/questions/question-repository.js";
|
import {QuestionRepository} from "../data/questions/question-repository.js";
|
||||||
import {LearningObjectIdentifier} from "../entities/content/learning-object-identifier.js";
|
import {LearningObjectIdentifier} from "../entities/content/learning-object-identifier.js";
|
||||||
|
import {mapToUser} from "../interfaces/user.js";
|
||||||
|
import {Student} from "../entities/users/student.entity.js";
|
||||||
|
|
||||||
export async function getAllQuestions(
|
export async function getAllQuestions(
|
||||||
id: LearningObjectIdentifier, full: boolean
|
id: LearningObjectIdentifier, full: boolean
|
||||||
|
@ -69,16 +71,20 @@ export async function getAnswersByQuestion(questionId: QuestionId, full: boolean
|
||||||
|
|
||||||
export async function createQuestion(questionDTO: QuestionDTO) {
|
export async function createQuestion(questionDTO: QuestionDTO) {
|
||||||
const questionRepository = getQuestionRepository();
|
const questionRepository = getQuestionRepository();
|
||||||
const question = mapToQuestion(questionDTO);
|
|
||||||
|
const author = mapToUser<Student>(questionDTO.author, new Student())
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const newQuestion = questionRepository.create(question)
|
await questionRepository.createQuestion({
|
||||||
await questionRepository.save(newQuestion);
|
loId: questionDTO.learningObjectIdentifier,
|
||||||
|
author,
|
||||||
|
content: questionDTO.content }
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return newQuestion;
|
return questionDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteQuestion(questionId: QuestionId) {
|
export async function deleteQuestion(questionId: QuestionId) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue