@@ -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,36 +75,40 @@ 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 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
108114 let descriptions = [ ] ;
@@ -124,20 +130,42 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
124130 this . isRejected = true ;
125131 }
126132
127- } catch ( e ) {
133+ } catch ( error ) {
128134 this . isLookUpRecordServerError = true ;
129135
130136 this . isPublished = false ;
131137 this . isReserved = false ;
132138 this . isRejected = false ;
133139 this . isIdOrRecordFound = false ;
134140 this . isArecord = false ;
135- throw new Error ( 'getRecordData >> throwing wrroe' )
141+ throw new Error ( 'getRecordData >> throwing error' ) ;
136142 } finally {
137143 this . isLookingUpRecord = false ;
138144 this . decrement ( 'totalExecutingRequests' ) ;
139145 }
140146 } ,
147+ async getIdData ( ) {
148+ const getIdUrl = `${ useGenericGlobalsStore ( ) . currentServicesUrl } /api/cve-id/${ this . cveId } ` ;
149+ try {
150+ const response = await axios . get ( getIdUrl ) ;
151+ const idData = response || { } ;
152+ this . isIdOrRecordFound = true ;
153+ this . isAnId = true ;
154+ if ( idData . status === 200 && idData ?. data ?. error === undefined ) {
155+ this . idData = idData . data ;
156+ if ( idData . state === 'RESERVED' ) {
157+ this . isReserved = true ;
158+ this . isArecord = false ;
159+ } else if ( this . $store . state . idData . state === 'REJECTED' ) {
160+ this . isRejected = true ;
161+ this . isArecord = false ;
162+ }
163+ }
164+
165+ } catch ( error ) {
166+ throw new Error ( 'getIdData >> throwing error' ) ;
167+ }
168+ } ,
141169 async getSearchResults ( ) {
142170 this . isQueryingSearchService = true ;
143171 const searchUrl = `${ import . meta. env . VITE_API_BASE_URL } ${ import . meta. env . VITE_LIST_SEARCH_PATH } ` ;
0 commit comments