getting total amount for charity page and adding to cart

This commit is contained in:
Arjun Patel
2019-04-22 01:09:50 -07:00
parent 522a35b104
commit 6542b03fe1
2 changed files with 10 additions and 3 deletions
+1 -1
View File
@@ -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,
+9 -2
View File
@@ -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, {