feat: add admin panel dto & validation
This commit is contained in:
@@ -34,16 +34,19 @@ export class ResultRangeCommandProvider {
|
||||
test: number,
|
||||
minScore: number,
|
||||
maxScore: number,
|
||||
excludeSelf: boolean = false,
|
||||
excludeId?: number,
|
||||
): 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)',
|
||||
'(resultRange.minScore <= :maxScore AND resultRange.maxScore >= :minScore)',
|
||||
{ minScore, maxScore },
|
||||
);
|
||||
|
||||
if (excludeId !== undefined)
|
||||
queryBuilder.andWhere('resultRange.id != :excludeId', { excludeId });
|
||||
|
||||
let overlappingRanges: Array<ResultRange>;
|
||||
|
||||
try {
|
||||
@@ -52,7 +55,7 @@ export class ResultRangeCommandProvider {
|
||||
throw new AppTimeoutException(err);
|
||||
}
|
||||
|
||||
if (overlappingRanges.length > (excludeSelf ? 1 : 0)) {
|
||||
if (overlappingRanges.length > 0) {
|
||||
throw new AppException(
|
||||
'scoring.errors.resultRangeOverlappingConstraint',
|
||||
HttpStatus.CONFLICT,
|
||||
@@ -145,9 +148,11 @@ export class ResultRangeCommandProvider {
|
||||
);
|
||||
}
|
||||
|
||||
await this.checkRangeOverlap(testId, minScore, maxScore, true);
|
||||
await this.checkRangeOverlap(testId, minScore, maxScore, id);
|
||||
|
||||
Object.assign(resultRange, updateResultRangeDto);
|
||||
const changes = { ...updateResultRangeDto };
|
||||
delete changes.test;
|
||||
Object.assign(resultRange, changes, { test: { id: testId }, testId });
|
||||
|
||||
try {
|
||||
return await this.resultRangeRepository.save(resultRange);
|
||||
|
||||
Reference in New Issue
Block a user