From 2997b36aab70730bfd0c1df6abe378cfa258b83b Mon Sep 17 00:00:00 2001 From: R Ranathunga Date: Wed, 22 May 2024 11:52:51 -0700 Subject: [PATCH 1/2] fix: archiving old pending change req records --- .../PendingChangeRequest.tsx | 10 ++- .../application/createPendingChangeRequest.ts | 4 +- app/schema/schema.graphql | 61 +++++++++++++++++++ .../Analyst/PendingChangeRequest.test.tsx | 32 ++++------ .../create_pending_change_request.sql | 25 ++++++++ .../create_pending_change_request.sql | 7 +++ db/sqitch.plan | 1 + 7 files changed, 112 insertions(+), 28 deletions(-) create mode 100644 db/deploy/mutations/create_pending_change_request.sql create mode 100644 db/revert/mutations/create_pending_change_request.sql diff --git a/app/components/Analyst/PendingChangeRequest/PendingChangeRequest.tsx b/app/components/Analyst/PendingChangeRequest/PendingChangeRequest.tsx index 3dd3c69933..9abca7ba5f 100644 --- a/app/components/Analyst/PendingChangeRequest/PendingChangeRequest.tsx +++ b/app/components/Analyst/PendingChangeRequest/PendingChangeRequest.tsx @@ -16,7 +16,7 @@ const StyledCheckbox = styled.input` `; const StyledFontAwesomeIcon = styled(FontAwesomeIcon)` - margin-left: 8px; ; + margin-left: 8px; `; const PendingChangeRequest = ({ application }) => { @@ -71,11 +71,9 @@ const PendingChangeRequest = ({ application }) => { createPendingChangeRequest({ variables: { input: { - applicationPendingChangeRequest: { - applicationId: rowId, - comment: reasonForChange, - isPending: isPendingRequest, - }, + _applicationId: rowId, + _ispending: isPendingRequest, + _comment: reasonForChange, }, }, onCompleted: () => { diff --git a/app/schema/mutations/application/createPendingChangeRequest.ts b/app/schema/mutations/application/createPendingChangeRequest.ts index 3b1acd57b8..e925c18b19 100644 --- a/app/schema/mutations/application/createPendingChangeRequest.ts +++ b/app/schema/mutations/application/createPendingChangeRequest.ts @@ -4,9 +4,9 @@ import useMutationWithErrorMessage from '../useMutationWithErrorMessage'; const mutation = graphql` mutation createPendingChangeRequestMutation( - $input: CreateApplicationPendingChangeRequestInput! + $input: CreatePendingChangeRequestInput! ) { - createApplicationPendingChangeRequest(input: $input) { + createPendingChangeRequest(input: $input) { applicationPendingChangeRequest { isPending comment diff --git a/app/schema/schema.graphql b/app/schema/schema.graphql index 47a88ce763..2701284261 100644 --- a/app/schema/schema.graphql +++ b/app/schema/schema.graphql @@ -69356,6 +69356,12 @@ type Mutation { """ input: CreatePackageInput! ): CreatePackagePayload + createPendingChangeRequest( + """ + The exclusive input argument for this mutation. An object type, make sure to see documentation for this object’s fields. + """ + input: CreatePendingChangeRequestInput! + ): CreatePendingChangeRequestPayload createProjectInformation( """ The exclusive input argument for this mutation. An object type, make sure to see documentation for this object’s fields. @@ -80376,6 +80382,61 @@ input CreatePackageInput { _package: Int } +"""The output of our `createPendingChangeRequest` mutation.""" +type CreatePendingChangeRequestPayload { + """ + The exact same `clientMutationId` that was provided in the mutation input, + unchanged and unused. May be used by a client to track mutations. + """ + clientMutationId: String + applicationPendingChangeRequest: ApplicationPendingChangeRequest + + """ + Our root query field type. Allows us to run any query from our mutation payload. + """ + query: Query + + """ + Reads a single `Application` that is related to this `ApplicationPendingChangeRequest`. + """ + applicationByApplicationId: Application + + """ + Reads a single `CcbcUser` that is related to this `ApplicationPendingChangeRequest`. + """ + ccbcUserByCreatedBy: CcbcUser + + """ + Reads a single `CcbcUser` that is related to this `ApplicationPendingChangeRequest`. + """ + ccbcUserByUpdatedBy: CcbcUser + + """ + Reads a single `CcbcUser` that is related to this `ApplicationPendingChangeRequest`. + """ + ccbcUserByArchivedBy: CcbcUser + + """ + An edge for our `ApplicationPendingChangeRequest`. May be used by Relay 1. + """ + applicationPendingChangeRequestEdge( + """The method to use when ordering `ApplicationPendingChangeRequest`.""" + orderBy: [ApplicationPendingChangeRequestsOrderBy!] = [PRIMARY_KEY_ASC] + ): ApplicationPendingChangeRequestsEdge +} + +"""All input for the `createPendingChangeRequest` mutation.""" +input CreatePendingChangeRequestInput { + """ + An arbitrary string value with no semantic meaning. Will be included in the + payload verbatim. May be used to track mutations by the client. + """ + clientMutationId: String + _applicationId: Int! + _ispending: Boolean! + _comment: String +} + """The output of our `createProjectInformation` mutation.""" type CreateProjectInformationPayload { """ diff --git a/app/tests/components/Analyst/PendingChangeRequest.test.tsx b/app/tests/components/Analyst/PendingChangeRequest.test.tsx index 9db8b93278..ddd2791f0a 100644 --- a/app/tests/components/Analyst/PendingChangeRequest.test.tsx +++ b/app/tests/components/Analyst/PendingChangeRequest.test.tsx @@ -131,11 +131,9 @@ describe('The Pending Change Request component', () => { 'createPendingChangeRequestMutation', { input: { - applicationPendingChangeRequest: { - applicationId: 1, - comment: 'Edited comment.', - isPending: true, - }, + _applicationId: 1, + _comment: 'Edited comment.', + _ispending: true, }, } ); @@ -195,11 +193,9 @@ describe('The Pending Change Request component', () => { 'createPendingChangeRequestMutation', { input: { - applicationPendingChangeRequest: { - applicationId: 1, - comment: 'Yes, change request cancelled', - isPending: false, - }, + _applicationId: 1, + _comment: 'Yes, change request cancelled', + _ispending: false, }, } ); @@ -265,11 +261,9 @@ describe('The Pending Change Request component', () => { 'createPendingChangeRequestMutation', { input: { - applicationPendingChangeRequest: { - applicationId: 1, - comment: 'This is a test comment.', - isPending: true, - }, + _applicationId: 1, + _comment: 'This is a test comment.', + _ispending: true, }, } ); @@ -301,11 +295,9 @@ describe('The Pending Change Request component', () => { 'createPendingChangeRequestMutation', { input: { - applicationPendingChangeRequest: { - applicationId: 1, - comment: null, - isPending: true, - }, + _applicationId: 1, + _comment: null, + _ispending: true, }, } ); diff --git a/db/deploy/mutations/create_pending_change_request.sql b/db/deploy/mutations/create_pending_change_request.sql new file mode 100644 index 0000000000..a0392a1bc0 --- /dev/null +++ b/db/deploy/mutations/create_pending_change_request.sql @@ -0,0 +1,25 @@ +-- Deploy ccbc:mutations/create_pending_change_request.sql to pg + +begin; + +create or replace function ccbc_public.create_pending_change_request(_application_id int, _isPending boolean, _comment varchar default null) returns ccbc_public.application_pending_change_request as $$ +declare +new_request_id int; +begin + + insert into ccbc_public.application_pending_change_request (application_id, comment, is_pending) + values (_application_id, _comment, _isPending) returning id into new_request_id; + + update ccbc_public.application_pending_change_request + set archived_at = now() + where application_id = _application_id and archived_at is null and id != new_request_id; + + return (select row(ccbc_public.application_pending_change_request.*) from ccbc_public.application_pending_change_request where id = new_request_id); + +end; +$$ language plpgsql volatile; + +grant execute on function ccbc_public.create_pending_change_request to ccbc_analyst; +grant execute on function ccbc_public.create_pending_change_request to ccbc_admin; + +commit; diff --git a/db/revert/mutations/create_pending_change_request.sql b/db/revert/mutations/create_pending_change_request.sql new file mode 100644 index 0000000000..60eb4505bc --- /dev/null +++ b/db/revert/mutations/create_pending_change_request.sql @@ -0,0 +1,7 @@ +-- Revert ccbc:mutations/create_pending_change_request from pg + +BEGIN; + +drop function ccbc_public.create_pending_change_request; + +COMMIT; diff --git a/db/sqitch.plan b/db/sqitch.plan index f418261572..1698ebaac8 100644 --- a/db/sqitch.plan +++ b/db/sqitch.plan @@ -564,3 +564,4 @@ tables/application_pending_change_request 2024-05-03T20:55:21Z ,,, # release v1.161.0 tables/cbc 2024-05-08T17:56:10Z Rafael Solorzano <61289255+rafasdc@users.noreply.github.com> # add cbc projects table for individual cbc projects tables/cbc_data 2024-05-08T18:08:06Z Rafael Solorzano <61289255+rafasdc@users.noreply.github.com> # table to hold the json data for individual cbc projects +mutations/create_pending_change_request 2024-05-22T16:44:01Z ,,, # add create application pending change request mutation From 76bcad3b5a1887850829c9743eba7ede5603e728 Mon Sep 17 00:00:00 2001 From: R Ranathunga Date: Wed, 22 May 2024 12:13:54 -0700 Subject: [PATCH 2/2] fix: typo --- .../Analyst/PendingChangeRequest/PendingChangeRequest.tsx | 2 +- app/schema/schema.graphql | 2 +- .../components/Analyst/PendingChangeRequest.test.tsx | 8 ++++---- db/deploy/mutations/create_pending_change_request.sql | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/components/Analyst/PendingChangeRequest/PendingChangeRequest.tsx b/app/components/Analyst/PendingChangeRequest/PendingChangeRequest.tsx index 9abca7ba5f..0fd3fe52d8 100644 --- a/app/components/Analyst/PendingChangeRequest/PendingChangeRequest.tsx +++ b/app/components/Analyst/PendingChangeRequest/PendingChangeRequest.tsx @@ -72,7 +72,7 @@ const PendingChangeRequest = ({ application }) => { variables: { input: { _applicationId: rowId, - _ispending: isPendingRequest, + _isPending: isPendingRequest, _comment: reasonForChange, }, }, diff --git a/app/schema/schema.graphql b/app/schema/schema.graphql index 2701284261..43d99bd830 100644 --- a/app/schema/schema.graphql +++ b/app/schema/schema.graphql @@ -80433,7 +80433,7 @@ input CreatePendingChangeRequestInput { """ clientMutationId: String _applicationId: Int! - _ispending: Boolean! + _isPending: Boolean! _comment: String } diff --git a/app/tests/components/Analyst/PendingChangeRequest.test.tsx b/app/tests/components/Analyst/PendingChangeRequest.test.tsx index ddd2791f0a..44c1d48dcb 100644 --- a/app/tests/components/Analyst/PendingChangeRequest.test.tsx +++ b/app/tests/components/Analyst/PendingChangeRequest.test.tsx @@ -133,7 +133,7 @@ describe('The Pending Change Request component', () => { input: { _applicationId: 1, _comment: 'Edited comment.', - _ispending: true, + _isPending: true, }, } ); @@ -195,7 +195,7 @@ describe('The Pending Change Request component', () => { input: { _applicationId: 1, _comment: 'Yes, change request cancelled', - _ispending: false, + _isPending: false, }, } ); @@ -263,7 +263,7 @@ describe('The Pending Change Request component', () => { input: { _applicationId: 1, _comment: 'This is a test comment.', - _ispending: true, + _isPending: true, }, } ); @@ -297,7 +297,7 @@ describe('The Pending Change Request component', () => { input: { _applicationId: 1, _comment: null, - _ispending: true, + _isPending: true, }, } ); diff --git a/db/deploy/mutations/create_pending_change_request.sql b/db/deploy/mutations/create_pending_change_request.sql index a0392a1bc0..222d747e29 100644 --- a/db/deploy/mutations/create_pending_change_request.sql +++ b/db/deploy/mutations/create_pending_change_request.sql @@ -2,13 +2,13 @@ begin; -create or replace function ccbc_public.create_pending_change_request(_application_id int, _isPending boolean, _comment varchar default null) returns ccbc_public.application_pending_change_request as $$ +create or replace function ccbc_public.create_pending_change_request(_application_id int, _is_pending boolean, _comment varchar default null) returns ccbc_public.application_pending_change_request as $$ declare new_request_id int; begin insert into ccbc_public.application_pending_change_request (application_id, comment, is_pending) - values (_application_id, _comment, _isPending) returning id into new_request_id; + values (_application_id, _comment, _is_pending) returning id into new_request_id; update ccbc_public.application_pending_change_request set archived_at = now()