import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { CreateQuestionTypeDto } from 'src/assessment-evaluation/dto/dtos-question-manager/question-type/create-question-type.dto';
import { UpdateQuestionTypeDto } from 'src/assessment-evaluation/dto/dtos-question-manager/question-type/update-question-type.dto';
import { QuestionType } from 'src/assessment-evaluation/entities/entities-question-manager/question-type.entity';

@Injectable()
export class QuestionTypeService {
  constructor(
    @InjectRepository(QuestionType)
    private questionTypeRepository: Repository<QuestionType>,
  ) {}

  /* 
    创建试题类型
  */
  async create(createQuestionTypeDto: CreateQuestionTypeDto) {
    await this.questionTypeRepository.insert(createQuestionTypeDto);
    return true;
  }
  /* 
    查找所有试题类型
  */
  async findAll() {
    return this.questionTypeRepository.find({
      select: ['id', 'name', 'element'],
      where: { delFlag: 0 },
    });
  }
  /* 
    更新试题类型
  */
  async update(id: number, updateQuestionTypeDto: UpdateQuestionTypeDto) {
    return this.questionTypeRepository.update(id, updateQuestionTypeDto);
  }
  /* 
    删除试题类型
  */
  async remove(id: number) {
    await this.questionTypeRepository.update(id, { delFlag: 1 });
    return true;
  }
}
