Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/1815 removed unused audits amend #679

Open
wants to merge 29 commits into
base: master
Choose a base branch
from

Conversation

jenbutongit
Copy link
Contributor

@jenbutongit jenbutongit commented Aug 23, 2023

Refactor/cleanup

Previously, events were being recorded in two places, in the Event table and the Audit table. This change makes the approach more consistent. events which relate to ListItems will be recorded on the Event table, and other events will be recorded on the Audit table.

A new nullable column has been added to both Event and Audit - annualReviewEmailType which are enums. This will help with querying the different types of email types, where previously the approach was inconsistent between tables.

For Audit, you may search for these annual review emails:

  • oneMonthBeforeStart // sent one month before nextAnnualReviewStartDate
  • oneWeekBeforeStart // sent one week before
  • oneDayBeforeStart // sent one day before
  • started // sent day of start
  • oneDayBeforeUnpublish // sent one day before unpublishing

For ListItem, you may search for these annual review emails:

  • started // sent day of nextAnnualReviewStartDate
  • weeklyUnpublish // sent every week until unpublish date
  • oneDayBeforeUnpublish // sent day before unpublish
  • unpublished // sent day of unpublishing
select * from "Audit" where "annualReviewEmailType" = 'oneMonthBeforeStart';
select * from "Audit" where "annualReviewEmailType" = 'started';

When annual review data is generated, List.jsonData.currentAnnualReview, it is now also added to the the Audit table. After an annual review ends, it is now easier to aggregate annual review Audits and Events.

-- get object describing the scheduled times of the emails which includes the reference
select "jsonData"->'currentAnnualReview' from "Audit" where "auditEvent" = 'ANNUAL_REVIEW' and "jsonData"->>'eventName' = 'startAnnualReview';

-- get just the reference
select "jsonData"->'currentAnnualReview'->'reference' reference from "Audit" where "auditEvent" = 'ANNUAL_REVIEW' and "jsonData"->>'eventName' = 'startAnnualReview';

-- get audits relating to reference
with annual_review as (select "jsonData"->'currentAnnualReview'->'reference' reference from "Audit" where "auditEvent" = 'ANNUAL_REVIEW' and "jsonData"->>'eventName' = 'startAnnualReview')
     select * from "Audit" join annual_review on annual_review.reference = "Audit"."jsonData"->'annualReviewRef' or annual_review.reference = "Audit"."jsonData"->'reference' ;

-- get Events relating to reference
with annual_review as (select "jsonData"->'currentAnnualReview'->'reference' reference from "Audit" where "auditEvent" = 'ANNUAL_REVIEW' and "jsonData"->>'eventName' = 'startAnnualReview')
select * from "Event" join annual_review on annual_review.reference = "Event"."jsonData"->'annualReviewRef' or annual_review.reference = "Event"."jsonData"->'reference';

@jenbutongit jenbutongit force-pushed the chore/1815-removed-unused-audits-amend branch from 5d17681 to 8c2bf75 Compare September 29, 2023 10:48
Squashed commits:
[f21dd86] docs, tidy
[c25983e] add composeKeyDatesForDate tests
[4957b51] add eventName: "startAnnualReview" and fix tests
[351d3d1] check oneDayBeforeUnpublish
[047ab92] lint
[a119939] also insert annual review data into audit.
[4ce950f] tidying
[10e57ce] fixing tests
[89bc9cf] fix: use getNotifyClient for sendUnpublishReminder. Change query to look for `weeklyUnpublish`
[0c4474a] fix test
[3886463] do not record video
[6a5f159] fix lint
[7e83b12] return
[efe56d0] tiding
[1751542] video: true
[692bde8] debug
[2e23ffa] return
[6c9506f] tidy
[488cdc6] refactor: tidy processListsBeforeAndDuringStart
[d59f2ee] fix smoke test query
[4d3c364] fix migration
[33a1ef6] tidy
[bd1b07b] order by time desc
[d2024ce] docs, tidy
[47582a1] fix tests
[c90f6c2] tidy comment
[280f21c] tidy
[fc79284] lint
[cf9bf90] remove unused types
[76f9cfa] tidy types
[225c978] tidy
[1016f20] add reference param
[4ba68a0] tidying
[721f12e] refactor: use type from prisma client.
[75f137a] refactor: use ListAnnualReviewPostReminderType for sendAnnualReviewPostEmails
[6f4688f] migration
[0fc9081] clean up
[b93d915] simplifying annualReviewProviderType enums
[db83234] change send**postEmail to just name of the email. change order of enums
[d636907] shouldSend logs and docs
[52b7d7f] change emailType to annualReviewEmailType
[04762cf] migrations
[289005a] chore(ingestPutController.ts): fix import path for EventCreate type from "server/models/listItem/listItemEvent" to "shared/listItemEvent" to resolve import error
[63ae40c] chore(listItemEvent.ts): refactor the [ListItemEvent.EDITED] event creation function to accept additional options for different types of edits
[53e947d] chore(worker.feature): update scenario names to be more descriptive
chore(the_string_key_date_email_will_be_sent_to_post.js): simplify the where clause in the query to improve readability and maintainability
[8f2d179] chore: add emailType to prisma queries
[eb7f672] chore(migration.sql): add migration script to add emailType columns to Audit and Event tables
chore(schema.prisma): add emailType fields to Audit and Event models
[ea961bc] chore: fix issues with unit tests
[1a998c7] chore: address issues raised in PR
[f603ecb] chore(migration.sql): delete unused audits for list items
[2068e78] chore(migration.sql): update migration to delete only listItem audits with auditEvent set to 'REMINDER'
refactor(listItemEvent.ts): remove unnecessary check for "id" in response
[3097a16] chore(migration.sql): Remove unused enum values from `AuditEvent` enum
[1dd6326] chore(migrations): add migration to delete unused audits and update audit enum

chore(migrations): add migration to delete unused audits

chore(migrations): add migration to update audit enum
[25e066d] chore: include start of annual review date when getting reminder events
refactor: rename function names that didn't make sense
[2bb242d] chore: fix issue with failing smoke test by...
chore(an_email_for_the_string_key_date_is_sent_to_eligible_providers.js): add array to test instead of string
chore(audit.ts): add missing export statement for findReminderAuditEvents function
chore(govukNotify.ts): update return value of sendAnnualReviewProviderEmail and sendAnnualReviewPostEmail functions
chore(helpers.ts): update parameter type of isEmailSentBefore function
chore(main.ts): update import statements for Audit and Event types
[53c0ad0] chore: fix issue with smoke test failing
[9316919] chore(resetAnnualReviewForList.ts): uncomment code to add audit event for endAnnualReview
[ef22446] chore: fix type related issues
[a42e5e5] chore(types.ts): remove NotifyResult interface
chore(govuk-notify.ts): change return value of sendAuthenticationEmail, sendApplicationConfirmationEmail, sendDataPublishedEmail, and sendEditDetailsEmail to check for "id" in result and result.id !== undefined
chore(notifications-node-client.ts): change statusText to id in mockResolvedValue
[1969ccc] refactor: remove depreciated recordListItemEvent function and all references to it
[76272f2] change funeral director to lawyer
[0105e4e] remove button import
[75781a4] mimic apply footer
[6b5f40e] smoke tests
[cc36e82] skip if /session/* route
[2cd89f7] replay answer
[472d5b3] fix smoke tests
[ca7dfce] e2e tests
[463e0c4] add backLinkFallback
[e362daf] chore: fix issues with unit tests
[31b0424] chore: fix issues with cookies not working
[91212a9] chore(proxyMiddleware): add lawyersPostController to handle POST request for /application/lawyers/which-list-of-lawyers route
chore(proxyMiddleware): update route handlers in applyRouter to use lawyersPostController instead of postLawyers
chore(listItemCreateInputFromWebhook): update countryName parameter to use addressCountry property from deserialised data
[d9895c1] add back pro-bono skip for prt
[eebe79d] refactor(express-session.ts): add application object to SessionData interface to store application related data
refactor(applyController.ts): add postLawyers function to handle POST request for lawyers application
[ed587ab] add back can you offer pro-bono services to british nationals
[e58541c] fix logic
[f897fbf] allow /application/session routes to pass through without country check
[e1d3d9b] remove unused
[1f8320c] tidy
[5dec6af] wip
[1f6de9f] wip
[5a61d06] feat: move "which list of lawyers do you want to be added to" into lists so we can serve the "We are not currently accepting online applications" page dynamically
@jenbutongit jenbutongit force-pushed the chore/1815-removed-unused-audits-amend branch from 8c2bf75 to 774679a Compare September 29, 2023 11:00
@jenbutongit jenbutongit marked this pull request as ready for review September 29, 2023 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants