diff --git a/app/controllers/grant.controller.js b/app/controllers/grant.controller.js index d84b3a5..3eb76ae 100644 --- a/app/controllers/grant.controller.js +++ b/app/controllers/grant.controller.js @@ -47,7 +47,7 @@ exports.createGrant = async (req, res, next) => { } ); - const grantsOrgs = organizations.map(org => { + const grantsOrgs = await organizations.map(async org => { return { grant_id: grant.id, organization_id: org.id, diff --git a/app/controllers/organization.controller.js b/app/controllers/organization.controller.js index 98b9b6c..9c3123c 100644 --- a/app/controllers/organization.controller.js +++ b/app/controllers/organization.controller.js @@ -265,7 +265,8 @@ exports.getOrganizationById = async (req, res, next) => { p.id as project_id, p.title as project_title, p.description as project_description, - p.isComplete + p.isComplete, + ta.total_amount as total_amount from organizations as o left join ( SELECT * from projects @@ -275,8 +276,14 @@ exports.getOrganizationById = async (req, res, next) => { from projects group by organization_id ) - ) + ) as p on p.organization_id = o.id + left join ( + SELECT SUM(amount) as total_amount, organization_id + FROM grants_organizations + GROUP BY organization_id + ) + as ta on ta.organization_id = o.id WHERE o.id = :charityId `; const org = await db.sequelize.query(QUERY, {