properly adding the fields needed in frontend
This commit is contained in:
@@ -108,7 +108,10 @@ exports.findGrantsByDonorId = async (req, res, next) => {
|
|||||||
g.num_regions,
|
g.num_regions,
|
||||||
g.donor_id,
|
g.donor_id,
|
||||||
GROUP_CONCAT(DISTINCT o.id SEPARATOR ',') AS organization_ids,
|
GROUP_CONCAT(DISTINCT o.id SEPARATOR ',') AS organization_ids,
|
||||||
GROUP_CONCAT(DISTINCT o.name SEPARATOR ',') AS organization_names
|
GROUP_CONCAT(DISTINCT o.name SEPARATOR ',') AS organization_names,
|
||||||
|
GROUP_CONCAT(DISTINCT o.primary_cause SEPARATOR ',') AS causes,
|
||||||
|
GROUP_CONCAT(DISTINCT o.primary_region SEPARATOR ',') AS regions,
|
||||||
|
GROUP_CONCAT(go.amount SEPARATOR ',') AS amounts
|
||||||
from grants as g
|
from grants as g
|
||||||
inner join GrantOrganizations as go on go.grant_id = g.id
|
inner join GrantOrganizations as go on go.grant_id = g.id
|
||||||
left join organizations as o on o.id = go.organization_id
|
left join organizations as o on o.id = go.organization_id
|
||||||
@@ -118,18 +121,29 @@ exports.findGrantsByDonorId = async (req, res, next) => {
|
|||||||
{ type: db.sequelize.QueryTypes.SELECT, replacements: { donor_id } }
|
{ type: db.sequelize.QueryTypes.SELECT, replacements: { donor_id } }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// adding in the organizations, causes, and regions for each grant into arrays
|
||||||
grants.map(grant => {
|
grants.map(grant => {
|
||||||
grant.organizations = [];
|
let org_ids = grant.organization_ids.toString().split(",");
|
||||||
|
let org_names = grant.organization_names.toString().split(",");
|
||||||
|
let causes = grant.causes.toString().split(",");
|
||||||
|
let regions = grant.regions.toString().split(",");
|
||||||
|
let amounts = grant.amounts.toString().split(",");
|
||||||
|
|
||||||
org_ids = grant.organization_ids.toString().split(",");
|
grant.organizations = [];
|
||||||
org_names = grant.organization_names.toString().split(",");
|
grant.causes = [];
|
||||||
|
grant.regions = [];
|
||||||
|
|
||||||
for (var i = 0; i < org_names.length; i++) {
|
for (var i = 0; i < org_names.length; i++) {
|
||||||
grant.organizations.push({
|
grant.organizations.push({
|
||||||
id: org_ids[i],
|
id: org_ids[i],
|
||||||
name: org_names[i]
|
name: org_names[i],
|
||||||
|
amount: parseInt(amounts[i])
|
||||||
});
|
});
|
||||||
|
causes[i] ? grant.causes.push({ name: causes[i] }) : null;
|
||||||
|
regions[i] ? grant.regions.push({ name: regions[i] }) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
grant.monthly = grant.monthly == 1 ? true : false;
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
|
|||||||
Reference in New Issue
Block a user