Skip to content

Commit

Permalink
Merge pull request #834 from UofT-Frosh-Orientation/changing-remainin…
Browse files Browse the repository at this point in the history
…g-tickets

fix remaining tickets
  • Loading branch information
gaurikam2003 authored Jul 31, 2024
2 parents b3e78c8 + 009a695 commit 2c60c26
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 2c60c26

Please sign in to comment.