Skip to content

Commit

Permalink
Merge pull request #3637 from bcgov/NDT-571-empty-ccbc-summary-data-e…
Browse files Browse the repository at this point in the history
…ven-if-a-sow-seems-to-be-uploaded-in-project-section

fix: add application id when archiving
  • Loading branch information
ccbc-service-account authored Oct 29, 2024
2 parents 445b47f + 2d28a09 commit e7519bf
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [1.203.3](https://github.com/bcgov/CONN-CCBC-portal/compare/v1.203.2...v1.203.3) (2024-10-29)

### Bug Fixes

- add application id when archiving ([bd19369](https://github.com/bcgov/CONN-CCBC-portal/commit/bd193693097893a7d7be4e0bd361e093cbd2c057))

## [1.203.2](https://github.com/bcgov/CONN-CCBC-portal/compare/v1.203.1...v1.203.2) (2024-10-29)

### Bug Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ const ProjectInformationForm: React.FC<Props> = ({
// archive by application id
archiveApplicationSow({
variables: {
input: { _amendmentNumber: 0 },
input: { _amendmentNumber: 0, _applicationId: rowId },
},
});
}
Expand Down
1 change: 1 addition & 0 deletions app/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -94693,6 +94693,7 @@ input ArchiveApplicationSowInput {
"""
clientMutationId: String
_amendmentNumber: Int!
_applicationId: Int!
}

"""The output of our `archiveIntake` mutation."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ describe('The ProjectInformation form', () => {
{
input: {
_amendmentNumber: 0,
_applicationId: 1,
},
}
);
Expand Down
5 changes: 3 additions & 2 deletions db/deploy/mutations/archive_application_sow.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ begin;

drop function if exists ccbc_public.archive_application_sow;

create or replace function ccbc_public.archive_application_sow(_amendment_number int)
create or replace function ccbc_public.archive_application_sow(_amendment_number int, _application_id int)
returns void as $$
declare
sow_data_ids int[];
Expand All @@ -14,13 +14,14 @@ begin
sow_data_ids := array(
select sd.id
from ccbc_public.application_sow_data as sd
where sd.amendment_number = _amendment_number
where sd.amendment_number = _amendment_number and sd.application_id = _application_id
);

-- Update archived_at for non-archived records in application_sow_data table
update ccbc_public.application_sow_data
set archived_at = now()
where amendment_number = _amendment_number
and application_id = _application_id
and archived_at is null;

-- Loop through the selected IDs
Expand Down
55 changes: 55 additions & 0 deletions db/deploy/mutations/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
-- Deploy ccbc:mutations/archive_application_sow to pg

begin;

drop function if exists ccbc_public.archive_application_sow;

create or replace function ccbc_public.archive_application_sow(_amendment_number int)
returns void as $$
declare
sow_data_ids int[];
sow_data_id int;
begin
-- Select all the IDs that belong to the application_id
sow_data_ids := array(
select sd.id
from ccbc_public.application_sow_data as sd
where sd.amendment_number = _amendment_number
);

-- Update archived_at for non-archived records in application_sow_data table
update ccbc_public.application_sow_data
set archived_at = now()
where amendment_number = _amendment_number
and archived_at is null;

-- Loop through the selected IDs
foreach sow_data_id in array sow_data_ids loop
-- Update archived_at on all the tabs for the current sow_data_id if it is null
update ccbc_public.sow_tab_1
set archived_at = now()
where sow_id = sow_data_id
and archived_at is null;

update ccbc_public.sow_tab_2
set archived_at = now()
where sow_id = sow_data_id
and archived_at is null;

update ccbc_public.sow_tab_7
set archived_at = now()
where sow_id = sow_data_id
and archived_at is null;

update ccbc_public.sow_tab_8
set archived_at = now()
where sow_id = sow_data_id
and archived_at is null;
end loop;
end;
$$ language plpgsql volatile;

grant execute on function ccbc_public.archive_application_sow to ccbc_analyst;
grant execute on function ccbc_public.archive_application_sow to ccbc_admin;

commit;
8 changes: 4 additions & 4 deletions db/revert/mutations/archive_application_sow.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ begin;

drop function if exists ccbc_public.archive_application_sow;

create or replace function ccbc_public.archive_application_sow(_application_id int)
create or replace function ccbc_public.archive_application_sow(_amendment_number int)
returns void as $$
declare
sow_data_ids int[];
Expand All @@ -14,13 +14,13 @@ begin
sow_data_ids := array(
select sd.id
from ccbc_public.application_sow_data as sd
where sd.application_id = _application_id
where sd.amendment_number = _amendment_number
);

-- Update archived_at for non-archived records in application_sow_data table
update ccbc_public.application_sow_data
set archived_at = now()
where application_id = _application_id
where amendment_number = _amendment_number
and archived_at is null;

-- Loop through the selected IDs
Expand Down Expand Up @@ -52,4 +52,4 @@ $$ language plpgsql volatile;
grant execute on function ccbc_public.archive_application_sow to ccbc_analyst;
grant execute on function ccbc_public.archive_application_sow to ccbc_admin;

begin;
commit;
55 changes: 55 additions & 0 deletions db/revert/mutations/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
-- Deploy ccbc:mutations/archive_application_sow to pg

begin;

drop function if exists ccbc_public.archive_application_sow;

create or replace function ccbc_public.archive_application_sow(_application_id int)
returns void as $$
declare
sow_data_ids int[];
sow_data_id int;
begin
-- Select all the IDs that belong to the application_id
sow_data_ids := array(
select sd.id
from ccbc_public.application_sow_data as sd
where sd.application_id = _application_id
);

-- Update archived_at for non-archived records in application_sow_data table
update ccbc_public.application_sow_data
set archived_at = now()
where application_id = _application_id
and archived_at is null;

-- Loop through the selected IDs
foreach sow_data_id in array sow_data_ids loop
-- Update archived_at on all the tabs for the current sow_data_id if it is null
update ccbc_public.sow_tab_1
set archived_at = now()
where sow_id = sow_data_id
and archived_at is null;

update ccbc_public.sow_tab_2
set archived_at = now()
where sow_id = sow_data_id
and archived_at is null;

update ccbc_public.sow_tab_7
set archived_at = now()
where sow_id = sow_data_id
and archived_at is null;

update ccbc_public.sow_tab_8
set archived_at = now()
where sow_id = sow_data_id
and archived_at is null;
end loop;
end;
$$ language plpgsql volatile;

grant execute on function ccbc_public.archive_application_sow to ccbc_analyst;
grant execute on function ccbc_public.archive_application_sow to ccbc_admin;

begin;
2 changes: 2 additions & 0 deletions db/sqitch.plan
Original file line number Diff line number Diff line change
Expand Up @@ -718,3 +718,5 @@ tables/application_form_template_9_data 2024-09-25T22:50:17Z Rafael Solorzano <6
@1.203.0 2024-10-25T16:54:48Z CCBC Service Account <[email protected]> # release v1.203.0
@1.203.1 2024-10-28T19:01:53Z CCBC Service Account <[email protected]> # release v1.203.1
@1.203.2 2024-10-29T17:37:47Z CCBC Service Account <[email protected]> # release v1.203.2
mutations/archive_application_sow [mutations/[email protected]] 2024-10-24T19:57:11Z Anthony Bushara <[email protected]> # Add application ID to prevent archiving other applications
@1.203.3 2024-10-29T21:17:39Z CCBC Service Account <[email protected]> # release v1.203.3
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "CONN-CCBC-portal",
"version": "1.203.2",
"version": "1.203.3",
"main": "index.js",
"repository": "https://github.com/bcgov/CONN-CCBC-portal.git",
"author": "Romer, Meherzad CITZ:EX <[email protected]>",
Expand Down

0 comments on commit e7519bf

Please sign in to comment.