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

import { TruckType } from './entities/truck-type.entity';

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

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