import { AbstractRepository } from "./AbstractRepository.js";
import { UserEntity } from "../entities/UserEntity.js";

export class UserRepository extends AbstractRepository<UserEntity> {
  constructor() {
    super(UserEntity);
  }

  async findByUserName(userName: string): Promise<UserEntity | null> {
    return this.repo.findOne({ where: { userName } });
  }

    /**
     * Find all users
     * @returns Array of all UserEntity records
     */
    async findAll(): Promise<UserEntity[]> {
        return await this.repo.find({
            order: {
                lastName: "ASC",
                firstName: "ASC",
            },
        });
    }
}
