Skip to content

Commit

Permalink
chore: spec work
Browse files Browse the repository at this point in the history
  • Loading branch information
BCerki committed Jul 19, 2023
1 parent cace7ff commit 86f2b2e
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ begin
(fc.new_form_data->>'dateSentToCsnr')::timestamptz
);

-- brianna is it this then? it sets it wrong? because it looks like it goes in right so it must be changed later. this is on create so that doesn't make sense
raise notice 'reporting_requirement_record_id: %', reporting_requirement_record_id;

update cif.form_change set form_data_record_id = reporting_requirement_record_id where id = fc.id;



elsif fc.operation = 'update' then

update cif.reporting_requirement rr set
Expand All @@ -67,6 +72,10 @@ begin
date_sent_to_csnr = (fc.new_form_data->>'dateSentToCsnr')::timestamptz
where py.reporting_requirement_id = fc.form_data_record_id;


-- brianna the first update doesn't get a form_data record id, I think it should, all the project ones have the same one


elsif fc.operation = 'archive' then

update cif.reporting_requirement set archived_at = now() where id = fc.form_data_record_id;
Expand Down
2 changes: 1 addition & 1 deletion schema/deploy/functions/raise_exception.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

begin;

create or replace function cif_private.raise_exception(text) returns text as
create or replace function cif_private.raise_exception(numeric) returns text as
$$
begin
raise exception '%',$1;
Expand Down
15 changes: 14 additions & 1 deletion schema/deploy/mutations/create_form_change.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

begin;

create function cif.create_form_change(
create or replace function raise_notice (s numeric) language plpgsql as
$$
begin
raise notice '%', s;
end;
$$;

create or replace function cif.create_form_change(
operation cif.form_change_operation,
json_schema_name varchar(1000),
form_data_schema_name varchar(1000),
Expand All @@ -13,6 +20,10 @@ create function cif.create_form_change(
change_status varchar(1000) default 'pending',
validation_errors jsonb default '[]'
) returns cif.form_change as $create_form_change$


cif_private.raise_exception(form_data_record_id);

insert into cif.form_change(
new_form_data,
operation,
Expand All @@ -24,6 +35,7 @@ create function cif.create_form_change(
json_schema_name,
validation_errors
) values (
-- brianna here it must be grabbing an old form change instead of the latest committed one
coalesce(new_form_data, (
select new_form_data
from cif.form_change
Expand All @@ -37,6 +49,7 @@ create function cif.create_form_change(
operation,
form_data_schema_name,
form_data_table_name,
-- or here?
form_data_record_id,
project_revision_id,
change_status,
Expand Down
11 changes: 9 additions & 2 deletions schema/deploy/mutations/create_project_revision.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ declare
revision_row cif.project_revision;
form_change_record record;
_amendment_type varchar(1000);
brianna cif.form_change;
begin
insert into cif.project_revision(project_id, change_status, revision_type, revision_status)
-- conditionally set revision_status to `In Discussion` if revision_type is Amendment otherwise set it to `Draft`
Expand Down Expand Up @@ -160,12 +161,18 @@ begin
operation => form_change_record.operation,
form_data_schema_name => 'cif',
form_data_table_name => form_change_record.form_data_table_name,
-- first update doesn't get this, I think it should cause other forms do
form_data_record_id => form_change_record.id,
project_revision_id => revision_row.id,
json_schema_name => form_change_record.json_schema_name
);
) ;
raise notice '!!!!!!!!!!!!!form_change_record.operation:%',form_change_record.operation;
raise notice '!!!!!!!!!!!!!form_change_record.form_data_table_name:%',form_change_record.form_data_table_name;
raise notice '!!!!!!!!!!!!!revision_row.id:%',revision_row.id;

raise notice '!!!!!!!!!!!!!form_change_record.json_schema_name:%',form_change_record.json_schema_name;
raise notice '!!!!!!!!!!!!!form_change_record.id:%',form_change_record.id;
end loop;

return revision_row;
end;
$function$ language plpgsql strict;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
-- Deploy cif:trigger_functions/set_previous_form_change_id to pg
-- requires: tables/form_change


-- brianna it sets the project summary report previus form change id off the first one
begin;
create or replace function cif_private.set_previous_form_change_id()
returns trigger as $$
begin

raise notice 'new: %',new;

new.previous_form_change_id = (
select id from cif.form_change
where form_data_schema_name = new.form_data_schema_name
Expand Down
40 changes: 31 additions & 9 deletions schema/test/unit/mutations/create_project_revision_test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,18 @@ select results_eq(

select results_eq(
$$
select new_form_data from cif.form_change
select form_data_record_id, previous_form_change_id, new_form_data from cif.form_change
where form_data_table_name = 'project' and project_revision_id = 2
$$,
$$
select '{
values(1,1, '{
"projectName": "name",
"summary": "lorem ipsum",
"fundingStreamRfpId": 1,
"projectStatusId": 1,
"proposalReference": "1235",
"operatorId": 1
}'::jsonb
}'::jsonb)
$$,
'creating a new project revision should create a form_change record for the project'
);
Expand Down Expand Up @@ -241,15 +241,18 @@ select is_empty(
'creating a new project revision should not create a form_change record for the project_contact'
);




select results_eq(
$$
select new_form_data, json_schema_name from cif.form_change
select form_data_record_id, previous_form_change_id, new_form_data, json_schema_name from cif.form_change
where form_data_table_name = 'reporting_requirement' and project_revision_id = 2
order by json_schema_name
$$,
$$
values
('{
(3,5,'{
"projectId":1,
"adjustedEmissionsIntensityPerformance": 98,
"baselineEmissionIntensity": 324.25364,
Expand All @@ -267,12 +270,13 @@ select results_eq(
"targetEmissionIntensity": 23.2357,
"totalLifetimeEmissionReduction": 44.4224
}'::jsonb, 'emission_intensity'::varchar),
('{
(1,3,'{
"projectId":1,
"reportType": "General Milestone",
"reportingRequirementIndex": 1
}'::jsonb, 'milestone'::varchar),
('{
-- brianna change this later to 4 I think
(null,6,'{
"projectId":1,
"reportType": "Project Summary Report",
"reportDueDate": "2021-08-31 14:24:46.318423-07",
Expand All @@ -283,13 +287,13 @@ select results_eq(
"paymentNotes": "payment notes",
"dateSentToCsnr": "2021-08-29 14:24:46.318423-07"
}'::jsonb, 'project_summary_report'::varchar),
('{
(2,4,'{
"projectId":1,
"reportType": "Annual",
"reportingRequirementIndex": 1
}'::jsonb, 'reporting_requirement'::varchar)
$$,
'creating a new project revision should create a form_change record for the reporting_requirement, for the milestone schema, generic reporting_requirement schema, emission_intensity and project_summary_report schemas'
'creating a new project revision should create a form_change record for the reporting_requirement, for the milestone schema, generic reporting_requirement schema, emission_intensity and project_summary_report schemas'
);

select results_eq(
Expand Down Expand Up @@ -350,5 +354,23 @@ select lives_ok(
'allows creating a pending General Revision on a project with a pending Amendment'
);

select '-----------';
select form_data_record_id, previous_form_change_id, new_form_data, json_schema_name from cif.form_change
where form_data_table_name = 'reporting_requirement' and project_revision_id = 2
order by form_data_record_id;
select '-----------';

select '-----------';
select form_data_record_id, previous_form_change_id, new_form_data
-- there is no form_data_record_id 4 for some reason
where form_data_record_id = 4
and form_data_schema_name = 'cif'
and form_data_table_name = 'reporting_requirement'
and json_schema_name='project_summary_report'
and change_status = 'committed'
order by updated_at desc, id desc;
-- limit 1;
select '-----------';

select finish();
rollback;

0 comments on commit 86f2b2e

Please sign in to comment.