feat: change minmax probability to minmax score
This commit is contained in:
@@ -32,16 +32,16 @@ export class ResultRangeCommandProvider {
|
||||
|
||||
private async checkRangeOverlap(
|
||||
test: number,
|
||||
minProbability: number,
|
||||
maxProbability: number,
|
||||
minScore: number,
|
||||
maxScore: number,
|
||||
excludeSelf: boolean = false,
|
||||
): Promise<void> {
|
||||
const queryBuilder = this.resultRangeRepository
|
||||
.createQueryBuilder('resultRange')
|
||||
.where('resultRange.testId = :test', { test })
|
||||
.andWhere(
|
||||
'(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 },
|
||||
'(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 },
|
||||
);
|
||||
|
||||
let overlappingRanges: Array<ResultRange>;
|
||||
@@ -92,8 +92,8 @@ export class ResultRangeCommandProvider {
|
||||
|
||||
await this.checkRangeOverlap(
|
||||
test.id,
|
||||
createResultRangeDto.minProbability,
|
||||
createResultRangeDto.maxProbability,
|
||||
createResultRangeDto.minScore,
|
||||
createResultRangeDto.maxScore,
|
||||
);
|
||||
|
||||
const newResultRange = this.resultRangeRepository.create({
|
||||
@@ -129,23 +129,23 @@ export class ResultRangeCommandProvider {
|
||||
? updateResultRangeDto.test
|
||||
: resultRange.test.id;
|
||||
|
||||
const minProbability =
|
||||
updateResultRangeDto.minProbability !== undefined
|
||||
? updateResultRangeDto.minProbability
|
||||
: resultRange.minProbability;
|
||||
const minScore =
|
||||
updateResultRangeDto.minScore !== undefined
|
||||
? updateResultRangeDto.minScore
|
||||
: resultRange.minScore;
|
||||
|
||||
const maxProbability =
|
||||
updateResultRangeDto.maxProbability !== undefined
|
||||
? updateResultRangeDto.maxProbability
|
||||
: resultRange.maxProbability;
|
||||
const maxScore =
|
||||
updateResultRangeDto.maxScore !== undefined
|
||||
? updateResultRangeDto.maxScore
|
||||
: resultRange.maxScore;
|
||||
|
||||
if (minProbability >= maxProbability) {
|
||||
if (minScore >= maxScore) {
|
||||
throw new BadRequestException(
|
||||
'scoring.errors.resultRangeMinMaxConstraint',
|
||||
);
|
||||
}
|
||||
|
||||
await this.checkRangeOverlap(testId, minProbability, maxProbability, true);
|
||||
await this.checkRangeOverlap(testId, minScore, maxScore, true);
|
||||
|
||||
Object.assign(resultRange, updateResultRangeDto);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user