-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create
water
schema models & helpers (#560)
https://eaflood.atlassian.net/browse/WATER-4057 As part of the work we have been doing on two-part tariff we are going to be creating all our new tables in the default `public` schema. We have also decided that when there is a legacy table that we are still going to need we will create a [View](https://www.postgresql.org/docs/current/sql-createview.html) of it in the `public` schema. This allows us to correct any issues with naming conventions, strip out unused fields, and join entities that are currently sat in different schemas. The first example of this approach was done in PR #531 . This change adds the models and helpers for the views in the `water` schema that were created in PR #551 > The final step will then be to refactor the existing code to use the new models and delete the old legacy ones.
- Loading branch information
Showing
49 changed files
with
3,707 additions
and
1 deletion.
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,47 @@ | ||
'use strict' | ||
|
||
/** | ||
* Model for bill_licences (water.billing_invoice_licences) | ||
* @module BillLicenceModel | ||
*/ | ||
|
||
const { Model } = require('objection') | ||
|
||
const BaseModel = require('./base.model.js') | ||
|
||
class BillLicenceModel extends BaseModel { | ||
static get tableName () { | ||
return 'billLicences' | ||
} | ||
|
||
static get relationMappings () { | ||
return { | ||
bill: { | ||
relation: Model.BelongsToOneRelation, | ||
modelClass: 'bill.model', | ||
join: { | ||
from: 'billLicences.billId', | ||
to: 'bills.id' | ||
} | ||
}, | ||
transactions: { | ||
relation: Model.HasManyRelation, | ||
modelClass: 'transaction.model', | ||
join: { | ||
from: 'billLicences.id', | ||
to: 'transactions.billLicenceId' | ||
} | ||
}, | ||
licence: { | ||
relation: Model.BelongsToOneRelation, | ||
modelClass: 'licence.model', | ||
join: { | ||
from: 'billLicences.licenceId', | ||
to: 'licences.id' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
module.exports = BillLicenceModel |
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,67 @@ | ||
'use strict' | ||
|
||
/** | ||
* Model for bill_run_volumes (water.billing_volumes) | ||
* @module BillRunVolumeModel | ||
*/ | ||
|
||
const { Model } = require('objection') | ||
|
||
const BaseModel = require('./base.model.js') | ||
|
||
class BillRunVolumeModel extends BaseModel { | ||
static get tableName () { | ||
return 'billRunVolumes' | ||
} | ||
|
||
static get relationMappings () { | ||
return { | ||
billRun: { | ||
relation: Model.BelongsToOneRelation, | ||
modelClass: 'bill-run.model', | ||
join: { | ||
from: 'billRunVolumes.billRunId', | ||
to: 'billRuns.id' | ||
} | ||
}, | ||
chargeReference: { | ||
relation: Model.BelongsToOneRelation, | ||
modelClass: 'charge-reference.model', | ||
join: { | ||
from: 'billRunVolumes.chargeReferenceId', | ||
to: 'chargeReferences.id' | ||
} | ||
} | ||
} | ||
} | ||
|
||
// NOTE: When we checked the live data the only statuses we could find in use were; 10, 40, 50, 60, 70, 90 and 100 | ||
static get twoPartTariffStatuses () { | ||
return { | ||
noReturnsSubmitted: 10, | ||
underQuery: 20, | ||
received: 30, | ||
someReturnsDue: 40, | ||
lateReturns: 50, | ||
overAbstraction: 60, | ||
noReturnsForMatching: 70, | ||
notDueForBilling: 80, | ||
returnLineOverlapsChargePeriod: 90, | ||
noMatchingChargeElement: 100 | ||
} | ||
} | ||
|
||
$twoPartTariffStatus () { | ||
const index = Object.values(BillRunVolumeModel.twoPartTariffStatuses).findIndex((value) => { | ||
return value === this.twoPartTariffStatus | ||
}) | ||
|
||
if (index !== -1) { | ||
return Object.keys(BillRunVolumeModel.twoPartTariffStatuses)[index] | ||
} | ||
|
||
return null | ||
} | ||
} | ||
|
||
module.exports = BillRunVolumeModel |
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,61 @@ | ||
'use strict' | ||
|
||
/** | ||
* Model for bill_runs (water.billing_batches) | ||
* @module BillRunModel | ||
*/ | ||
|
||
const { Model } = require('objection') | ||
|
||
const BaseModel = require('./base.model.js') | ||
|
||
class BillRunModel extends BaseModel { | ||
static get tableName () { | ||
return 'billRuns' | ||
} | ||
|
||
static get relationMappings () { | ||
return { | ||
region: { | ||
relation: Model.BelongsToOneRelation, | ||
modelClass: 'region.model', | ||
join: { | ||
from: 'billRuns.regionId', | ||
to: 'regions.id' | ||
} | ||
}, | ||
bills: { | ||
relation: Model.HasManyRelation, | ||
modelClass: 'bill.model', | ||
join: { | ||
from: 'billRuns.id', | ||
to: 'bills.billRunId' | ||
} | ||
}, | ||
billRunVolumes: { | ||
relation: Model.HasManyRelation, | ||
modelClass: 'bill-run-volume.model', | ||
join: { | ||
from: 'billRuns.id', | ||
to: 'billRunVolumes.billRunId' | ||
} | ||
} | ||
} | ||
} | ||
|
||
static get errorCodes () { | ||
return { | ||
failedToPopulateChargeVersions: 10, | ||
failedToProcessChargeVersions: 20, | ||
failedToPrepareTransactions: 30, | ||
failedToCreateCharge: 40, | ||
failedToCreateBillRun: 50, | ||
failedToDeleteInvoice: 60, | ||
failedToProcessTwoPartTariff: 70, | ||
failedToGetChargeModuleBillRunSummary: 80, | ||
failedToProcessRebilling: 90 | ||
} | ||
} | ||
} | ||
|
||
module.exports = BillRunModel |
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,39 @@ | ||
'use strict' | ||
|
||
/** | ||
* Model for bills (water.billing_invoices) | ||
* @module BillModel | ||
*/ | ||
|
||
const { Model } = require('objection') | ||
|
||
const BaseModel = require('./base.model.js') | ||
|
||
class BillModel extends BaseModel { | ||
static get tableName () { | ||
return 'bills' | ||
} | ||
|
||
static get relationMappings () { | ||
return { | ||
billRun: { | ||
relation: Model.BelongsToOneRelation, | ||
modelClass: 'bill-run.model', | ||
join: { | ||
from: 'bills.billRunId', | ||
to: 'billRuns.id' | ||
} | ||
}, | ||
billLicences: { | ||
relation: Model.HasManyRelation, | ||
modelClass: 'bill-licence.model', | ||
join: { | ||
from: 'bills.id', | ||
to: 'billLicences.billId' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
module.exports = BillModel |
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,31 @@ | ||
'use strict' | ||
|
||
/** | ||
* Model for change_reasons (water.change_reasons) | ||
* @module ChangeReasonModel | ||
*/ | ||
|
||
const { Model } = require('objection') | ||
|
||
const BaseModel = require('./base.model.js') | ||
|
||
class ChangeReasonModel extends BaseModel { | ||
static get tableName () { | ||
return 'changeReasons' | ||
} | ||
|
||
static get relationMappings () { | ||
return { | ||
chargeVersions: { | ||
relation: Model.HasManyRelation, | ||
modelClass: 'charge-version.model', | ||
join: { | ||
from: 'changeReasons.id', | ||
to: 'chargeVersions.changeReasonId' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
module.exports = ChangeReasonModel |
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,31 @@ | ||
'use strict' | ||
|
||
/** | ||
* Model for charge_categories (water.billing_charge_categories) | ||
* @module ChargeCategoryModel | ||
*/ | ||
|
||
const { Model } = require('objection') | ||
|
||
const BaseModel = require('./base.model.js') | ||
|
||
class ChargeCategoryModel extends BaseModel { | ||
static get tableName () { | ||
return 'chargeCategories' | ||
} | ||
|
||
static get relationMappings () { | ||
return { | ||
chargeReferences: { | ||
relation: Model.HasManyRelation, | ||
modelClass: 'charge-reference.model', | ||
join: { | ||
from: 'chargeCategories.id', | ||
to: 'chargeReferences.chargeCategoryId' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
module.exports = ChargeCategoryModel |
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,39 @@ | ||
'use strict' | ||
|
||
/** | ||
* Model for charge_elements (water.charge_purposes) | ||
* @module ChargeElementModel | ||
*/ | ||
|
||
const { Model } = require('objection') | ||
|
||
const BaseModel = require('./base.model.js') | ||
|
||
class ChargeElementModel extends BaseModel { | ||
static get tableName () { | ||
return 'chargeElements' | ||
} | ||
|
||
static get relationMappings () { | ||
return { | ||
chargeReference: { | ||
relation: Model.BelongsToOneRelation, | ||
modelClass: 'charge-reference.model', | ||
join: { | ||
from: 'chargeElements.chargeReferenceId', | ||
to: 'chargeReferences.id' | ||
} | ||
}, | ||
purpose: { | ||
relation: Model.BelongsToOneRelation, | ||
modelClass: 'purpose.model', | ||
join: { | ||
from: 'chargeElements.purposeId', | ||
to: 'purposes.id' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
module.exports = ChargeElementModel |
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,71 @@ | ||
'use strict' | ||
|
||
/** | ||
* Model for charge_references (water.charge_elements) | ||
* @module ChargeReferenceModel | ||
*/ | ||
|
||
const { Model } = require('objection') | ||
|
||
const BaseModel = require('./base.model.js') | ||
|
||
class ChargeReferenceModel extends BaseModel { | ||
static get tableName () { | ||
return 'chargeReferences' | ||
} | ||
|
||
static get relationMappings () { | ||
return { | ||
billRunVolumes: { | ||
relation: Model.HasManyRelation, | ||
modelClass: 'bill-run-volume.model', | ||
join: { | ||
from: 'chargeReferences.id', | ||
to: 'billRunVolumes.chargeReferenceId' | ||
} | ||
}, | ||
chargeVersion: { | ||
relation: Model.BelongsToOneRelation, | ||
modelClass: 'charge-version.model', | ||
join: { | ||
from: 'chargeReferences.chargeVersionId', | ||
to: 'chargeVersions.id' | ||
} | ||
}, | ||
chargeCategory: { | ||
relation: Model.BelongsToOneRelation, | ||
modelClass: 'charge-category.model', | ||
join: { | ||
from: 'chargeReferences.chargeCategoryId', | ||
to: 'chargeCategories.id' | ||
} | ||
}, | ||
chargeElements: { | ||
relation: Model.HasManyRelation, | ||
modelClass: 'charge-element.model', | ||
join: { | ||
from: 'chargeReferences.id', | ||
to: 'chargeElements.chargeReferenceId' | ||
} | ||
}, | ||
purpose: { | ||
relation: Model.BelongsToOneRelation, | ||
modelClass: 'purpose.model', | ||
join: { | ||
from: 'chargeReferences.purposeId', | ||
to: 'purposes.id' | ||
} | ||
}, | ||
transactions: { | ||
relation: Model.HasManyRelation, | ||
modelClass: 'transaction.model', | ||
join: { | ||
from: 'chargeReferences.id', | ||
to: 'transactions.chargeReferenceId' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
module.exports = ChargeReferenceModel |
Oops, something went wrong.