feat: add admin panel dto & validation
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user