cleanup for getting verified charities and also proper sendgrid and org transfer for payments
This commit is contained in:
@@ -198,8 +198,8 @@ exports.getAllOrganizations = async (req, res, next) => {
|
|||||||
from projects
|
from projects
|
||||||
group by organization_id
|
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, {
|
const organizations = await db.sequelize.query(QUERY, {
|
||||||
type: db.Sequelize.QueryTypes.SELECT
|
type: db.Sequelize.QueryTypes.SELECT
|
||||||
@@ -217,11 +217,31 @@ exports.searchOrganizations = (req, res, next) => {
|
|||||||
search = '%' + search + '%';
|
search = '%' + search + '%';
|
||||||
const limit = 10;
|
const limit = 10;
|
||||||
|
|
||||||
const QUERY = `SELECT * from organizations
|
const QUERY = `
|
||||||
WHERE name LIKE :search or
|
select
|
||||||
primary_cause LIKE :search or
|
o.*,
|
||||||
primary_region LIKE :search
|
p.id as project_id,
|
||||||
LIMIT :limit`;
|
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
|
db.sequelize
|
||||||
.query(QUERY, {
|
.query(QUERY, {
|
||||||
replacements: { search, limit },
|
replacements: { search, limit },
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ exports.grantCharge = async ({
|
|||||||
source: 'tok_visa',
|
source: 'tok_visa',
|
||||||
description: `Charity Bundle Payment`,
|
description: `Charity Bundle Payment`,
|
||||||
statement_descriptor: `charity bundle ${grant.id}`,
|
statement_descriptor: `charity bundle ${grant.id}`,
|
||||||
receipt_email: '[email protected]'
|
receipt_email: donors[0].email
|
||||||
});
|
});
|
||||||
|
|
||||||
let transfers = await organizations.map(async org => {
|
let transfers = await organizations.map(async org => {
|
||||||
@@ -40,7 +40,7 @@ exports.grantCharge = async ({
|
|||||||
amount: stripeOrgAmount - applicationStripeFee,
|
amount: stripeOrgAmount - applicationStripeFee,
|
||||||
currency: 'usd',
|
currency: 'usd',
|
||||||
source_transaction: charge.id,
|
source_transaction: charge.id,
|
||||||
destination: 'acct_1EAxzUIVW1uo07uH'
|
destination: org.stripe_account_id
|
||||||
});
|
});
|
||||||
return t;
|
return t;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user