import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ResourceClassifyDto } from '../dto/resource-classify.dto';
import { ResourceClassify } from '../entities/resource-classify.entity';

@Injectable()
export class ResourceClassifyService {
  constructor(
    @InjectRepository(ResourceClassify)
    private orgRepository: Repository<ResourceClassify>,
  ) {}

  async create(resourceClassifyDto: ResourceClassifyDto) {
    await this.orgRepository.insert(resourceClassifyDto);
    return true;
  }

  async findAll() {
    return this.orgRepository.find({
      select: ['id', 'name', 'pid'],
      where: { delFlag: 0 },
    });
  }

  async update(id: number, resourceClassifyDto: ResourceClassifyDto) {
    return this.orgRepository.update(id, resourceClassifyDto);
  }

  async remove(id: number) {
    return this.orgRepository.update(id, { delFlag: 1 });
  }
}
