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

Add billing_transaction model to water-abstraction-system #135

Merged
merged 10 commits into from
Mar 2, 2023

Conversation

Jozzey
Copy link
Contributor

@Jozzey Jozzey commented Mar 2, 2023

https://eaflood.atlassian.net/browse/WATER-3906
https://eaflood.atlassian.net/browse/WATER-3909

billing_transaction is linked to a billing invoice licence record. We need it to store the transaction detail for an invoice.

  • add the model
  • update relationships
  • add unit tests for model
  • update billing invoice licence model unit tests
  • add test helper

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

`billing_transaction` is linked to a billing invoice licence record. We need it to store the transaction detail for an invoice.

- add the model
- update relationships
- add unit tests for model
- update billing invoice licence model unit tests
- add test helper
@Jozzey Jozzey added the enhancement New feature or request label Mar 2, 2023
@Jozzey Jozzey self-assigned this Mar 2, 2023
@Jozzey Jozzey marked this pull request as ready for review March 2, 2023 12:50
@Jozzey Jozzey requested a review from Cruikshanks March 2, 2023 12:50
@Jozzey Jozzey merged commit 14d2c22 into main Mar 2, 2023
@Jozzey Jozzey deleted the add-billing_transaction-model branch March 2, 2023 13:33
Cruikshanks added a commit that referenced this pull request Mar 5, 2023
https://eaflood.atlassian.net/browse/WATER-3906
https://eaflood.atlassian.net/browse/WATER-3927

With our [Add billing_transaction model to water-abstraction-system](#135) change we had our first decimal field.

What we didn't realise when we created the migration is that the [pg package](https://www.npmjs.com/package/pg) returns decimals as strings.

We've encountered this issue before with BigInt's on the [charging-module-api](https://github.com/DEFRA/sroc-charging-module-api) which is why `db/db.js` has logic to parse the string **pg** returns back into a integer.

The root cause is the same. Out of concern about loss of precision the DB values are returned as strings. We know we're not dealing with values where this would be an issue so we can have **pg** implicitly parse the decimal strings into floats.

[This post](https://stackoverflow.com/a/39176670/6117745) focuses on the BigInt issue. But the cause and solution are the same for decimals.

So, this change ensures when we use [Knex](https://github.com/knex/knex) or [Objection.js](https://github.com/vincit/objection.js) we see floats (numbers) instead of strings.
Cruikshanks added a commit that referenced this pull request Mar 5, 2023
https://eaflood.atlassian.net/browse/WATER-3906
https://eaflood.atlassian.net/browse/WATER-3927

With our [Add billing_transaction model to water-abstraction-system](#135) change we had our first decimal field.

When we created the migration, we didn't realise that the [pg package](https://www.npmjs.com/package/pg) returns decimals as strings.

We've encountered this issue with BigInt on the [charging-module-api](https://github.com/DEFRA/sroc-charging-module-api) which is why `db/db.js` has logic to parse the string **pg** returns back into an integer.

The root cause is the same. Out of concern about the loss of precision the DB values are returned as strings. We know we're not dealing with values where this would be an issue so we can have **pg** implicitly parse the decimal strings into floats.

[This post](https://stackoverflow.com/a/39176670/6117745) focuses on the BigInt issue. But the cause and solution are the same for decimals.

So, this change ensures when we use [Knex](https://github.com/knex/knex) or [Objection.js](https://github.com/vincit/objection.js) we see floats (numbers) instead of strings.

---

Whilst making this change we also updated the existing fix for BigInts to use the same solution. Using named types rather than a 'magic number' from the DB was preferable in our opinion
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