Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
rvsiyad committed Dec 24, 2024
1 parent df5be82 commit 9f92cfe
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 83 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

// const util = require('util')
const util = require('util')
const PointModel = require('../../models/point.model.js')

/**
Expand All @@ -10,10 +10,14 @@ const PointModel = require('../../models/point.model.js')
*/
function go(data) {
const conditions = _formatAbstractionConditions(data.conditions)
console.log('🚀🚀🚀 ~ conditions:', conditions)
// console.log('🚀🚀🚀 ~ conditions:', conditions)
const groupedConditions = _groupAbstractionConditions(conditions)
console.log('🚀🚀🚀 ~ groupedConditions:', groupedConditions)
// console.log('🚀🚀🚀 ~ Formatted conditions: ', util.inspect(conditions, false, null, true /* enable colors */))
// console.log('🚀🚀🚀 ~ groupedConditions:', groupedConditions)
// console.log('🚀🚀🚀 ~ GroupedConditions: ', util.inspect(groupedConditions, false, null, true /* enable colors */))

// for (const [displayTitle, groupedCondition] of Object.entries(groupedConditions)) {
// console.log('🚀🚀🚀 ~ groupedCondition:', groupedCondition)
// }

return {
conditions,
Expand All @@ -27,9 +31,11 @@ function _formatAbstractionConditions(conditions) {
return conditions.map((condition) => {
return {
displayTitle: condition.displayTitle,
point: formatPoint(condition),
point: _formatPoint(condition),
purpose: condition.purposeDescription,
notes: condition.notes,
param1: _formatParam(condition.param1Label, condition.param1),
param2: _formatParam(condition.param2Label, condition.param2),
otherInformation: condition.notes,
conditionTypeDescription: condition.conditionTypeDescription,
subcodeDescription: condition.subcodeDescription
}
Expand All @@ -48,12 +54,30 @@ function _groupAbstractionConditions(conditions) {
}, {})
}

function formatPoint(condition) {
function _formatPoint(condition) {
const point = PointModel.fromJson(condition)

return point.$describe()
}

function _formatParam(paramLabel, param) {
if ((!paramLabel && !param) || (paramLabel && !param)) {
return null
}

if (!paramLabel && param) {
return {
paramLabel: 'Param label',
param
}
}

return {
paramLabel,
param
}
}

module.exports = {
go
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const LicenceModel = require('../../models/licence.model.js')
*/
async function go(licenceId) {
const conditions = await _fetchConditions(licenceId)
// console.log('🚀🚀🚀 ~ conditions:', conditions)
const licence = await _fetchLicence(licenceId)

return {
Expand All @@ -26,6 +27,42 @@ async function _fetchLicence(licenceId) {
return LicenceModel.query().findById(licenceId).select('id', 'licenceRef')
}

async function _fetchConditions(licenceId) {
return await db
.select(
'lvpct.displayTitle',
'lvpct.description AS conditionTypeDescription',
'lvpct.subcodeDescription',
'lvpct.param1Label',
'lvpct.param2Label',
'lvpc.param1',
'lvpc.param2',
'lvpc.param1',
'lvpc.param2',
'lvpc.notes',
'po.description AS pointDescription',
'po.ngr1',
'po.ngr2',
'po.ngr3',
'po.ngr4',
'pu.description AS purposeDescription'
)
.from('licence_version_purpose_condition_types AS lvpct')
.innerJoin(
'licence_version_purpose_conditions AS lvpc',
'lvpct.id',
'lvpc.licence_version_purpose_condition_type_id'
)
.innerJoin('licence_version_purposes AS lvp', 'lvpc.licence_version_purpose_id', 'lvp.id')
.innerJoin('licence_version_purpose_points AS lvpp', 'lvpp.licence_version_purpose_id', 'lvp.id')
.innerJoin('points AS po', 'po.id', 'lvpp.point_id')
.innerJoin('purposes as pu', 'pu.id', 'lvp.purpose_id')
.innerJoin('licence_versions AS lv', 'lvp.licence_version_id', 'lv.id')
.innerJoin('licences AS l', 'lv.licence_id', 'l.id')
.where('l.id', licenceId)
.andWhere('lv.status', 'current')
}

// async function _fetchConditions(licenceId) {
// return await db
// .select(
Expand Down Expand Up @@ -61,38 +98,6 @@ async function _fetchLicence(licenceId) {
// .groupBy('lvpct.displayTitle')
// }

async function _fetchConditions(licenceId) {
return await db
.select(
'lvpct.displayTitle',
'lvpct.description AS conditionTypeDescription',
'lvpct.subcodeDescription',
'lvpc.param1',
'lvpc.param2',
'lvpc.notes',
'po.description AS pointDescription',
'po.ngr1',
'po.ngr2',
'po.ngr3',
'po.ngr4',
'pu.description AS purposeDescription'
)
.from('licence_version_purpose_condition_types AS lvpct')
.innerJoin(
'licence_version_purpose_conditions AS lvpc',
'lvpct.id',
'lvpc.licence_version_purpose_condition_type_id'
)
.innerJoin('licence_version_purposes AS lvp', 'lvpc.licence_version_purpose_id', 'lvp.id')
.innerJoin('licence_version_purpose_points AS lvpp', 'lvpp.licence_version_purpose_id', 'lvp.id')
.innerJoin('points AS po', 'po.id', 'lvpp.point_id')
.innerJoin('purposes as pu', 'pu.id', 'lvp.purpose_id')
.innerJoin('licence_versions AS lv', 'lvp.licence_version_id', 'lv.id')
.innerJoin('licences AS l', 'lv.licence_id', 'l.id')
.where('l.id', licenceId)
.andWhere('lv.status', 'current')
}

// async function _fetch(licenceId) {
// return LicenceVersionPurposeConditionTypeModel.query()
// .select('displayTitle', 'description', 'subcodeDescription')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const FetchLicenceAbstractionConditionsService = require('../../services/licences/fetch-licence-abstraction-conditions.service.js')
const ViewLicenceAbstractionConditionsPresenter = require('../../presenters/licences/view-licence-abstraction-conditions.presenter.js')

const util = require('util')
// const util = require('util')

/**
* Calls the licence abstraction conditions presenter
Expand All @@ -15,7 +15,7 @@ async function go(licenceId) {
const licence = await FetchLicenceAbstractionConditionsService.go(licenceId)

const pageData = ViewLicenceAbstractionConditionsPresenter.go(licence)
console.log('🚀🚀🚀 ~ Conditions: ', util.inspect(pageData, false, null, true /* enable colors */))
// console.log('🚀🚀🚀 ~ Conditions: ', util.inspect(pageData, false, null, true /* enable colors */))

return {
activeNavBar: 'search',
Expand Down
150 changes: 108 additions & 42 deletions app/views/licences/conditions.njk
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,113 @@
}) }}

{% for condition in conditions %}
{# Set an easier to use index. #}
{% set rowIndex = loop.index0 %}

{% set tableRows = [] %}

{# Abstraction point cell #}
{% set abstractionPointsRow = {
key: {
text: "Abstraction point",
attributes: { 'data-test': 'abstraction-point-title-' + rowIndex }
},
value: {
html: condition.point,
attributes: { 'data-test': 'abstraction-point-' + rowIndex }
}
} %}

{% set tableRows = (tableRows.push(abstractionPointsRow), tableRows) %}

{# Condition type cell #}
{% set conditionTypeRow = {
key: {
text: "Condition type",
attributes: { 'data-test': 'condition-type-title-' + rowIndex }
},
value: {
html: condition.conditionTypeDescription,
attributes: { 'data-test': 'condition-type-' + rowIndex }
}
} %}

{% set tableRows = (tableRows.push(conditionTypeRow), tableRows) %}

{# Purpose cell #}
{% set purposeRow = {
key: {
text: "Purpose",
attributes: { 'data-test': 'purpose-title-' + rowIndex }
},
value: {
html: condition.purpose,
attributes: { 'data-test': 'purpose-' + rowIndex }
}
} %}

{% set tableRows = (tableRows.push(purposeRow), tableRows) %}

{# Subcode description cell #}
{% set subcodeDescriptionRow = {
key: {
text: "Subcode description",
attributes: { 'data-test': 'subcode-description-title-' + rowIndex }
},
value: {
html: condition.subcodeDescription,
attributes: { 'data-test': 'subcode-description-' + rowIndex }
}
} %}

{% set tableRows = (tableRows.push(subcodeDescriptionRow), tableRows) %}

{# Param1 cell #}
{% if condition.param1 %}
{% set param1Row = {
key: {
text: condition.param1.paramLabel,
attributes: { 'data-test': 'param-1-title-' + rowIndex }
},
value: {
html: condition.param1.param,
attributes: { 'data-test': 'param-1-' + rowIndex }
}
} %}

{% set tableRows = (tableRows.push(param1Row), tableRows) %}
{% endif %}

{# Param2 cell #}
{% if condition.param2 %}
{% set param2Row = {
key: {
text: condition.param2.paramLabel,
attributes: { 'data-test': 'param-2-title-' + rowIndex }
},
value: {
html: condition.param2.param,
attributes: { 'data-test': 'param-2-' + rowIndex }
}
} %}

{% set tableRows = (tableRows.push(param2Row), tableRows) %}
{% endif %}

{# Other information cell #}
{% set otherInformationRow = {
key: {
text: "Other information",
attributes: { 'data-test': 'other-information-title-' + rowIndex }
},
value: {
html: condition.otherInformation,
attributes: { 'data-test': 'other-information-' + rowIndex }
}
} %}

{% set tableRows = (tableRows.push(otherInformationRow), tableRows) %}

{# Summary card #}
{{ govukSummaryList({
card: {
Expand All @@ -26,48 +133,7 @@
classes: "govuk-table__caption--m govuk-!-margin-bottom-0"
}
},
rows: [
{
key: {
text: "Abstraction point"
},
value: {
text: condition.point
}
},
{
key: {
text: "Purpose"
},
value: {
text: condition.purpose
}
},
{
key: {
text: "Notes"
},
value: {
text: condition.notes
}
},
{
key: {
text: "Condition type"
},
value: {
text: condition.conditionTypeDescription
}
},
{
key: {
text: "Subcode description"
},
value: {
text: condition.subcodeDescription
}
}
]
rows: tableRows
}) }}
{% endfor %}
{% endblock %}

0 comments on commit 9f92cfe

Please sign in to comment.