import mongoose from 'mongoose';

import { ILoanPaymentDoc, LoanPaymentModel } from '../models/LoanPayment.model';

export const getPaymentForTransaction = async (productId: string, transactionId: string) => {
  const payments = await LoanPaymentModel.aggregate<ILoanPaymentDoc>([
    {
      $match: {
        'productId': new mongoose.Types.ObjectId(productId),
        'paid.statementId': new mongoose.Types.ObjectId(transactionId),
      },
    },
  ]);
  if (payments.length === 0) {
    return [];
  }
  return payments;
}
