|
| 1 | +import {CxRealtimeEngineStatus} from "../oss/CxRealtimeEngineStatus"; |
| 2 | + |
| 3 | +export default class CxIacResult { |
| 4 | + title: string; |
| 5 | + description: string; |
| 6 | + similarityID: string; |
| 7 | + filepath: string; |
| 8 | + severity: CxRealtimeEngineStatus; |
| 9 | + locations: { line: number, startIndex: number, endIndex: number }[]; |
| 10 | + |
| 11 | + static parseResult(resultObject: any): CxIacResult[] { |
| 12 | + let iacResults: CxIacResult[] = []; |
| 13 | + if (resultObject instanceof Array) { |
| 14 | + iacResults = resultObject.map((member: any) => { |
| 15 | + const iacResult = new CxIacResult(); |
| 16 | + iacResult.title = member.Title; |
| 17 | + iacResult.description = member.Description; |
| 18 | + iacResult.similarityID = member.SimilarityID; |
| 19 | + iacResult.filepath = member.FilePath; |
| 20 | + iacResult.severity = member.Severity as CxRealtimeEngineStatus; |
| 21 | + iacResult.locations = Array.isArray(member.Locations) |
| 22 | + ? member.Locations.map((l: any) => ({ |
| 23 | + line: l.Line, |
| 24 | + startIndex: l.StartIndex, |
| 25 | + endIndex: l.EndIndex, |
| 26 | + })) |
| 27 | + : []; |
| 28 | + return iacResult; |
| 29 | + }); |
| 30 | + } else { |
| 31 | + const iacResult = new CxIacResult(); |
| 32 | + iacResult.title = resultObject.Title; |
| 33 | + iacResult.description = resultObject.Description; |
| 34 | + iacResult.severity = resultObject.Severity; |
| 35 | + iacResult.filepath = resultObject.FilePath; |
| 36 | + iacResult.filepath = resultObject.FilePath; |
| 37 | + iacResult.locations = Array.isArray(resultObject.Locations) |
| 38 | + ? resultObject.Locations.map((l: any) => ({ |
| 39 | + line: l.Line, |
| 40 | + startIndex: l.StartIndex, |
| 41 | + endIndex: l.EndIndex, |
| 42 | + })) |
| 43 | + : []; |
| 44 | + iacResults.push(iacResult); |
| 45 | + } |
| 46 | + return iacResults; |
| 47 | + } |
| 48 | +} |
0 commit comments