import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { IsNull, Repository } from 'typeorm';
import { GeneDetailModel } from './entities/gene-detail.entity';

@Injectable()
export class GeneService {
  constructor(
    @InjectRepository(GeneDetailModel)
    private readonly geneDetailRepository: Repository<GeneDetailModel>,
  ) {}

  /**
   * 개체식별번호(cowId)로 유전자 상세 정보 조회
   * @param cowId 개체식별번호 (KOR...)
   * @returns 유전자 상세 정보 배열
   */
  async findByCowId(cowId: string): Promise<GeneDetailModel[]> {
    return await this.geneDetailRepository.find({
      where: {
        cowId,
        delDt: IsNull(),
      },
      order: {
        chromosome: 'ASC',
        position: 'ASC',
      },
    });
  }
}
