Various queries now properly include child campaigns
This commit is contained in:
parent
216cefaa98
commit
8a78fad0c7
4 changed files with 36 additions and 15 deletions
|
@ -7,7 +7,17 @@ module.exports = function(npo_id) {
|
||||||
|
|
||||||
request.get(campaignsPath).end(function(err, resp){
|
request.get(campaignsPath).end(function(err, resp){
|
||||||
resp.body.unshift(false)
|
resp.body.unshift(false)
|
||||||
appl.def('campaigns.data', resp.body)
|
let campaign_id_names = resp.body.map((i) => {
|
||||||
|
if (i.isChildCampaign)
|
||||||
|
{
|
||||||
|
return {id: i.id, name: i.name + " - " + i.creator}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return {id: i.id, name: i.name}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
appl.def('campaigns.data', campaign_id_names)
|
||||||
})
|
})
|
||||||
request.get(eventsPath).end(function(err, resp){
|
request.get(eventsPath).end(function(err, resp){
|
||||||
resp.body.unshift(false)
|
resp.body.unshift(false)
|
||||||
|
|
|
@ -50,7 +50,7 @@ module QueryCampaigns
|
||||||
["payments AS onetime", "onetime.id=payments.id AND onetime.kind='Donation'"],
|
["payments AS onetime", "onetime.id=payments.id AND onetime.kind='Donation'"],
|
||||||
["payments AS offsite", "offsite.id=payments.id AND offsite.kind='OffsitePayment'"],
|
["payments AS offsite", "offsite.id=payments.id AND offsite.kind='OffsitePayment'"],
|
||||||
["payments AS recurring", "recurring.id=payments.id AND recurring.kind='RecurringDonation'"])
|
["payments AS recurring", "recurring.id=payments.id AND recurring.kind='RecurringDonation'"])
|
||||||
.where("donations.campaign_id" => campaign_id)
|
.where("donations.campaign_id IN (#{QueryCampaigns.get_campaign_and_children(campaign_id).parse})")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,15 +62,18 @@ module QueryCampaigns
|
||||||
|
|
||||||
|
|
||||||
def self.name_and_id(npo_id)
|
def self.name_and_id(npo_id)
|
||||||
Psql.execute(
|
|
||||||
Qexpr.new.select(
|
np = Nonprofit.find(npo_id)
|
||||||
"campaigns.name",
|
campaigns = np.campaigns.not_deleted.includes(:profile).order('campaigns.name ASC')
|
||||||
"campaigns.id")
|
output = campaigns.map do |i|
|
||||||
.from("campaigns")
|
{
|
||||||
.where("campaigns.nonprofit_id=$id", id: npo_id)
|
'name' => i.name,
|
||||||
.where("campaigns.deleted='f' OR campaigns.deleted IS NULL")
|
'id' => i.id,
|
||||||
.order_by("campaigns.name ASC")
|
'isChildCampaign' => i.child_campaign?,
|
||||||
)
|
'creator' => i.profile&.name || "user ##{i.profile.id}"
|
||||||
|
}
|
||||||
|
end
|
||||||
|
output
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_campaign_and_children(campaign_id)
|
def self.get_campaign_and_children(campaign_id)
|
||||||
|
|
|
@ -19,7 +19,9 @@ module QueryDonations
|
||||||
.join(:supporters, "supporters.id=donations.supporter_id")
|
.join(:supporters, "supporters.id=donations.supporter_id")
|
||||||
.left_outer_join(:campaign_gifts, "campaign_gifts.donation_id=donations.id")
|
.left_outer_join(:campaign_gifts, "campaign_gifts.donation_id=donations.id")
|
||||||
.left_outer_join(:campaign_gift_options, "campaign_gift_options.id=campaign_gifts.campaign_gift_option_id")
|
.left_outer_join(:campaign_gift_options, "campaign_gift_options.id=campaign_gifts.campaign_gift_option_id")
|
||||||
.where("donations.campaign_id=$id", id: campaign_id)
|
.where("donations.campaign_id IN (#{QueryCampaigns
|
||||||
|
.get_campaign_and_children(campaign_id)
|
||||||
|
.parse})")
|
||||||
.group_by("donations.id", "supporters.id")
|
.group_by("donations.id", "supporters.id")
|
||||||
.order_by("donations.date")
|
.order_by("donations.date")
|
||||||
)
|
)
|
||||||
|
@ -27,7 +29,9 @@ module QueryDonations
|
||||||
|
|
||||||
def self.for_campaign_activities(id)
|
def self.for_campaign_activities(id)
|
||||||
QueryDonations.activities_expression(['donations.recurring'])
|
QueryDonations.activities_expression(['donations.recurring'])
|
||||||
.where('donations.campaign_id=$id', id: id)
|
.where("donations.campaign_id IN (#{QueryCampaigns
|
||||||
|
.get_campaign_and_children(id)
|
||||||
|
.parse})")
|
||||||
.execute
|
.execute
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,9 @@ module QuerySupporters
|
||||||
.left_outer_join('campaign_gifts', 'donations.id=campaign_gifts.donation_id')
|
.left_outer_join('campaign_gifts', 'donations.id=campaign_gifts.donation_id')
|
||||||
.left_outer_join('campaign_gift_options', 'campaign_gifts.campaign_gift_option_id=campaign_gift_options.id')
|
.left_outer_join('campaign_gift_options', 'campaign_gifts.campaign_gift_option_id=campaign_gift_options.id')
|
||||||
.where("supporters.nonprofit_id=$id", id: np_id)
|
.where("supporters.nonprofit_id=$id", id: np_id)
|
||||||
.where("donations.campaign_id=$id", id: campaign_id)
|
.where("donations.campaign_id IN (#{QueryCampaigns
|
||||||
|
.get_campaign_and_children(campaign_id)
|
||||||
|
.parse})")
|
||||||
.group_by('supporters.id')
|
.group_by('supporters.id')
|
||||||
.order_by('MAX(donations.date) DESC')
|
.order_by('MAX(donations.date) DESC')
|
||||||
|
|
||||||
|
@ -253,7 +255,9 @@ module QuerySupporters
|
||||||
expr = expr.and_where("tags.ids @> ARRAY[$tag_ids]", tag_ids: tag_ids)
|
expr = expr.and_where("tags.ids @> ARRAY[$tag_ids]", tag_ids: tag_ids)
|
||||||
end
|
end
|
||||||
if query[:campaign_id].present?
|
if query[:campaign_id].present?
|
||||||
expr = expr.add_join("donations", "donations.supporter_id=supporters.id AND donations.campaign_id=#{query[:campaign_id].to_i}")
|
expr = expr.add_join("donations", "donations.supporter_id=supporters.id AND donations.campaign_id IN (#{QueryCampaigns
|
||||||
|
.get_campaign_and_children(query[:campaign_id].to_i)
|
||||||
|
.parse})")
|
||||||
end
|
end
|
||||||
|
|
||||||
if query[:event_id].present?
|
if query[:event_id].present?
|
||||||
|
|
Loading…
Reference in a new issue