diff --git a/app/components/Analyst/PendingChangeRequest/PendingChangeRequest.tsx b/app/components/Analyst/PendingChangeRequest/PendingChangeRequest.tsx index 3dd3c69933..0fd3fe52d8 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..43d99bd830 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..44c1d48dcb 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..222d747e29 --- /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, _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, _is_pending) 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