in process of scaling data service and cleaner reducers
This commit is contained in:
@@ -34,9 +34,11 @@ exports.create = (req, res, next) => {
|
|||||||
|
|
||||||
// Find grants with causes, regions, and organizations by donor_id
|
// Find grants with causes, regions, and organizations by donor_id
|
||||||
exports.findByDonorId = (req, res, next) => {
|
exports.findByDonorId = (req, res, next) => {
|
||||||
|
const donor_id = req.user_data.id;
|
||||||
|
|
||||||
Grant.findAll({
|
Grant.findAll({
|
||||||
where: {
|
where: {
|
||||||
donor_id: req.params.donor_id
|
donor_id: donor_id
|
||||||
},
|
},
|
||||||
include: [Cause, Region, Organization]
|
include: [Cause, Region, Organization]
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -5,10 +5,12 @@ module.exports = (req, res, next) => {
|
|||||||
try {
|
try {
|
||||||
const token = req.headers.authorization.split(' ')[1];
|
const token = req.headers.authorization.split(' ')[1];
|
||||||
const decoded = jwt.verify(token, process.env.JWT_KEY);
|
const decoded = jwt.verify(token, process.env.JWT_KEY);
|
||||||
req.userData = decoded; //for use till end of request
|
req.user_data = decoded; //for use till end of request
|
||||||
|
|
||||||
next();
|
next();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
error.message = 'Check Auth Error';
|
||||||
|
error.status = 401;
|
||||||
return next(error);
|
return next(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ router.post('/', controllers.donor.create);
|
|||||||
router.get('/', checkAuth, controllers.donor.findAll);
|
router.get('/', checkAuth, controllers.donor.findAll);
|
||||||
|
|
||||||
// GET Retrieve grants with causes and regions and charities details by donor_id
|
// GET Retrieve grants with causes and regions and charities details by donor_id
|
||||||
router.get('/grants/:donor_id', checkAuth, controllers.grant.findByDonorId);
|
router.get('/grants/', checkAuth, controllers.grant.findByDonorId);
|
||||||
|
|
||||||
/** POST Create grants with following body:
|
/** POST Create grants with following body:
|
||||||
* - list of id's of selected causes and regions
|
* - list of id's of selected causes and regions
|
||||||
|
|||||||
Reference in New Issue
Block a user