enable disable and enable monthly grant
This commit is contained in:
@@ -150,21 +150,48 @@ exports.getGrantsByDonorId = async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.deleteGrant = (req, res, next) => {
|
exports.cancelMonthlyGrant = async (req, res, next) => {
|
||||||
const { grant_id } = req.body;
|
const { grant_id } = req.params;
|
||||||
const user = req.user;
|
|
||||||
|
|
||||||
Grant.destroy({ where: { id: grant_id, donor_id: user.id } })
|
try {
|
||||||
.then(result => {
|
await db.sequelize.query(
|
||||||
var message = 'Already Deleted';
|
`
|
||||||
if (result) {
|
UPDATE grants
|
||||||
message = 'Grant Deleted';
|
SET monthly = 0
|
||||||
|
WHERE Id = :grant_id`,
|
||||||
|
{
|
||||||
|
type: db.sequelize.QueryTypes.UPDATE,
|
||||||
|
replacements: { grant_id }
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
|
||||||
res.status(201).json({
|
return res.status(200).json({
|
||||||
result,
|
message: 'Successfully cancelled grant monthly payments'
|
||||||
message
|
});
|
||||||
});
|
} catch (error) {
|
||||||
})
|
next(error);
|
||||||
.catch(error => next(error));
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.enableMonthlyGrant = async (req, res, next) => {
|
||||||
|
const { grant_id } = req.params;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await db.sequelize.query(
|
||||||
|
`
|
||||||
|
UPDATE grants
|
||||||
|
SET monthly = 1
|
||||||
|
WHERE Id = :grant_id`,
|
||||||
|
{
|
||||||
|
type: db.sequelize.QueryTypes.UPDATE,
|
||||||
|
replacements: { grant_id }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(200).json({
|
||||||
|
message: 'Successfully enabled grant monthly payments'
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -65,31 +65,31 @@ exports.grantCharge = async ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Delete grant's stripe plan under subscription
|
// Delete grant's stripe plan under subscription
|
||||||
exports.deleteGrant = async (req, res, next) => {
|
// exports.deleteGrant = async (req, res, next) => {
|
||||||
const { grant_id } = req.body;
|
// const { grant_id } = req.body;
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
const paymentPlans = await PaymentPlan.findAll({ where: { grant_id } });
|
// const paymentPlans = await PaymentPlan.findAll({ where: { grant_id } });
|
||||||
|
|
||||||
// check if there are plans for that grant
|
// // check if there are plans for that grant
|
||||||
if (!paymentPlans.length) {
|
// if (!paymentPlans.length) {
|
||||||
return res.status(400).json({
|
// return res.status(400).json({
|
||||||
message: 'Not a valid grant'
|
// message: 'Not a valid grant'
|
||||||
});
|
// });
|
||||||
} else {
|
// } else {
|
||||||
const plan = paymentPlans[0];
|
// const plan = paymentPlans[0];
|
||||||
|
|
||||||
//delete the plan/grant under the subscription for the user
|
// //delete the plan/grant under the subscription for the user
|
||||||
await stripe.subscriptionItems.del(plan.sub_item_id);
|
// await stripe.subscriptionItems.del(plan.sub_item_id);
|
||||||
//delete the plan from the main product 'Grants'
|
// //delete the plan from the main product 'Grants'
|
||||||
await stripe.plans.del(plan.plan_id);
|
// await stripe.plans.del(plan.plan_id);
|
||||||
}
|
// }
|
||||||
|
|
||||||
next();
|
// next();
|
||||||
} catch (error) {
|
// } catch (error) {
|
||||||
next(error);
|
// next(error);
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
|
||||||
// allows the org to see their stripe account with their balance and payout to their bank
|
// allows the org to see their stripe account with their balance and payout to their bank
|
||||||
exports.getExpressUILink = async (req, res, next) => {
|
exports.getExpressUILink = async (req, res, next) => {
|
||||||
|
|||||||
@@ -28,12 +28,18 @@ router.get('/grants/', checkAuth(roles.DONOR), grant.getGrantsByDonorId);
|
|||||||
* */
|
* */
|
||||||
router.post('/grants/', checkAuth(roles.DONOR), grant.createGrant);
|
router.post('/grants/', checkAuth(roles.DONOR), grant.createGrant);
|
||||||
|
|
||||||
// DELETE a grant of a donor
|
// Cancel Monthly Payment for a grant of a donor
|
||||||
router.delete(
|
router.delete(
|
||||||
'/grants/',
|
'/grants/monthly/:grant_id',
|
||||||
checkAuth(roles.DONOR),
|
checkAuth(roles.DONOR),
|
||||||
stripe.deleteGrant,
|
grant.cancelMonthlyGrant
|
||||||
grant.deleteGrant
|
);
|
||||||
|
|
||||||
|
// Enable Monthly Payment for a grant of a donor
|
||||||
|
router.post(
|
||||||
|
'/grants/monthly/:grant_id',
|
||||||
|
checkAuth(roles.DONOR),
|
||||||
|
grant.enableMonthlyGrant
|
||||||
);
|
);
|
||||||
|
|
||||||
// POST to get suggested organizations to distribute to
|
// POST to get suggested organizations to distribute to
|
||||||
|
|||||||
Reference in New Issue
Block a user