Skip to content

Commit

Permalink
removed the isRegistrered requirement for retreat payment and userTyp…
Browse files Browse the repository at this point in the history
…e frosh. still need to make sure profile edit works
  • Loading branch information
gaurikam2003 committed Jul 24, 2024
1 parent db1fd5e commit 6fed0f5
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 24 deletions.
10 changes: 5 additions & 5 deletions client/src/pages/FroshRetreat/FroshRetreat.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ export const FroshRetreat = () => {
remainingTicketsSetter();
}, []);

useEffect(() => {
if (!isRegistered) {
navigate('/profile');
}
}, [isRegistered]);
// useEffect(() => {
// if (!isRegistered) {
// navigate('/profile');
// }
// }, [isRegistered]);

return (
<div className="frosh-retreat-page">
Expand Down
4 changes: 2 additions & 2 deletions server/src/controllers/PaymentController.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ const PaymentController = {
'retreat',
);

const frosh = await FroshServices.addRetreatPayment(user, payment_intent);
if (!frosh) {
const updatedUser = await FroshServices.addRetreatPayment(user, payment_intent);
if (!updatedUser) {
res.status(400).send({ message: 'Something went wrong!' });
}
res.status(200).send({ url });
Expand Down
2 changes: 1 addition & 1 deletion server/src/routes/paymentRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ router.get(
router.post(
'/frosh-retreat-payment',
checkLoggedIn,
checkUserType('frosh'),
// checkUserType('frosh'),
PaymentController.froshRetreatPayment,
);

Expand Down
55 changes: 39 additions & 16 deletions server/src/services/FroshServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,46 @@ const FroshServices = {
* @returns {User} updated user
*/
async addRetreatPayment(user, paymentIntent) {
return FroshModel.findByIdAndUpdate(user.id, {
$push: {
payments: [
{
item: 'Retreat Ticket',
paymentIntent: paymentIntent.toString(),
amountDue: 9500,
},
],
},
}).then(
(frosh) => frosh,
(error) => {
throw new Error('UNABLE_TO_ADD_PAYMENT', { cause: error });
},
);
try {
const updatedUser = await UserModel.findByIdAndUpdate(user.id, {
$push: {
payments: [
{
item: 'Retreat Ticket',
paymentIntent: paymentIntent.toString(),
amountDue: 9500,
},
],
},
}, { new: true});

if (!updatedUser){
throw new Error('user not found');
}

return updatedUser;

} catch (error) {
throw new Error('UNABLE_TO_ADD_PAYMENT', { cause: error });
}
},
// return FroshModel.findByIdAndUpdate(user.id, {
// $push: {
// payments: [
// {
// item: 'Retreat Ticket',
// paymentIntent: paymentIntent.toString(),
// amountDue: 9500,
// },
// ],
// },
// }).then(
// (frosh) => frosh,
// (error) => {
// throw new Error('UNABLE_TO_ADD_PAYMENT', { cause: error });
// },
// );
// },

/**
* @description Gets the frosh info from ID.
Expand Down

0 comments on commit 6fed0f5

Please sign in to comment.