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

Rename gauging stations to monitoring stations #1415

Merged
merged 8 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 0 additions & 39 deletions app/models/licence-gauging-station.model.js

This file was deleted.

39 changes: 39 additions & 0 deletions app/models/licence-monitoring-station.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict'

/**
* Model for licence_monitoring_stations (water.licence_monitoring_stations)
* @module LicenceMonitoringStationModel
*/

const { Model } = require('objection')

const BaseModel = require('./base.model.js')

class LicenceMonitoringStationModel extends BaseModel {
static get tableName () {
return 'licenceMonitoringStations'
}

static get relationMappings () {
return {
monitoringStation: {
relation: Model.BelongsToOneRelation,
modelClass: 'monitoring-station.model',
join: {
from: 'licenceMonitoringStations.monitoringStationId',
to: 'monitoringStations.id'
}
},
licence: {
relation: Model.BelongsToOneRelation,
modelClass: 'licence.model',
join: {
from: 'licenceMonitoringStations.licenceId',
to: 'licences.id'
}
}
}
}
}

module.exports = LicenceMonitoringStationModel
6 changes: 3 additions & 3 deletions app/models/licence.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ class LicenceModel extends BaseModel {
to: 'licenceDocumentHeaders.licenceRef'
}
},
licenceGaugingStations: {
licenceMonitoringStations: {
relation: Model.HasManyRelation,
modelClass: 'licence-gauging-station.model',
modelClass: 'licence-monitoring-station.model',
join: {
from: 'licences.id',
to: 'licenceGaugingStations.licenceId'
to: 'licenceMonitoringStations.licenceId'
}
},
licenceSupplementaryYears: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
'use strict'

/**
* Model for gauging_stations (water.gauging_stations)
* @module GaugingStationModel
* Model for monitoring_stations (water.gauging_stations)
* @module MonitoringStationModel
*/

const { Model } = require('objection')

const BaseModel = require('./base.model.js')

class GaugingStationModel extends BaseModel {
class MonitoringStationModel extends BaseModel {
static get tableName () {
return 'gaugingStations'
return 'monitoringStations'
}

// Defining which fields contain json allows us to insert an object without needing to stringify it first
Expand All @@ -23,16 +23,16 @@ class GaugingStationModel extends BaseModel {

static get relationMappings () {
return {
licenceGaugingStations: {
licenceMonitoringStations: {
relation: Model.HasManyRelation,
modelClass: 'licence-gauging-station.model',
modelClass: 'licence-monitoring-station.model',
join: {
from: 'gaugingStations.id',
to: 'licenceGaugingStations.gaugingStationId'
from: 'monitoringStations.id',
to: 'licenceMonitoringStations.monitoringStationId'
}
}
}
}
}

module.exports = GaugingStationModel
module.exports = MonitoringStationModel
12 changes: 6 additions & 6 deletions app/presenters/licences/view-licence-summary.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function go (licence) {
expiredDate,
id,
licenceDocumentHeader,
licenceGaugingStations,
licenceMonitoringStations,
region,
startDate
} = licence
Expand All @@ -48,7 +48,7 @@ function go (licence) {
endDate: _endDate(expiredDate),
licenceHolder: _licenceHolder(licence),
licenceId: id,
monitoringStations: _monitoringStations(licenceGaugingStations),
monitoringStations: _monitoringStations(licenceMonitoringStations),
purposes,
purposesCount: licenceVersionPurposes ? licenceVersionPurposes.length : 0,
region: region.displayName,
Expand Down Expand Up @@ -198,19 +198,19 @@ function _licenceVersionPurposes (licence) {
return currentVersion.licenceVersionPurposes
}

function _monitoringStations (licenceGaugingStations) {
function _monitoringStations (licenceMonitoringStations) {
const monitoringStations = []

for (const licenceGaugingStation of licenceGaugingStations) {
for (const licenceMonitoringStation of licenceMonitoringStations) {
const alreadySeen = monitoringStations.some((monitoringStation) => {
return monitoringStation.id === licenceGaugingStation.gaugingStation.id
return monitoringStation.id === licenceMonitoringStation.monitoringStation.id
})

if (alreadySeen) {
continue
}

monitoringStations.push(licenceGaugingStation.gaugingStation)
monitoringStations.push(licenceMonitoringStation.monitoringStation)
}

return monitoringStations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ const { formatAbstractionPeriod, formatLongDate } = require('../base.presenter.j
* Formats the monitoring station details and related licences data for the view monitoring-station page
*
* @param {object} auth - The auth object taken from `request.auth` containing user details
* @param {module:GaugingStationModel[]} monitoringStation - The monitoring station and associated licences data
* @param {module:MonitoringStationModel[]} monitoringStation - The monitoring station and associated licences data
* returned by `FetchMonitoringStationService`
*
* @returns {object} monitoring station and licence data needed by the view template
*/
function go (auth, monitoringStation) {
const formattedLicences = _formatLicences(monitoringStation.licenceGaugingStations)
const formattedLicences = _formatLicences(monitoringStation.licenceMonitoringStations)
const sortedLicences = _sortLicences(formattedLicences)
const groupedLicences = _groupLicences(sortedLicences)

Expand Down Expand Up @@ -143,7 +143,7 @@ function _pageTitle (riverName, stationName) {

function _sortLicences (licences) {
// NOTE: Sorting the licences in order of `licenceRef` proved difficult to complete as licences are fetched by those
// linked to a licence gauging station, where the licence reference is stored inside the nested licence object.
// linked to a licence monitoring station, where the licence reference is stored inside the nested licence object.
// However, by extracting and comparing `licenceRef` directly within the sort function, we can order the licences
// alphabetically. The sort logic below compares the `licenceRef` of each licence and orders them in ascending order.
return licences.sort((licenceA, licenceB) => {
Expand Down
8 changes: 4 additions & 4 deletions app/services/data/load/load.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ const CompanyContactHelper = require('../../../../test/support/helpers/company-c
const CompanyHelper = require('../../../../test/support/helpers/company.helper.js')
const ContactHelper = require('../../../../test/support/helpers/contact.helper.js')
const EventHelper = require('../../../../test/support/helpers/event.helper.js')
const GaugingStationHelper = require('../../../../test/support/helpers/gauging-station.helper.js')
const LicenceAgreementHelper = require('../../../../test/support/helpers/licence-agreement.helper.js')
const LicenceDocumentHeaderHelper = require('../../../../test/support/helpers/licence-document-header.helper.js')
const LicenceDocumentRoleHelper = require('../../../../test/support/helpers/licence-document-role.helper.js')
const LicenceDocumentHelper = require('../../../../test/support/helpers/licence-document.helper.js')
const LicenceEntityRoleHelper = require('../../../../test/support/helpers/licence-entity-role.helper.js')
const LicenceEntityHelper = require('../../../../test/support/helpers/licence-entity.helper.js')
const LicenceGaugingStationHelper = require('../../../../test/support/helpers/licence-gauging-station.helper.js')
const LicenceMonitoringStationHelper = require('../../../../test/support/helpers/licence-monitoring-station.helper.js')
const LicenceRoleHelper = require('../../../../test/support/helpers/licence-role.helper.js')
const LicenceSupplementaryYearHelper = require('../../../../test/support/helpers/licence-supplementary-year.helper.js')
const LicenceVersionPurposeConditionHelper = require('../../../../test/support/helpers/licence-version-purpose-condition.helper.js')
Expand All @@ -42,6 +41,7 @@ const LicenceVersionPurposePointHelper = require('../../../../test/support/helpe
const LicenceVersionHelper = require('../../../../test/support/helpers/licence-version.helper.js')
const LicenceHelper = require('../../../../test/support/helpers/licence.helper.js')
const ModLogHelper = require('../../../../test/support/helpers/mod-log.helper.js')
const MonitoringStationHelper = require('../../../../test/support/helpers/monitoring-station.helper.js')
const PointHelper = require('../../../../test/support/helpers/point.helper.js')
const PermitLicenceHelper = require('../../../../test/support/helpers/permit-licence.helper.js')
const ReturnLogHelper = require('../../../../test/support/helpers/return-log.helper.js')
Expand Down Expand Up @@ -86,14 +86,13 @@ const LOAD_HELPERS = {
companies: { helper: CompanyHelper, test: true, legacy: { schema: 'crm_v2', table: 'companies', id: 'company_id' } },
contacts: { helper: ContactHelper, test: true, legacy: { schema: 'crm_v2', table: 'contacts', id: 'contact_id' } },
events: { helper: EventHelper, test: false },
gaugingStations: { helper: GaugingStationHelper, test: true, legacy: { schema: 'water', table: 'gauging_stations', id: 'gauging_station_id' } },
licenceAgreements: { helper: LicenceAgreementHelper, test: true, legacy: { schema: 'water', table: 'licence_agreements', id: 'licence_agreement_id' } },
licenceDocumentHeaders: { helper: LicenceDocumentHeaderHelper, test: false },
licenceDocumentRoles: { helper: LicenceDocumentRoleHelper, test: true, legacy: { schema: 'crm_v2', table: 'document_roles', id: 'document_role_id' } },
licenceDocuments: { helper: LicenceDocumentHelper, test: true, legacy: { schema: 'crm_v2', table: 'documents', id: 'document_id' } },
licenceEntityRoles: { helper: LicenceEntityRoleHelper, test: false },
licenceEntities: { helper: LicenceEntityHelper, test: false },
licenceGaugingStations: { helper: LicenceGaugingStationHelper, test: true, legacy: { schema: 'water', table: 'licence_gauging_stations', id: 'licence_gauging_station_id' } },
licenceMonitoringStations: { helper: LicenceMonitoringStationHelper, test: true, legacy: { schema: 'water', table: 'licence_gauging_stations', id: 'licence_gauging_station_id' } },
licenceRoles: { helper: LicenceRoleHelper, test: false },
LicenceSupplementaryYears: { helper: LicenceSupplementaryYearHelper, test: false },
licenceVersionPurposeConditions: { helper: LicenceVersionPurposeConditionHelper, test: false },
Expand All @@ -102,6 +101,7 @@ const LOAD_HELPERS = {
licenceVersions: { helper: LicenceVersionHelper, test: true, legacy: { schema: 'water', table: 'licence_versions', id: 'licence_version_id' } },
licences: { helper: LicenceHelper, test: true, legacy: { schema: 'water', table: 'licences', id: 'licence_id' } },
modLogs: { helper: ModLogHelper, test: false },
monitoringStations: { helper: MonitoringStationHelper, test: true, legacy: { schema: 'water', table: 'gauging_stations', id: 'gauging_station_id' } },
points: { helper: PointHelper, test: false },
permitLicences: { helper: PermitLicenceHelper, test: false },
returnLogs: { helper: ReturnLogHelper, test: true, legacy: { schema: 'returns', table: 'returns', id: 'return_id' } },
Expand Down
8 changes: 4 additions & 4 deletions app/services/licences/fetch-licence-summary.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ async function _fetch (licenceId) {
'displayTitle'
])
})
.withGraphFetched('licenceGaugingStations')
.modifyGraph('licenceGaugingStations', (builder) => {
.withGraphFetched('licenceMonitoringStations')
.modifyGraph('licenceMonitoringStations', (builder) => {
builder.select([
'id'
])
.whereNull('deletedAt')
})
.withGraphFetched('licenceGaugingStations.gaugingStation')
.modifyGraph('licenceGaugingStations.gaugingStation', (builder) => {
.withGraphFetched('licenceMonitoringStations.monitoringStation')
.modifyGraph('licenceMonitoringStations.monitoringStation', (builder) => {
builder.select([
'id',
'label'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
* @module FetchMonitoringStationService
*/

const GaugingStationModel = require('../../models/gauging-station.model.js')
const MonitoringStationModel = require('../../models/monitoring-station.model.js')

/**
* Fetches the matching monitoring station and associated licences needed for the view monitoring-station page
*
* @param {string} monitoringStationId - The UUID for the monitoring station to fetch
*
* @returns {Promise<module:GaugingStationModel>} the matching `GaugingStationModel` populated with the data needed for
* the view monitoring station page
* @returns {Promise<module:MonitoringStationModel>} the matching `MonitoringStationModel` populated with the data
* needed for the view monitoring station page
*/
async function go (monitoringStationId) {
return _fetch(monitoringStationId)
}

async function _fetch (monitoringStationId) {
return GaugingStationModel.query()
return MonitoringStationModel.query()
.findById(monitoringStationId)
.select([
'id',
Expand All @@ -30,8 +30,8 @@ async function _fetch (monitoringStationId) {
'stationReference',
'wiskiId'
])
.withGraphFetched('licenceGaugingStations')
.modifyGraph('licenceGaugingStations', (builder) => {
.withGraphFetched('licenceMonitoringStations')
.modifyGraph('licenceMonitoringStations', (builder) => {
builder
.select([
'abstractionPeriodStartDay',
Expand All @@ -50,8 +50,8 @@ async function _fetch (monitoringStationId) {
{ column: 'statusUpdatedAt', order: 'desc', nulls: 'last' }
])
})
.withGraphFetched('licenceGaugingStations.licence')
.modifyGraph('licenceGaugingStations.licence', (builder) => {
.withGraphFetched('licenceMonitoringStations.licence')
.modifyGraph('licenceMonitoringStations.licence', (builder) => {
builder
.select([
'id',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'use strict'

exports.up = function (knex) {
return knex
.schema
.dropViewIfExists('gauging_stations')
.createView('monitoring_stations', (view) => {
view.as(knex('gauging_stations').withSchema('water').select([
'gauging_station_id AS id',
'label',
'lat',
'long',
'easting',
'northing',
'grid_reference',
'catchment_name ',
'river_name',
'wiski_id',
'station_reference',
'status',
'metadata',
'hydrology_station_id',
// 'is_test'
'date_created AS created_at',
'date_updated AS updated_at'
]))
})
}

exports.down = function (knex) {
return knex
.schema
.dropViewIfExists('monitoring_stations')
.createView('gauging_stations', (view) => {
view.as(knex('gauging_stations').withSchema('water').select([
'gauging_station_id AS id',
'label',
'lat',
'long',
'easting',
'northing',
'grid_reference',
'catchment_name ',
'river_name',
'wiski_id',
'station_reference',
'status',
'metadata',
'hydrology_station_id',
// 'is_test'
'date_created AS created_at',
'date_updated AS updated_at'
]))
})
}
Loading
Loading