feat: change answer submission architecture
This commit is contained in:
@@ -56,6 +56,9 @@ export class Test {
|
||||
@OneToMany(() => Question, (question) => question.test)
|
||||
questions!: Array<Question>;
|
||||
|
||||
@Column({ type: 'int', nullable: false, default: 0 })
|
||||
questionsCount!: number;
|
||||
|
||||
@OneToMany(() => ResultRange, (range) => range.test)
|
||||
resultRanges!: Array<ResultRange>;
|
||||
|
||||
|
||||
@@ -105,4 +105,28 @@ export class TestsCommandProvider {
|
||||
throw new AppTimeoutException(err);
|
||||
}
|
||||
}
|
||||
|
||||
public async incrementQuestionsCount(testId: number, count?: number) {
|
||||
try {
|
||||
await this.testRepository.increment(
|
||||
{ id: testId },
|
||||
'questionsCount',
|
||||
count || 1,
|
||||
);
|
||||
} catch (err) {
|
||||
throw new AppTimeoutException(err);
|
||||
}
|
||||
}
|
||||
|
||||
public async decrementQuestionsCount(testId: number, count?: number) {
|
||||
try {
|
||||
await this.testRepository.decrement(
|
||||
{ id: testId },
|
||||
'questionsCount',
|
||||
count || 1,
|
||||
);
|
||||
} catch (err) {
|
||||
throw new AppTimeoutException(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,4 +48,18 @@ export class TestsService {
|
||||
public async deleteOne(id: number) {
|
||||
return await this.testsCommandProvider.deleteOne(id);
|
||||
}
|
||||
|
||||
public async incrementQuestionsCount(testId: number, count?: number) {
|
||||
return await this.testsCommandProvider.incrementQuestionsCount(
|
||||
testId,
|
||||
count,
|
||||
);
|
||||
}
|
||||
|
||||
public async decrementQuestionsCount(testId: number, count?: number) {
|
||||
return await this.testsCommandProvider.decrementQuestionsCount(
|
||||
testId,
|
||||
count,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user