import { BorrowerModel } from '../models/Borrower.model';
import { IUserAccess } from '../interfaces/auth-user.interface';

export class BorrowersDB {
  async getAllBorrowers() {
    return BorrowerModel.find().sort({ name: 1 }).lean();
  }

  async getActiveBorrowers() {
    return BorrowerModel.find({ active: true }).sort({ name: 1 }).lean();
  }

  async getAllowedBorrowers(user: IUserAccess) {
    return BorrowerModel
      .find(user.allBorrowers ? {} : { '_id': { $in: user.borrowersAccess } })
      .collation({ locale: 'en' })
      .sort({ code: 1 })
      .lean();
  }
}
