import { BaseRepository } from '@edr/api-common';
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';

import { WagonType } from './entities/wagon-type.entity';

@Injectable()
export class WagonTypesRepository extends BaseRepository<WagonType> {
  constructor(
    @InjectRepository(WagonType)
    repository: Repository<WagonType>,
  ) {
    super(repository);
  }

  findByCode(code: string): Promise<WagonType | null> {
    return this.repository.findOne({ where: { code } });
  }
}
