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

import { Consignment } from "./entities/consignment.entity";

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

  /** Look up a consignment by its tracking number. */
  findByTrackingNumber(trackingNumber: string): Promise<Consignment | null> {
    return this.repository.findOne({ where: { trackingNumber } });
  }
}
