@@ -14,7 +14,7 @@ export class ImportRuleService {
1414 }
1515
1616 private minWordsCheck ( value : string , min : number , minLengthPerWord : number ) : boolean {
17- if ( ! value ) return false ;
17+ if ( ! value ) { return false ; }
1818 const words = value . trim ( ) . split ( / \s + / ) . filter ( word => word . length >= minLengthPerWord ) ;
1919 return words . length >= min ;
2020
@@ -29,150 +29,151 @@ export class ImportRuleService {
2929
3030 // dataTypes
3131 if ( ! Array . isArray ( obj . dataTypes ) || obj . dataTypes . length === 0 ) {
32- if ( ! obj . dataTypes ) {
33- obj . dataTypes = null
32+ if ( ! obj . dataTypes ) {
33+ obj . dataTypes = null ;
3434 }
35- errors [ ' dataTypes' ] = [ 'dataTypes are required' ] ;
35+ errors . dataTypes = [ 'dataTypes are required' ] ;
3636 }
3737
3838 // name
3939 if ( typeof obj . name !== 'string' || obj . name . trim ( ) === '' ) {
4040
41- if ( ! obj . name ) {
42- obj . name = null
41+ if ( ! obj . name ) {
42+ obj . name = null ;
4343 }
44- errors [ ' name' ] = [ 'Name is required' ] ;
44+ errors . name = [ 'Name is required' ] ;
4545 } else if ( ! this . minWordsCheck ( obj . name , 2 , 3 ) ) {
46- errors [ ' name' ] = [ 'Name must contain between 2 and 3 words' ] ;
46+ errors . name = [ 'Name must contain between 2 and 3 words' ] ;
4747 }
4848
4949 // adversary
5050 if ( typeof obj . adversary !== 'string' || obj . adversary . trim ( ) === '' ) {
51- if ( ! obj . adversary ) {
52- obj . adversary = null
51+ if ( ! obj . adversary ) {
52+ obj . adversary = null ;
5353 }
54- errors [ ' adversary' ] = [ 'Adversary is required' ] ;
55- } else if ( ! [ 'origin' , 'target' ] . includes ( obj . adversary ) ) {
56- errors [ ' adversary' ] = [ 'Adversary must be one of these: "origin", "target"' ] ;
54+ errors . adversary = [ 'Adversary is required' ] ;
55+ } else if ( ! [ 'origin' , 'target' ] . includes ( obj . adversary ) ) {
56+ errors . adversary = [ 'Adversary must be one of these: "origin", "target"' ] ;
5757 }
5858
5959 // confidentiality
6060 if ( typeof obj . confidentiality !== 'number' ) {
61- if ( ! obj . confidentiality ) {
62- obj . confidentiality = null
63- errors [ ' confidentiality' ] = [ 'Confidentiality is required' ] ;
64- } else {
65- errors [ ' confidentiality' ] = [ 'Confidentiality must be a number' ] ;
61+ if ( ! obj . confidentiality ) {
62+ obj . confidentiality = null ;
63+ errors . confidentiality = [ 'Confidentiality is required' ] ;
64+ } else {
65+ errors . confidentiality = [ 'Confidentiality must be a number' ] ;
6666 }
6767 } else if ( obj . confidentiality < 0 || obj . confidentiality > 3 ) {
68- errors [ ' confidentiality' ] = [ 'Confidentiality must be between 0 and 3' ] ;
68+ errors . confidentiality = [ 'Confidentiality must be between 0 and 3' ] ;
6969 }
7070
7171 // integrity
7272 if ( typeof obj . integrity !== 'number' ) {
73- if ( ! obj . integrity ) {
74- obj . integrity = null
75- errors [ ' integrity' ] = [ 'Integrity is required' ] ;
76- } else {
77- errors [ ' integrity' ] = [ 'Integrity must be a number' ] ;
73+ if ( ! obj . integrity ) {
74+ obj . integrity = null ;
75+ errors . integrity = [ 'Integrity is required' ] ;
76+ } else {
77+ errors . integrity = [ 'Integrity must be a number' ] ;
7878 }
7979 } else if ( obj . integrity < 0 || obj . integrity > 3 ) {
80- errors [ ' integrity' ] = [ 'Integrity must be between 0 and 3' ] ;
80+ errors . integrity = [ 'Integrity must be between 0 and 3' ] ;
8181 }
8282
8383 // availability
8484 if ( typeof obj . availability !== 'number' ) {
8585
86- if ( ! obj . availability ) {
87- obj . availability = null
88- errors [ ' availability' ] = [ 'Availability is required' ] ;
89- } else {
90- errors [ ' availability' ] = [ 'Availability must be a number' ] ;
86+ if ( ! obj . availability ) {
87+ obj . availability = null ;
88+ errors . availability = [ 'Availability is required' ] ;
89+ } else {
90+ errors . availability = [ 'Availability must be a number' ] ;
9191 }
9292 } else if ( obj . availability < 0 || obj . availability > 3 ) {
93- errors [ ' availability' ] = [ 'Availability must be between 0 and 3' ] ;
93+ errors . availability = [ 'Availability must be between 0 and 3' ] ;
9494 }
9595
9696 // category
9797 if ( typeof obj . category !== 'string' || obj . category . trim ( ) === '' ) {
9898
99- if ( ! obj . category ) {
100- obj . category = null
99+ if ( ! obj . category ) {
100+ obj . category = null ;
101101 }
102- errors [ ' category' ] = [ 'Category is required' ] ;
102+ errors . category = [ 'Category is required' ] ;
103103 } else if ( ! this . minWordsCheck ( obj . category , 1 , 3 ) ) {
104- errors [ ' category' ] = [ 'Category must contain between 1 and 3 words' ] ;
104+ errors . category = [ 'Category must contain between 1 and 3 words' ] ;
105105 }
106106
107107 // technique
108108 if ( typeof obj . technique !== 'string' || obj . technique . trim ( ) === '' ) {
109109
110- if ( ! obj . technique ) {
111- obj . technique = null
110+ if ( ! obj . technique ) {
111+ obj . technique = null ;
112112 }
113- errors [ ' technique' ] = [ 'Technique is required' ] ;
113+ errors . technique = [ 'Technique is required' ] ;
114114 } else if ( ! this . minWordsCheck ( obj . technique , 1 , 3 ) ) {
115- errors [ ' technique' ] = [ 'Technique must contain between 1 and 3 words' ] ;
115+ errors . technique = [ 'Technique must contain between 1 and 3 words' ] ;
116116 }
117117
118118 // description
119119 if ( typeof obj . description !== 'string' || obj . description . trim ( ) === '' ) {
120- if ( ! obj . description ) {
121- obj = { description :null , ...obj }
120+ if ( ! obj . description ) {
121+ obj = { description : null , ...obj } ;
122122 }
123- errors [ ' description' ] = [ 'Description is required' ] ;
123+ errors . description = [ 'Description is required' ] ;
124124 } else if ( ! this . minWordsCheck ( obj . description , 2 , 3 ) ) {
125- errors [ ' description' ] = [ 'Description must contain between 2 and 3 words' ] ;
125+ errors . description = [ 'Description must contain between 2 and 3 words' ] ;
126126 }
127127
128128 // definition
129129 if ( typeof obj . definition !== 'string' || obj . definition . trim ( ) === '' ) {
130- if ( ! obj . definition ) {
131- obj . definition = null
130+ if ( ! obj . definition ) {
131+ obj . definition = null ;
132132 }
133- errors [ ' definition' ] = [ 'Definition is required' ] ;
133+ errors . definition = [ 'Definition is required' ] ;
134134 } else if ( ! this . minWordsCheck ( obj . definition , 2 , 3 ) ) {
135- errors [ ' definition' ] = [ 'Definition must contain between 2 and 3 words' ] ;
135+ errors . definition = [ 'Definition must contain between 2 and 3 words' ] ;
136136 }
137137
138138 // references
139139 if ( ! Array . isArray ( obj . references ) ) {
140- if ( ! obj . references ) {
141- obj . references = null
142- errors [ ' references' ] = [ 'References is required' ] ;
143- } else {
144- errors [ ' references' ] = [ 'References must be an array' ] ;
140+ if ( ! obj . references ) {
141+ obj . references = null ;
142+ errors . references = [ 'References is required' ] ;
143+ } else {
144+ errors . references = [ 'References must be an array' ] ;
145145 }
146146 } else {
147147 const invalidRefs = obj . references . filter ( ( ref : any ) => typeof ref !== 'string' || ! this . isValidURL ( ref ) ) ;
148148 if ( invalidRefs . length > 0 ) {
149- errors [ ' references' ] = [ 'All references must be valid URLs' ] ;
149+ errors . references = [ 'All references must be valid URLs' ] ;
150150 }
151151 }
152152
153153
154154 const allowedFields = [
155- "id" ,
156- " dataTypes" ,
157- " impact" ,
158- " where" ,
159- " afterEvents" ,
160- " name" ,
161- " adversary" ,
162- " confidentiality" ,
163- " integrity" ,
164- " availability" ,
155+ 'id' ,
156+ ' dataTypes' ,
157+ ' impact' ,
158+ ' where' ,
159+ ' afterEvents' ,
160+ ' name' ,
161+ ' adversary' ,
162+ ' confidentiality' ,
163+ ' integrity' ,
164+ ' availability' ,
165165 'references' ,
166- "category" ,
167- "technique" ,
168- "description" ,
169- "definition" ,
170- "systemOwner" ,
171- "deduplicateBy"
166+ 'category' ,
167+ 'technique' ,
168+ 'description' ,
169+ 'definition' ,
170+ 'systemOwner' ,
171+ 'deduplicateBy' ,
172+ 'groupBy'
172173 ] ;
173174
174- Object . keys ( obj ) . filter ( key => ! allowedFields . includes ( key ) ) . forEach ( key => {
175- errors [ key ] = [ `uknowed field: ${ key } ` ]
175+ Object . keys ( obj ) . filter ( key => ! allowedFields . includes ( key ) ) . forEach ( key => {
176+ errors [ key ] = [ `uknowed field: ${ key } ` ] ;
176177 } ) ;
177178
178179
0 commit comments