From c2be9b605aa6786ee4c4edafb2b07e644609e1e8 Mon Sep 17 00:00:00 2001 From: Gaurika Mahajan Date: Wed, 31 Jul 2024 19:14:27 -0400 Subject: [PATCH] pls work --- server/src/services/PaymentServices.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/server/src/services/PaymentServices.js b/server/src/services/PaymentServices.js index 96fd9608..1c569b11 100644 --- a/server/src/services/PaymentServices.js +++ b/server/src/services/PaymentServices.js @@ -116,14 +116,23 @@ const PaymentServices = { * @returns {Number} number of non-expired payments for a given item */ async getNonExpiredPaymentsCountForItem(item) { - return FroshModel.countDocuments({ - payments: { $elemMatch: { item, expired: false } }, - }).then( - (count) => count, - (error) => { - throw new Error('UNABLE_TO_GET_COUNT_OF_PAYMENTS', { cause: error }); - }, - ); + try { + // Count non-expired payments for the item in FroshModel + const froshCount = await FroshModel.countDocuments({ + payments: { $elemMatch: { item, expired: false } }, + }); + + // Count non-expired payments for the item in UserModel + const userCount = await UserModel.countDocuments({ + payments: { $elemMatch: { item, expired: false } }, + }); + + // Sum the counts from both models + const totalCount = froshCount + userCount; + return totalCount; + } catch (error) { + throw new Error('UNABLE_TO_GET_COUNT_OF_PAYMENTS', { cause: error }); + } }, /**