import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { AuditType } from './../audit-types/entities/audit-type.entity';
import { CreateAuditTypeDto } from './dto/create-audit-type.dto';
import { UpdateAuditTypeDto } from './dto/update-audit-type.dto';

@Injectable()
export class AuditTypesService {
  constructor(
    @InjectRepository(AuditType, 'certification_db')
    private readonly auditTypeRepository: Repository<AuditType>,
  ) {}

  async create(createAuditTypeDto: CreateAuditTypeDto) {
    const auditType = this.auditTypeRepository.create(createAuditTypeDto);
    return await this.auditTypeRepository.save(auditType);
  }

  async findAll() {
    return await this.auditTypeRepository.find();
  }

  async findOne(id: number) {
    return await this.auditTypeRepository.findOne({ where: { id } });
  }

  async update(id: number, updateAuditTypeDto: UpdateAuditTypeDto) {
    await this.auditTypeRepository.update(id, updateAuditTypeDto);
    return this.findOne(id);
  }

  async remove(id: number) {
    return await this.auditTypeRepository.delete(id);
  }
}
