From d5670c248a68ab8c553d700d140e4a611bf873ee Mon Sep 17 00:00:00 2001 From: Quentin Bellanger Date: Wed, 6 Nov 2024 11:30:27 +0100 Subject: [PATCH 1/3] sort returned audits on account dashboard by desc creation date --- .../src/audits/audit.service.ts | 132 +++++++++--------- 1 file changed, 68 insertions(+), 64 deletions(-) diff --git a/confiture-rest-api/src/audits/audit.service.ts b/confiture-rest-api/src/audits/audit.service.ts index 5898ceae0..5550aae3d 100644 --- a/confiture-rest-api/src/audits/audit.service.ts +++ b/confiture-rest-api/src/audits/audit.service.ts @@ -9,7 +9,7 @@ import { } from "@prisma/client"; import { nanoid } from "nanoid"; import sharp from "sharp"; -import { omit, pick, setWith, sortBy, uniqBy } from "lodash"; +import { omit, orderBy, pick, sortBy, setWith, uniqBy } from "lodash"; import { PrismaService } from "../prisma.service"; import * as RGAA from "../rgaa.json"; @@ -1366,76 +1366,80 @@ export class AuditService { } }); - return audits.map((a) => { - const results = [ - ...a.transverseElementsPage.results, - ...a.pages.flatMap((p) => p.results) - ]; - - const progress = - results.filter((r) => r.status !== CriterionResultStatus.NOT_TESTED) - .length / - (CRITERIA_BY_AUDIT_TYPE[a.auditType].length * a.pages.length); - - let complianceLevel = null; - - if (progress >= 1) { - const resultsGroupedById = results.reduce< - Record - >((acc, c) => { - const key = `${c.topic}.${c.criterium}`; - if (acc[key]) { - acc[key].push(c); - } else { - acc[key] = [c]; - } - return acc; - }, {}); - - const results2 = CRITERIA_BY_AUDIT_TYPE[a.auditType].map( - (c) => resultsGroupedById[`${c.topic}.${c.criterium}`] ?? null - ); + return orderBy( + audits.map((a) => { + const results = [ + ...a.transverseElementsPage.results, + ...a.pages.flatMap((p) => p.results) + ]; - const applicableCriteria = results2.filter((criteria) => - criteria.some((c) => isCompliant(c) || isNotCompliant(c)) - ); + const progress = + results.filter((r) => r.status !== CriterionResultStatus.NOT_TESTED) + .length / + (CRITERIA_BY_AUDIT_TYPE[a.auditType].length * a.pages.length); + + let complianceLevel = null; + + if (progress >= 1) { + const resultsGroupedById = results.reduce< + Record + >((acc, c) => { + const key = `${c.topic}.${c.criterium}`; + if (acc[key]) { + acc[key].push(c); + } else { + acc[key] = [c]; + } + return acc; + }, {}); - const compliantCriteria = applicableCriteria.filter((criteria) => { - // remove untested transverse criterion - const withoutUntestedTrans = criteria.filter( - (c) => - !(isTransverse(c, a.transverseElementsPageId) && isNotTested(c)) + const results2 = CRITERIA_BY_AUDIT_TYPE[a.auditType].map( + (c) => resultsGroupedById[`${c.topic}.${c.criterium}`] ?? null ); - return ( - withoutUntestedTrans.some((c) => isCompliant(c)) && - withoutUntestedTrans.every( - (c) => isCompliant(c) || isNotApplicable(c) - ) + const applicableCriteria = results2.filter((criteria) => + criteria.some((c) => isCompliant(c) || isNotCompliant(c)) ); - }); - complianceLevel = Math.round( - (compliantCriteria.length / applicableCriteria.length) * 100 - ); - } + const compliantCriteria = applicableCriteria.filter((criteria) => { + // remove untested transverse criterion + const withoutUntestedTrans = criteria.filter( + (c) => + !(isTransverse(c, a.transverseElementsPageId) && isNotTested(c)) + ); - const statementIsPublished = !!a.initiator; + return ( + withoutUntestedTrans.some((c) => isCompliant(c)) && + withoutUntestedTrans.every( + (c) => isCompliant(c) || isNotApplicable(c) + ) + ); + }); - return { - ...pick( - a, - "procedureName", - "editUniqueId", - "consultUniqueId", - "creationDate", - "auditType" - ), - complianceLevel, - status: progress < 1 ? "IN_PROGRESS" : "COMPLETED", - estimatedCsvSize: 502 + a.pages.length * 318, - statementIsPublished - }; - }); + complianceLevel = Math.round( + (compliantCriteria.length / applicableCriteria.length) * 100 + ); + } + + const statementIsPublished = !!a.initiator; + + return { + ...pick( + a, + "procedureName", + "editUniqueId", + "consultUniqueId", + "creationDate", + "auditType" + ), + complianceLevel, + status: progress < 1 ? "IN_PROGRESS" : "COMPLETED", + estimatedCsvSize: 502 + a.pages.length * 318, + statementIsPublished + }; + }), + (a) => a.creationDate, + ["desc"] + ); } } From 5fdc0eee3093ce6e4bae13a64550645556cc1370 Mon Sep 17 00:00:00 2001 From: Quentin Bellanger Date: Wed, 6 Nov 2024 11:31:54 +0100 Subject: [PATCH 2/3] create a variable to store unordered audits --- .../src/audits/audit.service.ts | 130 +++++++++--------- 1 file changed, 64 insertions(+), 66 deletions(-) diff --git a/confiture-rest-api/src/audits/audit.service.ts b/confiture-rest-api/src/audits/audit.service.ts index 5550aae3d..d0ca16aac 100644 --- a/confiture-rest-api/src/audits/audit.service.ts +++ b/confiture-rest-api/src/audits/audit.service.ts @@ -1366,80 +1366,78 @@ export class AuditService { } }); - return orderBy( - audits.map((a) => { - const results = [ - ...a.transverseElementsPage.results, - ...a.pages.flatMap((p) => p.results) - ]; + const unorderedAudits = audits.map((a) => { + const results = [ + ...a.transverseElementsPage.results, + ...a.pages.flatMap((p) => p.results) + ]; + + const progress = + results.filter((r) => r.status !== CriterionResultStatus.NOT_TESTED) + .length / + (CRITERIA_BY_AUDIT_TYPE[a.auditType].length * a.pages.length); + + let complianceLevel = null; + + if (progress >= 1) { + const resultsGroupedById = results.reduce< + Record + >((acc, c) => { + const key = `${c.topic}.${c.criterium}`; + if (acc[key]) { + acc[key].push(c); + } else { + acc[key] = [c]; + } + return acc; + }, {}); - const progress = - results.filter((r) => r.status !== CriterionResultStatus.NOT_TESTED) - .length / - (CRITERIA_BY_AUDIT_TYPE[a.auditType].length * a.pages.length); - - let complianceLevel = null; - - if (progress >= 1) { - const resultsGroupedById = results.reduce< - Record - >((acc, c) => { - const key = `${c.topic}.${c.criterium}`; - if (acc[key]) { - acc[key].push(c); - } else { - acc[key] = [c]; - } - return acc; - }, {}); + const results2 = CRITERIA_BY_AUDIT_TYPE[a.auditType].map( + (c) => resultsGroupedById[`${c.topic}.${c.criterium}`] ?? null + ); - const results2 = CRITERIA_BY_AUDIT_TYPE[a.auditType].map( - (c) => resultsGroupedById[`${c.topic}.${c.criterium}`] ?? null - ); + const applicableCriteria = results2.filter((criteria) => + criteria.some((c) => isCompliant(c) || isNotCompliant(c)) + ); - const applicableCriteria = results2.filter((criteria) => - criteria.some((c) => isCompliant(c) || isNotCompliant(c)) + const compliantCriteria = applicableCriteria.filter((criteria) => { + // remove untested transverse criterion + const withoutUntestedTrans = criteria.filter( + (c) => + !(isTransverse(c, a.transverseElementsPageId) && isNotTested(c)) ); - const compliantCriteria = applicableCriteria.filter((criteria) => { - // remove untested transverse criterion - const withoutUntestedTrans = criteria.filter( - (c) => - !(isTransverse(c, a.transverseElementsPageId) && isNotTested(c)) - ); + return ( + withoutUntestedTrans.some((c) => isCompliant(c)) && + withoutUntestedTrans.every( + (c) => isCompliant(c) || isNotApplicable(c) + ) + ); + }); - return ( - withoutUntestedTrans.some((c) => isCompliant(c)) && - withoutUntestedTrans.every( - (c) => isCompliant(c) || isNotApplicable(c) - ) - ); - }); + complianceLevel = Math.round( + (compliantCriteria.length / applicableCriteria.length) * 100 + ); + } - complianceLevel = Math.round( - (compliantCriteria.length / applicableCriteria.length) * 100 - ); - } + const statementIsPublished = !!a.initiator; - const statementIsPublished = !!a.initiator; + return { + ...pick( + a, + "procedureName", + "editUniqueId", + "consultUniqueId", + "creationDate", + "auditType" + ), + complianceLevel, + status: progress < 1 ? "IN_PROGRESS" : "COMPLETED", + estimatedCsvSize: 502 + a.pages.length * 318, + statementIsPublished + }; + }); - return { - ...pick( - a, - "procedureName", - "editUniqueId", - "consultUniqueId", - "creationDate", - "auditType" - ), - complianceLevel, - status: progress < 1 ? "IN_PROGRESS" : "COMPLETED", - estimatedCsvSize: 502 + a.pages.length * 318, - statementIsPublished - }; - }), - (a) => a.creationDate, - ["desc"] - ); + return orderBy(unorderedAudits, (a) => a.creationDate, ["desc"]); } } From 1d849b29c0a82358229a8d2202349dd31d0dea23 Mon Sep 17 00:00:00 2001 From: Quentin Bellanger Date: Wed, 6 Nov 2024 11:39:23 +0100 Subject: [PATCH 3/3] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c44f2a043..1dfb4dd6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Tous les changements notables de Ara sont documentĂ©s ici avec leur date, leur c ### Corrections 🐛 - Ordonne correctement les pages dans la dĂ©claration d’accessibilitĂ© et le contexte de l’audit ([#819](https://github.com/DISIC/Ara/pull/819)) +- Ordonne les audits du tableau de bord par date de crĂ©ation descendante (du plus rĂ©cent au plus ancien) ([#821](https://github.com/DISIC/Ara/pull/821)) ## 31/10/2024