Skip to content

Commit

Permalink
calculate entities with issues instead of entries with issues
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeGoodall committed Oct 11, 2024
1 parent 1efefb4 commit faf449d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
16 changes: 13 additions & 3 deletions src/middleware/common.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export async function reformatIssuesToBeByEntryNumber (req, res, next) {

export function formatErrorSummaryParams (req, res, next) {
const { lpa, dataset: datasetId, issue_type: issueType, issue_field: issueField } = req.params
const { issuesByEntryNumber, entityCount: entityCountRow, issueEntitiesCount } = req
const { issuesByEntryNumber, entityCount: entityCountRow, issues } = req

const { entity_count: entityCount } = entityCountRow ?? { entity_count: 0 }

Expand All @@ -180,7 +180,7 @@ export function formatErrorSummaryParams (req, res, next) {
let issueItems

if (Object.keys(issuesByEntryNumber).length < entityCount) {
errorHeading = performanceDbApi.getTaskMessage({ issue_type: issueType, num_issues: issueEntitiesCount, entityCount, field: issueField }, true)
errorHeading = performanceDbApi.getTaskMessage({ issue_type: issueType, num_issues: issues.length, entityCount, field: issueField }, true)
issueItems = Object.keys(issuesByEntryNumber).map((entryNumber, i) => {
return {
html: performanceDbApi.getTaskMessage({ issue_type: issueType, num_issues: 1, field: issueField }) + ` in record ${entryNumber}`,
Expand All @@ -189,7 +189,7 @@ export function formatErrorSummaryParams (req, res, next) {
})
} else {
issueItems = [{
html: performanceDbApi.getTaskMessage({ issue_type: issueType, num_issues: issueEntitiesCount, entityCount, field: issueField }, true)
html: performanceDbApi.getTaskMessage({ issue_type: issueType, num_issues: issues.length, entityCount, field: issueField }, true)
}]
}

Expand All @@ -216,6 +216,16 @@ export const fetchEntitiesFromOrganisationAndEntryNumbers = fetchMany({
dataset: FetchOptions.fromParams
})

export const paginateEntitiesAndPullOutCount = (req, res, next) => {
const { entities, pagination } = req

req.entitiesWithIssuesCount = entities.length

req.entities = entities.slice(pagination.offset, pagination.offset + pagination.limit)

next()
}

export const getPaginationOptions = (resultsCount) => (req, res, next) => {
const { pageNumber } = req.params

Expand Down
8 changes: 4 additions & 4 deletions src/middleware/issueTable.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
fetchDatasetInfo,
fetchEntitiesFromOrganisationAndEntryNumbers,
fetchEntityCount,
fetchIssueEntitiesCount,
fetchIssues,
fetchLatestResource,
fetchOrgInfo,
Expand All @@ -16,6 +15,7 @@ import {
isResourceIdNotInParams,
logPageError,
nestEntityFields,
paginateEntitiesAndPullOutCount,
pullOutDatasetSpecification,
reformatIssuesToBeByEntryNumber,
replaceUnderscoreWithHyphenForEntities,
Expand Down Expand Up @@ -111,10 +111,10 @@ export const prepareIssueTableTemplateParams = (req, res, next) => {
* @returns {void}
*/
export const createPaginationTemplatePrams = (req, res, next) => {
const { issueEntitiesCount } = req
const { entitiesWithIssuesCount } = req
const { pageNumber, lpa, dataset: datasetId, issue_type: issueType, issue_field: issueField } = req.params

const totalPages = Math.ceil(issueEntitiesCount / paginationPageLength)
const totalPages = Math.floor(entitiesWithIssuesCount / paginationPageLength)

const BaseSubpath = `/organisations/${lpa}/${datasetId}/${issueType}/${issueField}/`

Expand Down Expand Up @@ -173,11 +173,11 @@ export default [
fetchIssues,
getEntryNumbersWithIssues,
fetchEntitiesFromOrganisationAndEntryNumbers,
paginateEntitiesAndPullOutCount,
extractJsonFieldFromEntities,
replaceUnderscoreWithHyphenForEntities,
nestEntityFields,
addIssuesToEntities,
fetchIssueEntitiesCount,
fetchEntityCount,
reformatIssuesToBeByEntryNumber,
formatErrorSummaryParams,
Expand Down
6 changes: 4 additions & 2 deletions src/services/performanceDbApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,10 @@ export default {
LEFT JOIN entity e ON f.entity = e.entity
WHERE e.organisation_entity = ${organisationEntity}
AND entry_number in (${entryNumbers.join(', ')})
LIMIT ${pagination.limit}
OFFSET ${pagination.offset}
`
// Can't have pagination here as we need to know the count of all the entities with issues anyway, something for the performance db?
// LIMIT ${pagination.limit}
// OFFSET ${pagination.offset}
// `
}
}

0 comments on commit faf449d

Please sign in to comment.