feat: add admin panel dto & validation
This commit is contained in:
@@ -69,6 +69,11 @@ export class Test extends BaseEntity {
|
||||
@Column({ type: 'int', nullable: false, default: 0 })
|
||||
questionsCount!: number;
|
||||
|
||||
// Published questionnaires have no versioned snapshots. Keep their structure
|
||||
// immutable even after unpublishing, including for active guest sessions.
|
||||
@Column({ type: 'boolean', default: false })
|
||||
structureLocked!: boolean;
|
||||
|
||||
@OneToMany(() => ResultRange, (range) => range.test)
|
||||
resultRanges!: Array<ResultRange>;
|
||||
|
||||
|
||||
@@ -72,19 +72,21 @@ export class TestsCommandProvider {
|
||||
}
|
||||
|
||||
const accessType = updateTestDto.accessType ?? test.accessType;
|
||||
const price = updateTestDto.price ?? test.price;
|
||||
const price =
|
||||
updateTestDto.price !== undefined ? updateTestDto.price : test.price;
|
||||
|
||||
if (
|
||||
(accessType === AccessType.PAID && !price) ||
|
||||
(accessType !== AccessType.PAID && price)
|
||||
(accessType === AccessType.PAID && price == null) ||
|
||||
(accessType !== AccessType.PAID && price != null)
|
||||
) {
|
||||
throw new BadRequestException('tests.errors.priceAccessConstraint');
|
||||
}
|
||||
|
||||
Object.assign(test, updateTestDto);
|
||||
|
||||
if (updateTestDto.status === TestStatus.PUBLISHED) {
|
||||
if (test.status === TestStatus.PUBLISHED) {
|
||||
await this.publishTestValidatorProvider.validate(test.id);
|
||||
test.structureLocked = true;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user