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

Update "create bill run" endpoint to create a bill run #56

Merged
merged 7 commits into from
Jan 3, 2023

Conversation

StuAA78
Copy link
Contributor

@StuAA78 StuAA78 commented Dec 16, 2022

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

When we set up our "create bill run" endpoint, we had it simply respond to requests with a dummy response. We now update it to actually create a bill run and an event, and return the required details in the same format as the dummy response.

@StuAA78 StuAA78 added the enhancement New feature or request label Dec 16, 2022
@StuAA78 StuAA78 self-assigned this Dec 16, 2022
Cruikshanks added a commit that referenced this pull request Dec 16, 2022
It was spotted whilst working on [Update "create bill run" endpoint to create a bill run](#56) that we had an issue with our [Objection models](https://vincit.github.io/objection.js/).

The previous team didn't use the convention of just calling the unique identifier in each table `id`. Instead they incorporate the table name, for example, `billing_batch_id`. **Objection** is expecting the identifier column to be `id` and is failing when in some cases.

Because of this we need to go back and specify [idColumn](https://vincit.github.io/objection.js/api/model/static-properties.html#static-idcolumn) in all our models.
Cruikshanks added a commit that referenced this pull request Dec 16, 2022
It was spotted whilst working on [Update "create bill run" endpoint to create a bill run](#56) that we had an issue with our [Objection models](https://vincit.github.io/objection.js/).

The previous team didn't use the convention of just calling the unique identifier in each table `id`. Instead they incorporate the table name, for example, `billing_batch_id`. **Objection** is expecting the identifier column to be `id` and is failing when in some cases.

Because of this we need to go back and specify [idColumn](https://vincit.github.io/objection.js/api/model/static-properties.html#static-idcolumn) in all our models.
Cruikshanks added a commit that referenced this pull request Dec 19, 2022
It was spotted whilst working on [Update "create bill run" endpoint to create a bill run](#56) that we had an issue with our [Objection models](https://vincit.github.io/objection.js/).

The previous team didn't use the convention of just calling the unique identifier in each table `id`. Instead, they incorporate the table name, for example, `billing_batch_id`. **Objection** is expecting the identifier column to be `id` and is failing when in some cases.

Because of this, we need to go back and specify [idColumn](https://vincit.github.io/objection.js/api/model/static-properties.html#static-idcolumn) in all our models.
Cruikshanks added a commit that referenced this pull request Dec 20, 2022
https://eaflood.atlassian.net/browse/WATER-3854

We are about to [Update "create bill run" endpoint to create a bill run](#56). Currently, everything is happening in the controller whereas our convention is to do everything in a service and keep our controllers ['skinny'](https://blog.makersacademy.com/forget-fat-models-its-time-for-skinny-controllers-and-skinny-models-a9b84ec481b7).

So, we need a service, something like `SupplementaryService`. But oh no! It already exists.

This change is about refactoring the code currently in `SupplementaryService` to a more explicit testing version so we can free up the namespace. While we're at it, we also rename our `/test` path to `/qa` because everyone is getting confused when they come across a `test/` folder in the repo!
Cruikshanks added a commit that referenced this pull request Dec 21, 2022
https://eaflood.atlassian.net/browse/WATER-3854

We are about to [Update "create bill run" endpoint to create a bill run](#56). Currently, everything is happening in the controller whereas our convention is to do everything in a service and keep our controllers ['skinny'](https://blog.makersacademy.com/forget-fat-models-its-time-for-skinny-controllers-and-skinny-models-a9b84ec481b7).

So, we need a service, something like `SupplementaryService`. But oh no! It already exists.

This change is about refactoring the code currently in `SupplementaryService` to a more explicit testing version so we can free up the namespace. Whilst we're at it we also rename the `/test` path to `check/` as everyone was getting confused by seeing `test/` folders in various places in the code 😁
@Cruikshanks Cruikshanks force-pushed the update-endpoint-to-create-bill-run branch from 818543e to f2e219b Compare December 23, 2022 14:59
@Cruikshanks Cruikshanks force-pushed the update-endpoint-to-create-bill-run branch 2 times, most recently from 12a5a6a to 121661b Compare January 2, 2023 22:08
StuAA78 and others added 5 commits January 2, 2023 22:58
https://eaflood.atlassian.net/browse/WATER-3854

When we set up our "create bill run" endpoint, we had it simply respond to requests with a dummy response. We now update it to actually create a bill run and an event, and return the required details in the same format as the dummy response.
As we start to look at creating entries in the db, we run into an issue when Objection errors because it can't find an `id` column. On investigation it turns out that if the primary id column isn't called `id`, it needs to be specified in the model. We therefore add an `idColumn` static method to our billing batch model
We update our `createBillRun` controller to create a record for the bill run in the db. We initially hardcode the financial year fields just to get it working, with the intention of pulling these through properly from the request in a later commit
We try and follow that the path you see in the url matches where the controller sits in the repo.
We need something that handles formatting the response for the POST `/bill-runs` endpoint. We use what we did in DEFRA/water-abstraction-ui#2247 as a spec.
@Cruikshanks Cruikshanks force-pushed the update-endpoint-to-create-bill-run branch from 534bb73 to e005c3a Compare January 2, 2023 22:58
At the start of a new bill run we need to

- create the initial billing batch record
- create the associated event record
- send a request to the SROC Charging Module API and link it to our billing batch

With those 3 things done we can return control back to the requester (which will be the UI) whilst we get on with the rest of the bill run process.

This adds the service that will handle those 3 steps. We're waiting on additional functionality before we can do the last one. But for now steps 1 & 2 are done and we'll have a home for step 3 when it's ready!
Now we've created the InitiateBillingBatchService we refactor the bill runs controller to use it.
@Cruikshanks Cruikshanks marked this pull request as ready for review January 3, 2023 00:02
Copy link
Member

@Cruikshanks Cruikshanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😁

@StuAA78 StuAA78 merged commit 73e3a3c into main Jan 3, 2023
@StuAA78 StuAA78 deleted the update-endpoint-to-create-bill-run branch January 3, 2023 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants