Skip to content

Commit

Permalink
Support strengths prop filtering by PS code in Organisations GET
Browse files Browse the repository at this point in the history
endpoint

[Re #1611]

We need to filter the strengths count according to the provided PS iso
code from the params, so only those bookmarked initiatives for the
given PS are taking into account when the PS iso code is provided. In
this case, we do not count again same bookmarks for different sections,
as it is only relevant the PS used to bookmark those initiatives.
  • Loading branch information
joseAyudarte91 committed Nov 6, 2023
1 parent d06f5e1 commit 2fba517
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 17 additions & 0 deletions backend/src/gpml/db/organisation.clj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@
) FILTER (WHERE oba.badge_id IS NOT NULL),
'[]'::jsonb) AS assigned_badges,")))

(defn list-organisations-strengths-cto
[{:keys [plastic-strategy-id]}]
(let [bookmarked-initiatives-join (if-not plastic-strategy-id
""
(format
"INNER JOIN plastic_strategy_initiative_bookmark psib
ON (oi.initiative = psib.initiative_id AND psib.plastic_strategy_id = %d)"
plastic-strategy-id))]
(format "SELECT oi.organisation, %s AS initiative
FROM organisation_initiative oi
%s
WHERE oi.association IN ('owner', 'implementor', 'donor', 'partner')"
(if-not plastic-strategy-id
"oi.initiative"
"psib.initiative_id")
bookmarked-initiatives-join)))

(defn list-organisations-cto-query-filter-and-params
[params]
(let [{:keys [filters plastic-strategy-id]} params
Expand Down
4 changes: 1 addition & 3 deletions backend/src/gpml/db/organisation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ WHERE 1=1
-- :name list-organisations :query :many
-- :doc List organisations with advanced filtering (for PSW mainly)
WITH organisations_strengths_cte AS (
SELECT organisation, initiative
FROM organisation_initiative
WHERE association IN ('owner', 'implementor', 'donor', 'partner')
--~ (#'gpml.db.organisation/list-organisations-strengths-cto params)
),
organisations_cte AS (
SELECT
Expand Down

0 comments on commit 2fba517

Please sign in to comment.