-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return deep proposal json for proposal queries
This is the big one... We're changing the way we populate deep proposals, leveraging psql directly instead of putting that burden on the application. We may find that there are optimizations to be made in future, but this removes a large amount of complexity from the application. As part of this we are also improving the deep object so that it includes the base field information directly, meaning a client won't need to load a list of base fields in order to understand the context of an application form field. Issue #821 Change our query approach to use DB-level json functions
- Loading branch information
Showing
26 changed files
with
276 additions
and
853 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
export * from './db'; | ||
export * from './enrichers'; | ||
export * from './migrate'; | ||
export * from './operations'; | ||
export * from './parameters'; |
21 changes: 21 additions & 0 deletions
21
src/database/initialization/application_form_field_to_json.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
CREATE OR REPLACE FUNCTION application_form_field_to_json(application_form_field application_form_fields) | ||
RETURNS JSONB AS $$ | ||
DECLARE | ||
base_field_json JSONB; | ||
BEGIN | ||
SELECT base_field_to_json(base_fields.*) | ||
INTO base_field_json | ||
FROM base_fields | ||
WHERE base_fields.id = application_form_field.base_field_id; | ||
|
||
RETURN jsonb_build_object( | ||
'id', application_form_field.id, | ||
'applicationFormId', application_form_field.application_form_id, | ||
'baseFieldId', application_form_field.base_field_id, | ||
'baseField', base_field_json, | ||
'position', application_form_field.position, | ||
'label', application_form_field.label, | ||
'createdAt', application_form_field.created_at | ||
); | ||
END; | ||
$$ LANGUAGE plpgsql; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
CREATE OR REPLACE FUNCTION organization_to_json(organization organizations) | ||
RETURNS JSONB AS $$ | ||
DECLARE | ||
proposals_json JSONB; | ||
BEGIN | ||
SELECT jsonb_agg( | ||
proposal_to_json(proposals.*) | ||
ORDER BY proposals.id DESC | ||
) | ||
INTO proposals_json | ||
FROM proposals | ||
JOIN organizations_proposals ON organizations_proposals.proposal_id = proposal.id | ||
WHERE organizations_proposals.organization_id = organization.id; | ||
|
||
RETURN jsonb_build_object( | ||
'id', organization.id, | ||
'employerIdentificationNumber', organization.employer_identification_number, | ||
'name', organization.name, | ||
'proposals', COALESCE(proposals_json, '[]'::JSONB), | ||
'createdAt', organization.created_at | ||
); | ||
END; | ||
$$ LANGUAGE plpgsql; |
Oops, something went wrong.