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
@@ -8,11 +8,11 @@ export class CreateResultRangeDTO {
@IsNumber()
@IsNotEmpty()
minScore!: number;
minProbability!: number;
@IsNumber()
@IsNotEmpty()
maxScore!: number;
maxProbability!: number;
@IsString()
@IsNotEmpty()
@@ -14,11 +14,11 @@ export class FindResultRangeDTO extends PartialType(PaginationQueryDTO) {
@IsNumber()
@IsOptional()
minScore?: number;
minProbability?: number;
@IsNumber()
@IsOptional()
maxScore?: number;
maxProbability?: number;
@IsString()
@IsOptional()
@@ -15,13 +15,13 @@ export class ResultRange {
type: 'int',
nullable: false,
})
minScore!: number;
minProbability!: number;
@Column({
type: 'int',
nullable: false,
})
maxScore!: number;
maxProbability!: number;
@Column({
type: 'varchar',
@@ -1,8 +1,8 @@
export enum ResultRangeSortField {
ID = 'id',
TEST = 'test',
MIN_SCORE = 'minScore',
MAX_SCORE = 'maxScore',
MIN_PROBABILITY = 'minProbability',
MAX_PROBABILITY = 'maxProbability',
TITLE = 'title',
DESCRIPTION = 'description',
}
@@ -17,12 +17,12 @@ export const filterResultRanges = (query: FindResultRangeDTO) => {
where.title = ILike(`%${query.title}%`);
}
if (query.maxScore !== undefined) {
where.maxScore = query.maxScore;
if (query.maxProbability !== undefined) {
where.maxProbability = query.maxProbability;
}
if (query.minScore !== undefined) {
where.minScore = query.minScore;
if (query.minProbability !== undefined) {
where.minProbability = query.minProbability;
}
return where;
@@ -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);
@@ -14,15 +14,15 @@ export class ResultRangeValidator implements ValidatorConstraintInterface {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const obj = validationArguments?.object as any;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { minScore, maxScore } = obj;
return minScore < maxScore;
const { minProbability, maxProbability } = obj;
return minProbability < maxProbability;
}
defaultMessage?(): string {
const i18n = I18nContext.current();
return (
i18n?.t('scoring.errors.resultRangeMinMaxConstraint') ||
'minScore value should be less than maxScore.'
'minProbability value should be less than maxProbability.'
);
}
}