starting fix for getGrantsByDonor

This commit is contained in:
Arjun Patel
2019-03-23 04:20:37 -07:00
parent 76e4a20fec
commit 9c42496e22
+29 -13
View File
@@ -93,22 +93,38 @@ exports.createGrant = async (req, res, next) => {
}; };
// Find grants with causes, regions, and organizations by donor_id // Find grants with causes, regions, and organizations by donor_id
exports.findGrantsByDonorId = (req, res, next) => { exports.findGrantsByDonorId = async (req, res, next) => {
const donor_id = req.user.id; const donor_id = req.user.id;
Grant.findAll({ try {
where: { const grants = await db.sequelize.query(`
donor_id: donor_id Select
}, g.id,
include: [Cause, Region, Organization] g.name,
}) g.amount,
.then(grants => { g.monthly,
res.status(200).json({ g.num_causes,
grants, g.num_regions,
number_items: grants.length g.donor_id,
}); g.created_at,
g.updated_at,
o.id as organization_id,
o.primary_cause,
o.primary_region
from grants as g
left join GrantOrganizations as go on go.grant_id = g.id
left join organizations as o on go.organization_id = o.id
where donor_id = "0568eef6-f3cb-480b-933c-d32d540bface";
`, {
type: db.sequelize.QueryTypes.SELECT
});
return res.status(200).json({
grants
}) })
.catch(error => next(error)); } catch (error) {
next(error);
}
}; };
exports.deleteGrant = (req, res, next) => { exports.deleteGrant = (req, res, next) => {