Skip to content

Commit

Permalink
Merge pull request #2096 from bcgov/1212-increase-buffer
Browse files Browse the repository at this point in the history
fix: add greater buffer time to prevent modal popup on intake form
  • Loading branch information
AntBush authored Aug 15, 2023
2 parents eaddabb + 46f9948 commit 6a076f8
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 20 deletions.
4 changes: 2 additions & 2 deletions db/deploy/mutations/update_application_form.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ declare
begin

select updated_at into current_updated_at from ccbc_public.form_data where id = form_data_row_id;
-- Adding a buffer, can be used to update if someone happens to have a version of the form that was opened <1 second from the last save
-- Adding a buffer, can be used to update if someone happens to have a version of the form that was opened <3 seconds from the last save
-- Risk is that there can still be overwritten data.
if client_updated_at < current_updated_at - interval '1 second' then
if client_updated_at < current_updated_at - interval '3 second' then
raise exception 'Data is Out of Sync';
end if;

Expand Down
48 changes: 48 additions & 0 deletions db/deploy/mutations/update_application_form@1.94.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
-- Deploy ccbc:mutations/update_application_form to pg

begin;
-- Since we're updating the function definition, need to manually drop
drop function ccbc_public.update_application_form;

create or replace function ccbc_public.update_application_form(form_data_row_id int, json_data jsonb, last_edited_page varchar, client_updated_at timestamp with time zone)
returns ccbc_public.form_data as
$func$
declare
current_updated_at timestamp with time zone;
updated_form_data ccbc_public.form_data;
begin

select updated_at into current_updated_at from ccbc_public.form_data where id = form_data_row_id;
-- Adding a buffer, can be used to update if someone happens to have a version of the form that was opened <1 second from the last save
-- Risk is that there can still be overwritten data.
if client_updated_at < current_updated_at - interval '1 second' then
raise exception 'Data is Out of Sync';
end if;

update ccbc_public.form_data
set
-- use json concatenation operator to merge the provided json_data with the dynamic submission values
json_data = $2 || jsonb_build_object(
'submission', coalesce($2->'submission', jsonb_build_object()) || jsonb_build_object(
'submissionCompletedFor', $2->'organizationProfile'->'organizationName',
'submissionDate', (date_trunc('day', now(), 'America/Vancouver')::date)
)
),
last_edited_page = $3
where id = form_data_row_id
returning * into updated_form_data;

return updated_form_data;
end;
$func$ language plpgsql;

grant execute on function ccbc_public.update_application_form to ccbc_auth_user;

comment on function ccbc_public.update_application_form is
$$
Mutation to update the "application" form.
This mutation should only be used by applicants as it sets the submission page data
$$;


commit;
49 changes: 31 additions & 18 deletions db/revert/mutations/update_application_form.sql
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
-- Deploy ccbc:mutations/update_application_form to pg

begin;

-- Since we're updating the function definition, need to manually drop
drop function ccbc_public.update_application_form;

create or replace function ccbc_public.update_application_form(form_data_row_id int, json_data jsonb, last_edited_page varchar)
create or replace function ccbc_public.update_application_form(form_data_row_id int, json_data jsonb, last_edited_page varchar, client_updated_at timestamp with time zone)
returns ccbc_public.form_data as
$$

update ccbc_public.form_data
set
-- use json concatenation operator to merge the provided json_data with the dynamic submission values
json_data = $2 || jsonb_build_object(
'submission', coalesce($2->'submission', jsonb_build_object()) || jsonb_build_object(
'submissionCompletedFor', $2->'organizationProfile'->'organizationName',
'submissionDate', (date_trunc('day', now(), 'America/Vancouver')::date)
)
),
last_edited_page = $3
where id = form_data_row_id
returning *;

$$ language sql;
$func$
declare
current_updated_at timestamp with time zone;
updated_form_data ccbc_public.form_data;
begin

select updated_at into current_updated_at from ccbc_public.form_data where id = form_data_row_id;
-- Adding a buffer, can be used to update if someone happens to have a version of the form that was opened <1 second from the last save
-- Risk is that there can still be overwritten data.
if client_updated_at < current_updated_at - interval '1 second' then
raise exception 'Data is Out of Sync';
end if;

update ccbc_public.form_data
set
-- use json concatenation operator to merge the provided json_data with the dynamic submission values
json_data = $2 || jsonb_build_object(
'submission', coalesce($2->'submission', jsonb_build_object()) || jsonb_build_object(
'submissionCompletedFor', $2->'organizationProfile'->'organizationName',
'submissionDate', (date_trunc('day', now(), 'America/Vancouver')::date)
)
),
last_edited_page = $3
where id = form_data_row_id
returning * into updated_form_data;

return updated_form_data;
end;
$func$ language plpgsql;

grant execute on function ccbc_public.update_application_form to ccbc_auth_user;

Expand Down
35 changes: 35 additions & 0 deletions db/revert/mutations/update_application_form@1.94.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-- Deploy ccbc:mutations/update_application_form to pg

begin;

drop function ccbc_public.update_application_form;

create or replace function ccbc_public.update_application_form(form_data_row_id int, json_data jsonb, last_edited_page varchar)
returns ccbc_public.form_data as
$$

update ccbc_public.form_data
set
-- use json concatenation operator to merge the provided json_data with the dynamic submission values
json_data = $2 || jsonb_build_object(
'submission', coalesce($2->'submission', jsonb_build_object()) || jsonb_build_object(
'submissionCompletedFor', $2->'organizationProfile'->'organizationName',
'submissionDate', (date_trunc('day', now(), 'America/Vancouver')::date)
)
),
last_edited_page = $3
where id = form_data_row_id
returning *;

$$ language sql;

grant execute on function ccbc_public.update_application_form to ccbc_auth_user;

comment on function ccbc_public.update_application_form is
$$
Mutation to update the "application" form.
This mutation should only be used by applicants as it sets the submission page data
$$;


commit;
1 change: 1 addition & 0 deletions db/sqitch.plan
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,4 @@ mutations/archive_application_community_progress_report 2023-08-10T17:18:29Z Mar
functions/next_intake [functions/next_intake@1.94.0] 2023-08-14T20:10:54Z Marcel Mueller <marcel@m2> # return only intakes where archived_at is null
functions/open_intake [functions/open_intake@1.94.0] 2023-08-14T20:21:04Z Marcel Mueller <marcel@m2> # return only intakes where archived_at is null
functions/receive_applications [functions/receive_applications@1.94.0] 2023-08-14T21:26:26Z Marcel Mueller <marcel@m2> # select intake where archived at is null
mutations/update_application_form [mutations/update_application_form@1.94.0] 2023-08-14T20:22:39Z Tony Bushara <tonybushara@pop-os> # Increase the buffer time to 3 seconds

0 comments on commit 6a076f8

Please sign in to comment.