@@ -8,6 +8,7 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
88 cveId : '' ,
99 from : 0 ,
1010 isArecord : undefined ,
11+ isAnId : undefined ,
1112 isSeachButtonDisabled : true ,
1213 isIdOrRecordFound : true ,
1314 isPublished : false ,
@@ -19,6 +20,7 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
1920 isLookUpRecordServerError : false ,
2021 isSearchServerError : false ,
2122 query : '' ,
23+ idData : { } ,
2224 recordData : { } ,
2325 searchResults : [ ] ,
2426 searchType : true ,
@@ -73,42 +75,44 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
7375 this . isSearching = true ;
7476 try {
7577
76- // * 2nd, query search service
78+ // * query search service
7779 this . totalExecutingRequests = 1 ;
7880 await this . getSearchResults ( ) ;
7981
8082 // * Check if keyword is CVE ID
8183 if ( this . isCveIdPattern ( ) ) {
8284 this . totalExecutingRequests = 2 ;
8385
84- // 1st, lookup ID to get Record data, and continue to get CVE Records that mention that ID
86+ // lookup ID to get Record data
8587 this . cveId = this . query . toUpperCase ( ) ;
86- await this . getRecordData ( ) ;
88+ await this . getRecordData ( ) ;
8789 }
8890
8991 } catch ( error ) {
90- throw new Error ( 'search() >> error with getRecordData() and or getSearchResults()' ) ;
92+ // if record is not found, find potential reserved/rejected ID
93+ if ( this . isCveIdPattern ( ) && Object . keys ( this . recordData ) . length === 0 ) {
94+ await this . getIdData ( ) ;
95+ }
96+
97+ throw new Error ( 'search() >> error with getSearchResults(), getRecordData(), or getIdData()' ) ;
9198 } finally {
9299 this . isSearching = false ;
93100 this . setUpInitialPagination ( ) ;
94101 }
95102 } ,
96103 async getRecordData ( ) {
97104 this . isLookingUpRecord = true ;
98- const getRecordUrl = `/api/cve/${ this . cveId } ` ;
105+ const getRecordUrl = `${ useGenericGlobalsStore ( ) . currentServicesUrl } /api/cve/${ this . cveId } ` ;
99106
100107 try {
101- axios . defaults . baseURL = useGenericGlobalsStore ( ) . currentServicesUrl ;
102108 const response = await axios . get ( getRecordUrl ) ;
103109 const cveRecordData = response ?. data || { } ;
104110 this . isArecord = true ;
105- this . isIdOrRecordFound = false ;
111+ this . isIdOrRecordFound = true ;
106112
107113 // format description
108- let descriptions = [ ] ;
109- cveRecordData . containers ?. cna ?. descriptions . forEach ( ( description ) => {
110- if ( this . isEnglishLanguage ( description . lang ) ) descriptions . push ( this . processShowMoreShowLessDescription ( description . value ) ) ;
111- } ) ;
114+ let descriptions = this . processDescriptionsField ( cveRecordData ) ;
115+
112116 let recordDataSummary = {
113117 cveId : cveRecordData ?. cveMetadata ?. cveId || 'No ID provided' ,
114118 cna : cveRecordData ?. containers ?. cna ?. providerMetadata ?. shortName || 'No CNA provided' ,
@@ -124,20 +128,42 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
124128 this . isRejected = true ;
125129 }
126130
127- } catch ( e ) {
131+ } catch ( error ) {
128132 this . isLookUpRecordServerError = true ;
129133
130134 this . isPublished = false ;
131135 this . isReserved = false ;
132136 this . isRejected = false ;
133137 this . isIdOrRecordFound = false ;
134138 this . isArecord = false ;
135- throw new Error ( 'getRecordData >> throwing wrroe' )
139+ throw new Error ( 'getRecordData >> throwing error' ) ;
136140 } finally {
137141 this . isLookingUpRecord = false ;
138142 this . decrement ( 'totalExecutingRequests' ) ;
139143 }
140144 } ,
145+ async getIdData ( ) {
146+ const getIdUrl = `${ useGenericGlobalsStore ( ) . currentServicesUrl } /api/cve-id/${ this . cveId } ` ;
147+ try {
148+ const response = await axios . get ( getIdUrl ) ;
149+ const idData = response || { } ;
150+ this . isIdOrRecordFound = true ;
151+ this . isAnId = true ;
152+ if ( idData . status === 200 && idData ?. data ?. error === undefined ) {
153+ this . idData = idData . data ;
154+ if ( idData . state === 'RESERVED' ) {
155+ this . isReserved = true ;
156+ this . isArecord = false ;
157+ } else if ( this . $store . state . idData . state === 'REJECTED' ) {
158+ this . isRejected = true ;
159+ this . isArecord = false ;
160+ }
161+ }
162+
163+ } catch ( error ) {
164+ throw new Error ( 'getIdData >> throwing error' ) ;
165+ }
166+ } ,
141167 async getSearchResults ( ) {
142168 this . isQueryingSearchService = true ;
143169 const searchUrl = `${ import . meta. env . VITE_API_BASE_URL } ${ import . meta. env . VITE_LIST_SEARCH_PATH } ` ;
@@ -168,7 +194,7 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
168194 cveId : result . _id ,
169195 cna : result ?. _source ?. containers ?. cna ?. providerMetadata ?. shortName || 'No CNA provided' ,
170196 cnaOrgId : result ?. _source ?. containers ?. cna ?. providerMetadata ?. orgId || '' ,
171- descriptions : this . processDescriptionsField ( result ) ,
197+ descriptions : this . processDescriptionsField ( result ?. _source ) ,
172198 relevancyScore : result ?. _score
173199 } ) ;
174200 } ) ;
@@ -177,17 +203,17 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
177203
178204 this . searchResults = parsedResults ;
179205 } ,
180- processDescriptionsField ( result ) {
206+ processDescriptionsField ( recordData ) {
181207 let descriptions = [ ] ;
182- if ( result ?. _source ? .cveMetadata ?. state === "PUBLISHED" ) {
183- result ?. _source ? .containers ?. cna ?. descriptions . forEach ( ( description ) => {
208+ if ( recordData . cveMetadata ?. state === "PUBLISHED" ) {
209+ recordData . containers ?. cna ?. descriptions . forEach ( ( description ) => {
184210 if ( this . isEnglishLanguage ( description . lang ) ) descriptions . push ( this . processShowMoreShowLessDescription ( description . value ) ) ;
185211 } ) ;
186- } else if ( result ?. _source ? .cveMetadata ?. state === "REJECTED" ) {
187- result ?. _source ? .containers ?. cna ?. rejectedReasons . forEach ( ( rejectedReason ) => {
212+ } else if ( recordData . cveMetadata ?. state === "REJECTED" ) {
213+ recordData . containers ?. cna ?. rejectedReasons . forEach ( ( rejectedReason ) => {
188214 if ( this . isEnglishLanguage ( rejectedReason . lang ) ) descriptions . push ( this . processShowMoreShowLessDescription ( rejectedReason . value ) ) ;
189215 } ) ;
190- } else {
216+ } else { // resevered/rejected ID w/o a CVE record does not have description, and that logic is handled in corresponding Vue file
191217 descriptions . push ( 'No description provided' ) ;
192218 }
193219
0 commit comments