feat: add user submission functionality
This commit is contained in:
@@ -36,6 +36,7 @@ export class Question {
|
||||
content!: string;
|
||||
|
||||
@Column({ type: 'int', nullable: false })
|
||||
@Index()
|
||||
order!: number;
|
||||
|
||||
@Column({ type: 'int', default: 1 })
|
||||
@@ -51,7 +52,7 @@ export class Question {
|
||||
metadata!: QuestionMetadata;
|
||||
|
||||
@OneToMany(() => Choice, (choice) => choice.question)
|
||||
choices?: Array<Choice>;
|
||||
choices!: Array<Choice>;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt!: Date;
|
||||
|
||||
@@ -35,14 +35,6 @@ export class QuestionsCommandProvider {
|
||||
public async createOne(createQuestionDto: CreateQuestionDTO) {
|
||||
const test = await this.testsService.adminGetOne(createQuestionDto.test);
|
||||
|
||||
if (!test) {
|
||||
throw new AppException(
|
||||
'common.errors.entityNotFound',
|
||||
HttpStatus.NOT_FOUND,
|
||||
{ entity: '$t(tests.fields.test)' },
|
||||
);
|
||||
}
|
||||
|
||||
const newQuestion = this.questionsRepository.create({
|
||||
...createQuestionDto,
|
||||
test,
|
||||
@@ -81,15 +73,7 @@ export class QuestionsCommandProvider {
|
||||
}
|
||||
|
||||
if (updateQuestionDto.test) {
|
||||
const test = await this.testsService.adminGetOne(updateQuestionDto.test);
|
||||
|
||||
if (!test) {
|
||||
throw new AppException(
|
||||
'common.errors.entityNotFound',
|
||||
HttpStatus.NOT_FOUND,
|
||||
{ entity: '$t(tests.fields.test)' },
|
||||
);
|
||||
}
|
||||
await this.testsService.adminGetOne(updateQuestionDto.test);
|
||||
}
|
||||
|
||||
const type =
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { filterQuestions } from '../helpers/filter-questions.helper';
|
||||
import Utils from '@/common/utils';
|
||||
import { FindQuestionsDTO } from '../dtos/find-questions.dto';
|
||||
@@ -9,6 +9,7 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Question } from '../entities/question.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { TestsService } from '@/modules/tests/providers/tests.service';
|
||||
import { AppException } from '@/common/exceptions/app.exception';
|
||||
|
||||
@Injectable()
|
||||
export class QuestionsQueryProvider {
|
||||
@@ -33,13 +34,13 @@ export class QuestionsQueryProvider {
|
||||
let selectedTest: Test | null = null;
|
||||
|
||||
if (query.test) {
|
||||
try {
|
||||
selectedTest = await this.testsService.adminGetOne(query.test);
|
||||
} catch (err) {
|
||||
throw new AppTimeoutException(err);
|
||||
}
|
||||
selectedTest = await this.testsService.adminGetOne(query.test, {
|
||||
relations: { questions: true },
|
||||
});
|
||||
}
|
||||
|
||||
console.log(selectedTest);
|
||||
|
||||
try {
|
||||
const [questions, total] = await this.questionsRepository.findAndCount({
|
||||
where: {
|
||||
@@ -69,13 +70,25 @@ export class QuestionsQueryProvider {
|
||||
}
|
||||
|
||||
public async findOneForAdmin(id: number) {
|
||||
let question: Question | null = null;
|
||||
|
||||
try {
|
||||
return await this.questionsRepository.findOne({
|
||||
question = await this.questionsRepository.findOne({
|
||||
where: { id },
|
||||
relations: { test: true },
|
||||
relations: { test: true, rangeRules: true, choices: true },
|
||||
});
|
||||
} catch (err) {
|
||||
throw new AppTimeoutException(err);
|
||||
}
|
||||
|
||||
if (!question) {
|
||||
throw new AppException(
|
||||
'common.errors.entityNotFound',
|
||||
HttpStatus.NOT_FOUND,
|
||||
{ entity: '$t(questions.fields.question)' },
|
||||
);
|
||||
}
|
||||
|
||||
return question;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user