feat: add admin panel dto & validation

This commit is contained in:
2026-11-14 22:43:12 +03:30
parent 2d32e2679b
commit 8d6834f44c
18 changed files with 1832 additions and 52 deletions
@@ -57,7 +57,7 @@ export class QuestionRangeRuleCommandProvider {
question: number,
min: number,
max: number,
excludeSelf: boolean = false,
excludeId?: number,
): Promise<void> {
const queryBuilder = this.questionRangeRulesRepository
.createQueryBuilder('rule')
@@ -72,6 +72,9 @@ export class QuestionRangeRuleCommandProvider {
{ min, max },
);
if (excludeId !== undefined)
queryBuilder.andWhere('rule.id != :excludeId', { excludeId });
let overlappingRules: Array<QuestionRangeRule>;
try {
@@ -80,7 +83,7 @@ export class QuestionRangeRuleCommandProvider {
throw new AppTimeoutException(err);
}
if (overlappingRules.length > (excludeSelf ? 1 : 0)) {
if (overlappingRules.length > 0) {
throw new AppException(
'questions.errors.rangeRuleIntersectionConstraint',
HttpStatus.CONFLICT,
@@ -178,9 +181,14 @@ export class QuestionRangeRuleCommandProvider {
);
}
await this.checkRangeOverlap(questionId, min, max, true);
await this.checkRangeOverlap(questionId, min, max, id);
Object.assign(questionRangeRule, updateQuestionRangeRuleDto);
const changes = { ...updateQuestionRangeRuleDto };
delete changes.question;
Object.assign(questionRangeRule, changes, {
question: { id: questionId },
questionId,
});
try {
return await this.questionRangeRulesRepository.save(questionRangeRule);