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

Refactor CreateEventService for bill runs #73

Merged
merged 8 commits into from
Jan 2, 2023

Conversation

Cruikshanks
Copy link
Member

@Cruikshanks Cruikshanks commented Dec 23, 2022

https://eaflood.atlassian.net/browse/WATER-3831

We've created the model and a service wrapper for creating events. But at this time we are only interested in creating an event when a new bill run is initialised. That means some fields will always be set with a certain value.

Also, based on reviewing existing events created by the legacy code the metadata holds a formatted version of a bill run. So, we need to handle that.

All this means we'd be better placed to refactor the existing service to focus on new bill-run events.

** Notes

  • Add migrations for missing fields
    There are columns on the regions and billing_batches tables that the existing logic extracts data from that isn't present in our test db. So, we add alter migrations for the missing fields and update our helpers accordingly.

  • Add presenter needed to format metadata content
    The metadata field in an event record doesn't just contain a dump of the BillingBatch as JSON. Instead, it is a specifically formatted object. So, we need something that will convert the BillingBatchModel instance into the content we need.

  • Add source as a default in BillingBatchHelper
    Source is populated when a billing batch event is created for real. So, we ensure it's populated in our helper to reflect that.

Example of bill run metadata
{
  "batch": {
    "id": "c7dcab89-8ba7-447b-99f3-25b1161d932b",
    "type": "supplementary",
    "region": {
      "id": "0d2e80dc-a5c5-45a0-91ce-48926e29bbba",
      "code": "T",
      "name": "Thames",
      "type": "region",
      "displayName": "Thames",
      "numericCode": 7
    },
    "source": "wrls",
    "status": "processing",
    "endYear": {
      "yearEnding": 2022
    },
    "invoices": [],
    "isSummer": false,
    "netTotal": null,
    "startYear": {
      "yearEnding": 2017
    },
    "dateCreated": "2022-01-21T14:34:31.813Z",
    "dateUpdated": "2022-01-21T14:34:31.813Z",
    "invoiceCount": null,
    "invoiceValue": null,
    "creditNoteCount": null,
    "creditNoteValue": null
  }
}

https://eaflood.atlassian.net/browse/WATER-3831

We've created the model and a service wrapper for creating events. But at this time we are only interested in creating an `event` when a new bill run is initialised. That means some fields will always be set with a certain value.

Also, based on reviewing existing events created by the legacy code the `metadata` holds a formatted version of a bill run. So, we need to handle that.

All this means we'd be better placed to refactor the existing service to focus on new bill run events.
@Cruikshanks Cruikshanks added the housekeeping Refactoring, tidying up or other work which supports the project label Dec 23, 2022
@Cruikshanks Cruikshanks self-assigned this Dec 23, 2022
There are columns on the `regions` and `billing_batches` tables that the existing logic extracts data from that isn't present in our test db. So, we add alter migrations for the missing fields and update our helpers accordingly.
The metadata field in an event record doesn't just contain a dump of the BillingBatch as JSON. Instead it seems to be a specifically formatted object. So, we need something that will convert the `BillingBatchModel` instance into the content we need.
Source seems to be populated when a billing batch event is created for real. So, we ensure it's populated in our helper to reflect that.
@Cruikshanks Cruikshanks force-pushed the refactor-create-event-for-bill-runs branch from 2896412 to e814fc1 Compare January 2, 2023 20:27
The name now hopefully better reflects what we'l use it for.
Getting ahead of ourselves!

We intend to rename all our models and services to reflect how they are referred to in the UI, or within the team. At the moment though we are using the database as our guide but we know this is the most 'wrong' of how things are now referenced in the service.
Now the service does what we need it to do; create new billing batch events.
@Cruikshanks Cruikshanks marked this pull request as ready for review January 2, 2023 21:11
@Cruikshanks Cruikshanks merged commit 6d4e6e8 into main Jan 2, 2023
@Cruikshanks Cruikshanks deleted the refactor-create-event-for-bill-runs branch January 2, 2023 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
housekeeping Refactoring, tidying up or other work which supports the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant