-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add email trigger for 'create application' & fix trigger not to…
… send an email when version = 0
- Loading branch information
Showing
10 changed files
with
106 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const createDraftApplicationStartedMail = ({ | ||
email, | ||
firstName, | ||
lastName, | ||
operatorName, | ||
facilityName | ||
}) => { | ||
return ` | ||
<p>${firstName}<p> | ||
<p>${lastName}<p> | ||
<p>${email}<p> | ||
<p>${operatorName}<p> | ||
<p>${facilityName}<p> | ||
`; | ||
}; | ||
|
||
module.exports = createDraftApplicationStartedMail; |
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
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
46 changes: 46 additions & 0 deletions
46
schema/deploy/trigger_functions/draft_application_started.sql
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 ggircs-portal:trigger_functions/draft_application_started to pg | ||
-- requires: schema_ggircs_portal | ||
|
||
begin; | ||
|
||
create or replace function ggircs_portal_private.draft_application_started() returns trigger as $$ | ||
declare | ||
user_details record; | ||
operation_details record; | ||
begin | ||
|
||
with ud as ( | ||
select cu.first_name, cu.last_name, cu.email_address | ||
from ggircs_portal.ciip_user cu | ||
where cu.uuid = (select sub from ggircs_portal.session()) | ||
) | ||
select * from ud into user_details; | ||
|
||
with od as ( | ||
select f.facility_name, o.operator_name | ||
from ggircs_portal.facility f | ||
join ggircs_portal.organisation o | ||
on o.id = f.organisation_id | ||
and f.id = new.facility_id | ||
) | ||
select * from od into operation_details; | ||
|
||
perform ggircs_portal_private.graphile_worker_job_definer( | ||
'sendMail', | ||
json_build_object( | ||
'type', 'draft_application_started', | ||
'firstName', user_details.first_name, | ||
'lastName', user_details.last_name, | ||
'email', user_details.email_address, | ||
'operatorName', operation_details.operator_name, | ||
'facilityName', operation_details.facility_name | ||
) | ||
); | ||
|
||
return new; | ||
end; | ||
$$ language plpgsql volatile; | ||
|
||
comment on function ggircs_portal_private.draft_application_started is 'Trigger function sends an email upon being called'; | ||
|
||
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
7 changes: 7 additions & 0 deletions
7
schema/revert/trigger_functions/draft_application_started.sql
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,7 @@ | ||
-- Revert ggircs-portal:trigger_functions/draft_application_started from pg | ||
|
||
begin; | ||
|
||
drop function ggircs_portal_private.draft_application_started; | ||
|
||
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
7 changes: 7 additions & 0 deletions
7
schema/verify/trigger_functions/draft_application_started.sql
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,7 @@ | ||
-- Verify ggircs-portal:trigger_functions/draft_application_started on pg | ||
|
||
begin; | ||
|
||
select pg_get_functiondef('ggircs_portal_private.draft_application_started()'::regprocedure); | ||
|
||
rollback; |