Skip to content

Commit

Permalink
Merge branch 'dev' into prod
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurikam2003 committed Jul 31, 2024
2 parents 2ed31f5 + 2c60c26 commit 5e854bd
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions server/src/services/PaymentServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,25 @@ 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 {
let froshCount = 0;
let userCount = 0;

if (item === 'Retreat Ticket') {
userCount = await UserModel.countDocuments({
payments: { $elemMatch: { item, expired: false } },
});
} else {
froshCount = await FroshModel.countDocuments({
payments: { $elemMatch: { item, expired: false } },
});
}

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 5e854bd

Please sign in to comment.