-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2095 from bcgov/2083-deleted-intake-bug
fix: return only non archived intakes from next_intake and open_intake function
- Loading branch information
Showing
15 changed files
with
223 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
-- Deploy ccbc:functions/next_intake to pg | ||
|
||
begin; | ||
|
||
create or replace function ccbc_public.next_intake() | ||
returns ccbc_public.intake | ||
as $function$ | ||
select * | ||
from ccbc_public.intake | ||
where now() < open_timestamp | ||
order by ccbc_intake_number | ||
limit 1; | ||
$function$ language sql stable; | ||
|
||
grant execute on function ccbc_public.next_intake to ccbc_auth_user, ccbc_guest, ccbc_admin, ccbc_analyst; | ||
|
||
comment on function ccbc_public.next_intake is 'Returns the next intake if any'; | ||
|
||
commit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- Deploy ccbc:functions/open_intake to pg | ||
|
||
BEGIN; | ||
|
||
create or replace function ccbc_public.open_intake() returns ccbc_public.intake as | ||
$function$ | ||
select * from ccbc_public.intake where now() >= open_timestamp and now() <= close_timestamp; | ||
$function$ language sql stable; | ||
|
||
grant execute on function ccbc_public.open_intake to ccbc_guest, ccbc_auth_user, ccbc_admin, ccbc_analyst; | ||
|
||
comment on function ccbc_public.open_intake is 'Returns the current open intake'; | ||
|
||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
-- Deploy ccbc:functions/receive_applications to pg | ||
|
||
BEGIN; | ||
|
||
create or replace function ccbc_public.receive_applications() returns table(result_id int) as | ||
$function$ | ||
declare | ||
current_app ccbc_public.application%ROWTYPE; | ||
last_status text; | ||
cnt int; | ||
applications refcursor; | ||
|
||
begin | ||
select count(*) into cnt from ccbc_public.application | ||
where intake_id in ( | ||
select id from ccbc_public.intake where now() >= close_timestamp); | ||
|
||
open applications for select id, intake_id | ||
from ccbc_public.application | ||
where intake_id in ( | ||
select id from ccbc_public.intake where now() >= close_timestamp); | ||
|
||
loop | ||
fetch applications into current_app; | ||
exit when not found; | ||
|
||
select ccbc_public.application_status(current_app) into last_status; | ||
|
||
if last_status = 'submitted' then | ||
insert into ccbc_public.application_status (application_id, status) | ||
values (current_app.id,'received'); | ||
end if; | ||
end loop; | ||
|
||
close applications; | ||
|
||
return query select 0 as result_id; | ||
end; | ||
$function$ language plpgsql volatile; | ||
|
||
grant execute on function ccbc_public.receive_applications to ccbc_job_executor; | ||
revoke execute on function ccbc_public.receive_applications from ccbc_auth_user; | ||
|
||
comment on function ccbc_public.receive_applications is 'Detects closed intake and marks all submitted applications as Received'; | ||
|
||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
-- Deploy ccbc:functions/next_intake to pg | ||
|
||
begin; | ||
|
||
create or replace function ccbc_public.next_intake() | ||
returns ccbc_public.intake | ||
as $function$ | ||
select * | ||
from ccbc_public.intake | ||
where now() < open_timestamp | ||
order by ccbc_intake_number | ||
limit 1; | ||
$function$ language sql stable; | ||
|
||
grant execute on function ccbc_public.next_intake to ccbc_auth_user, ccbc_guest; | ||
|
||
comment on function ccbc_public.next_intake is 'Returns the next intake if any'; | ||
|
||
commit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- Deploy ccbc:functions/open_intake to pg | ||
|
||
BEGIN; | ||
|
||
create or replace function ccbc_public.open_intake() returns ccbc_public.intake as | ||
$function$ | ||
select * from ccbc_public.intake where now() >= open_timestamp and now() <= close_timestamp; | ||
$function$ language sql stable; | ||
|
||
grant execute on function ccbc_public.open_intake to ccbc_guest, ccbc_auth_user; | ||
|
||
comment on function ccbc_public.open_intake is 'Returns the current open intake'; | ||
|
||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
-- Deploy ccbc:functions/receive_applications to pg | ||
|
||
BEGIN; | ||
|
||
create or replace function ccbc_public.receive_applications() returns table(result_id int) as | ||
$function$ | ||
declare | ||
current_app ccbc_public.application%ROWTYPE; | ||
last_status text; | ||
cnt int; | ||
applications refcursor; | ||
|
||
begin | ||
select count(*) into cnt from ccbc_public.application | ||
where intake_id in ( | ||
select id from ccbc_public.intake where now() >= close_timestamp); | ||
|
||
open applications for select id, intake_id | ||
from ccbc_public.application | ||
where intake_id in ( | ||
select id from ccbc_public.intake where now() >= close_timestamp); | ||
|
||
loop | ||
fetch applications into current_app; | ||
exit when not found; | ||
|
||
select ccbc_public.application_status(current_app) into last_status; | ||
|
||
if last_status = 'submitted' then | ||
insert into ccbc_public.application_status (application_id, status) | ||
values (current_app.id,'received'); | ||
end if; | ||
end loop; | ||
|
||
close applications; | ||
|
||
return query select 0 as result_id; | ||
end; | ||
$function$ language plpgsql volatile; | ||
|
||
grant execute on function ccbc_public.receive_applications to ccbc_auth_user; | ||
revoke execute on function ccbc_public.receive_applications from ccbc_job_executor; | ||
|
||
comment on function ccbc_public.receive_applications is 'Detects closed intake and marks all submitted applications as Received'; | ||
|
||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters