2025SELab2-project-Dwengo/backend/src/data/questions/answer-repository.ts
Gerald Schmittinger 4dcd4671ca fix(backend): Workaround voor autoincrement-problemen bij SQLite
SQLite (die we voor de automatische tests gebruiken) ondersteunt geen autoincrement op kolommen die deel uitmaken van een composite primary key. Hiervoor heb ik een workaround geïmplementeerd.
2025-03-13 02:20:01 +01:00

37 lines
1.2 KiB
TypeScript

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';
export class AnswerRepository extends DwengoEntityRepository<Answer> {
public createAnswer(answer: {
toQuestion: Question;
author: Teacher;
content: string;
}): Promise<Answer> {
const answerEntity = this.create(
{
toQuestion: answer.toQuestion,
author: answer.author,
content: answer.content,
timestamp: new Date()
}
);
return this.insert(answerEntity);
}
public findAllAnswersToQuestion(question: Question): Promise<Answer[]> {
return this.findAll({
where: { toQuestion: question },
orderBy: { sequenceNumber: 'ASC' },
});
}
public removeAnswerByQuestionAndSequenceNumber(
question: Question,
sequenceNumber: number
): Promise<void> {
return this.deleteWhere({
toQuestion: question,
sequenceNumber: sequenceNumber,
});
}
}