Skip to content

Commit dccd71b

Browse files
authored
Feature/172 fixa export (#520)
* fix: populate diagnostic from precomputed report in generate-report endpoint * refactor: simplify generate-report to use precomputed report directly * fix: update request body from result to report --------- Signed-off-by: Mats Johansson <extern.mats.johansson@digg.se>
1 parent 1a447f7 commit dccd71b

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

openapi.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ paths:
158158
schema:
159159
type: object
160160
required:
161-
- result
161+
- report
162162
properties:
163-
result:
163+
report:
164164
type: array
165165
items:
166-
$ref: '#/components/schemas/RapLPCustomSpectralDiagnosticItem'
167-
description: An array of result items used to generate the Excel report.
166+
$ref: '#/components/schemas/DiagnosticReport'
167+
description: An array of precomputed report items used to generate the Excel report.
168168
responses:
169169
'200':
170170
description: Successful operation
@@ -489,12 +489,12 @@ components:
489489
id:
490490
type: string
491491
example: "UFN.05"
492-
omrade:
492+
område:
493493
type: string
494494
example: "URL Format och namngivning"
495495
required:
496496
- id
497-
- omrade
497+
- område
498498

499499
PopulatedDiagnosticRuleInfo:
500500
allOf:

src/routes/validate.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,15 @@ export const registerValidationRoutes = (app: Express) => {
6161
const data = req.body;
6262
const context = new RuleExecutionContext();
6363

64-
if (!data || !data.result || !Array.isArray(data.result)) {
65-
return res.status(400).json({ error: 'Invalid data format. Expected an object with a "result" array.' });
64+
if (!data || !Array.isArray(data.report)) {
65+
return res.status(400).json({ error: 'Invalid data format. Expected an object with a "report" array.' });
6666
}
6767

6868
const reportHandler = new ExcelReportProcessor();
6969
let buffer: Buffer;
7070

71-
const ruleCategories = data.categories && data.categories.length > 0 ? data.categories : undefined;
72-
73-
const enabledRulesAndCategorys = await importAndCreateRuleInstances(ruleCategories);
7471
const customDiagnostic = new RapLPDiagnostic(context);
75-
customDiagnostic.processRuleExecutionInformation(data.result, enabledRulesAndCategorys.rules,enabledRulesAndCategorys.instanceCategoryMap);
72+
customDiagnostic.setFromPrecomputedReport(data.report);
7673
const diagnosticReports: DiagnosticReport[] = customDiagnostic.processDiagnosticInformation();
7774

7875
try {

src/util/RapLPDiagnostic.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,21 @@ class RapLPDiagnostic {
9999
}
100100
}
101101
}
102+
setFromPrecomputedReport(reports: { Notering: string; regler: { id: string; område: string; krav?: string; helpUrl?: string; status: string }[] }[]): void {
103+
for (const report of reports) {
104+
for (const regel of report.regler) {
105+
const ruleInfo = { id: regel.id, område: regel.område, krav: regel.krav ?? '', helpUrl: regel.helpUrl };
106+
if (regel.status === 'OK') {
107+
this._ruleSets.executedUniqueRules.push(ruleInfo);
108+
} else if (regel.status === 'EJ OK') {
109+
this._ruleSets.executedUniqueRulesWithError.push(ruleInfo);
110+
} else {
111+
this._ruleSets.notApplicableRules.push(ruleInfo);
112+
}
113+
}
114+
}
115+
}
116+
102117
processDiagnosticInformation(): DiagnosticReport[] {
103118
const allReports: DiagnosticReport[] = [];
104119
// Populate the diagnostic reports and add them to the array

0 commit comments

Comments
 (0)