Skip to content

Commit

Permalink
update controllers to use severity field
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeGoodall committed Nov 29, 2023
1 parent 1dea512 commit c381086
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
44 changes: 24 additions & 20 deletions src/controllers/errorsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import MyController from './MyController.js'

import { severityLevels } from '../utils/utils.js'

class ErrorsController extends MyController {
get (req, res, next) {
const validationResult = req.sessionModel.get('validationResult')

const { aggregatedIssues, issueCounts } = this.aggregateIssues(validationResult)
const { aggregatedIssues, issueCounts } = this.getAggregatedErrors(validationResult)

const rows = Object.values(aggregatedIssues)

Expand All @@ -19,31 +21,33 @@ class ErrorsController extends MyController {
super.get(req, res, next)
}

aggregateIssues (apiResponseData) {
getAggregatedErrors (apiResponseData) {
const aggregatedIssues = {}
const issueCounts = {}

apiResponseData['issue-log'].forEach(issue => {
const entryNumber = issue['entry-number']

const rowValues = apiResponseData['converted-csv'][issue['line-number'] - 2]
if (!(entryNumber in aggregatedIssues)) {
aggregatedIssues[entryNumber] = Object.keys(rowValues).reduce((acc, originalColumnName) => {
const mappedColumnName = this.lookupMappedColumnNameFromOriginal(originalColumnName, apiResponseData['column-field-log'])
acc[mappedColumnName] = {
error: false,
value: rowValues[originalColumnName]
}
return acc
}, {})
}
if (issue.severity === severityLevels.error) {
const entryNumber = issue['entry-number']

if (entryNumber in aggregatedIssues) {
aggregatedIssues[entryNumber][issue.field] = {
error: this.lookupIssueType(issue['issue-type']),
value: rowValues[this.lookupOriginalColumnNameFromMapped(issue.field, apiResponseData['column-field-log'])]
const rowValues = apiResponseData['converted-csv'][issue['line-number'] - 2]
if (!(entryNumber in aggregatedIssues)) {
aggregatedIssues[entryNumber] = Object.keys(rowValues).reduce((acc, originalColumnName) => {
const mappedColumnName = this.lookupMappedColumnNameFromOriginal(originalColumnName, apiResponseData['column-field-log'])
acc[mappedColumnName] = {
error: false,
value: rowValues[originalColumnName]
}
return acc
}, {})
}

if (entryNumber in aggregatedIssues) {
aggregatedIssues[entryNumber][issue.field] = {
error: this.lookupIssueType(issue['issue-type']),
value: rowValues[this.lookupOriginalColumnNameFromMapped(issue.field, apiResponseData['column-field-log'])]
}
issueCounts[issue.field] = issueCounts[issue.field] ? issueCounts[issue.field] + 1 : 1
}
issueCounts[issue.field] = issueCounts[issue.field] ? issueCounts[issue.field] + 1 : 1
}
})

Expand Down
4 changes: 3 additions & 1 deletion src/controllers/uploadController.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { lookup } from 'mime-types'
import MyController from './MyController.js'
import config from '../../config/index.js'

import { severityLevels } from '../utils/utils.js'

const upload = multer({ dest: 'uploads/' })

const apiRoute = config.api.url + config.api.validationEndpoint
Expand All @@ -26,7 +28,7 @@ class UploadController extends MyController {
dataSubject: req.sessionModel.get('data-subject'),
organisation: 'local-authority-eng:CAT' // ToDo: this needs to be dynamic, not collected in the prototype, should it be?
})
this.errorCount = jsonResult['issue-log'].length
this.errorCount = jsonResult['issue-log'].filter(issue => issue.severity === severityLevels.error).length
req.body.datafile = req.file
req.body.validationResult = jsonResult
} catch (error) {
Expand Down
6 changes: 6 additions & 0 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const severityLevels = {
notice: 'notice',
informational: 'info',
warning: 'warning',
error: 'error'
}

0 comments on commit c381086

Please sign in to comment.