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

import { Customer } from "./entities/customer.entity";

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

  /** Find a customer by their unique email. */
  findByEmail(email: string): Promise<Customer | null> {
    return this.repository.findOne({ where: { email } });
  }
}
