feat: change result range check field

This commit is contained in:
2026-09-09 18:22:06 +03:30
parent f3c86da09b
commit bc333b8289
12 changed files with 67 additions and 44 deletions
@@ -32,16 +32,16 @@ export class ResultRangeCommandProvider {
private async checkRangeOverlap(
test: number,
minScore: number,
maxScore: number,
minProbability: number,
maxProbability: number,
excludeSelf: boolean = false,
): Promise<void> {
const queryBuilder = this.resultRangeRepository
.createQueryBuilder('resultRange')
.where('resultRange.testId = :test', { test })
.andWhere(
'(resultRange.minScore BETWEEN :minScore AND :maxScore) OR (resultRange.maxScore BETWEEN :minScore AND :maxScore) OR (:minScore BETWEEN resultRange.minScore AND resultRange.maxScore) OR (:maxScore BETWEEN resultRange.minScore AND resultRange.maxScore)',
{ minScore, maxScore },
'(resultRange.minProbability BETWEEN :minProbability AND :maxProbability) OR (resultRange.maxProbability BETWEEN :minProbability AND :maxProbability) OR (:minProbability BETWEEN resultRange.minProbability AND resultRange.maxProbability) OR (:maxProbability BETWEEN resultRange.minProbability AND resultRange.maxProbability)',
{ minProbability, maxProbability },
);
let overlappingRanges: Array<ResultRange>;
@@ -92,8 +92,8 @@ export class ResultRangeCommandProvider {
await this.checkRangeOverlap(
test.id,
createResultRangeDto.minScore,
createResultRangeDto.maxScore,
createResultRangeDto.minProbability,
createResultRangeDto.maxProbability,
);
const newResultRange = this.resultRangeRepository.create({
@@ -129,23 +129,23 @@ export class ResultRangeCommandProvider {
? updateResultRangeDto.test
: resultRange.test.id;
const minScore =
updateResultRangeDto.minScore !== undefined
? updateResultRangeDto.minScore
: resultRange.minScore;
const minProbability =
updateResultRangeDto.minProbability !== undefined
? updateResultRangeDto.minProbability
: resultRange.minProbability;
const maxScore =
updateResultRangeDto.maxScore !== undefined
? updateResultRangeDto.maxScore
: resultRange.maxScore;
const maxProbability =
updateResultRangeDto.maxProbability !== undefined
? updateResultRangeDto.maxProbability
: resultRange.maxProbability;
if (minScore >= maxScore) {
if (minProbability >= maxProbability) {
throw new BadRequestException(
'scoring.errors.resultRangeMinMaxConstraint',
);
}
await this.checkRangeOverlap(testId, minScore, maxScore, true);
await this.checkRangeOverlap(testId, minProbability, maxProbability, true);
Object.assign(resultRange, updateResultRangeDto);