Skip to content

Commit

Permalink
pls work
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurikam2003 committed Jul 31, 2024
1 parent 7939acd commit c2be9b6
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions server/src/services/PaymentServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
},

/**
Expand Down

0 comments on commit c2be9b6

Please sign in to comment.