Skip to content

Commit

Permalink
Merge pull request #3295 from bcgov/NDT-344-Pending-Change-Request-no…
Browse files Browse the repository at this point in the history
…t-archiving-old-records

fix: archiving old pending change request records
  • Loading branch information
RRanath authored May 23, 2024
2 parents ecf463b + 1daed0b commit 5db2a45
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const StyledCheckbox = styled.input`
`;

const StyledFontAwesomeIcon = styled(FontAwesomeIcon)`
margin-left: 8px; ;
margin-left: 8px;
`;

const PendingChangeRequest = ({ application }) => {
Expand Down Expand Up @@ -71,11 +71,9 @@ const PendingChangeRequest = ({ application }) => {
createPendingChangeRequest({
variables: {
input: {
applicationPendingChangeRequest: {
applicationId: rowId,
comment: reasonForChange,
isPending: isPendingRequest,
},
_applicationId: rowId,
_isPending: isPendingRequest,
_comment: reasonForChange,
},
},
onCompleted: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 61 additions & 0 deletions app/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
"""
Expand Down
32 changes: 12 additions & 20 deletions app/tests/components/Analyst/PendingChangeRequest.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
);
Expand Down Expand Up @@ -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,
},
}
);
Expand Down Expand Up @@ -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,
},
}
);
Expand Down Expand Up @@ -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,
},
}
);
Expand Down
25 changes: 25 additions & 0 deletions db/deploy/mutations/create_pending_change_request.sql
Original file line number Diff line number Diff line change
@@ -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;
7 changes: 7 additions & 0 deletions db/revert/mutations/create_pending_change_request.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Revert ccbc:mutations/create_pending_change_request from pg

BEGIN;

drop function ccbc_public.create_pending_change_request;

COMMIT;
1 change: 1 addition & 0 deletions db/sqitch.plan
Original file line number Diff line number Diff line change
Expand Up @@ -564,3 +564,4 @@ tables/application_pending_change_request 2024-05-03T20:55:21Z ,,, <ryohani89@NH
@1.161.0 2024-05-15T17:59:55Z CCBC Service Account <[email protected]> # release v1.161.0
tables/cbc 2024-05-08T17:56:10Z Rafael Solorzano <[email protected]> # add cbc projects table for individual cbc projects
tables/cbc_data 2024-05-08T18:08:06Z Rafael Solorzano <[email protected]> # table to hold the json data for individual cbc projects
mutations/create_pending_change_request 2024-05-22T16:44:01Z ,,, <ryohani89@NH504670> # add create application pending change request mutation

0 comments on commit 5db2a45

Please sign in to comment.