diff --git a/app/controllers/organization.controller.js b/app/controllers/organization.controller.js index ec71770..98b9b6c 100644 --- a/app/controllers/organization.controller.js +++ b/app/controllers/organization.controller.js @@ -198,8 +198,8 @@ exports.getAllOrganizations = async (req, res, next) => { from projects group by organization_id ) - ) - as p on p.organization_id = o.id + ) as p on p.organization_id = o.id + where o.is_verified = 1 and o.stripe_account_id IS NOT NULL `; const organizations = await db.sequelize.query(QUERY, { type: db.Sequelize.QueryTypes.SELECT @@ -217,11 +217,31 @@ exports.searchOrganizations = (req, res, next) => { search = '%' + search + '%'; const limit = 10; - const QUERY = `SELECT * from organizations - WHERE name LIKE :search or - primary_cause LIKE :search or - primary_region LIKE :search - LIMIT :limit`; + const QUERY = ` + select + o.*, + p.id as project_id, + p.title as project_title, + p.description as project_description, + p.isComplete + from organizations as o + left join ( + SELECT * from projects + where id in ( + select + max(id) + from projects + group by organization_id + ) + ) as p on p.organization_id = o.id + WHERE o.is_verified = 1 and o.stripe_account_id IS NOT NULL + and (o.name LIKE :search or + o.primary_cause LIKE :search or + o.primary_region LIKE :search or + p.title LIKE :search) + LIMIT :limit + `; + db.sequelize .query(QUERY, { replacements: { search, limit }, diff --git a/app/controllers/stripe.controller.js b/app/controllers/stripe.controller.js index 669401c..3e0a1cd 100644 --- a/app/controllers/stripe.controller.js +++ b/app/controllers/stripe.controller.js @@ -29,7 +29,7 @@ exports.grantCharge = async ({ source: 'tok_visa', description: `Charity Bundle Payment`, statement_descriptor: `charity bundle ${grant.id}`, - receipt_email: 'arjun@ucharify.com' + receipt_email: donors[0].email }); let transfers = await organizations.map(async org => { @@ -40,7 +40,7 @@ exports.grantCharge = async ({ amount: stripeOrgAmount - applicationStripeFee, currency: 'usd', source_transaction: charge.id, - destination: 'acct_1EAxzUIVW1uo07uH' + destination: org.stripe_account_id }); return t; });