File tree 2 files changed +10
-7
lines changed
2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ export const NavigationBar = () => {
26
26
const [ searchResultIsOpen , setSearchResultIsOpen ] = useState ( false ) ;
27
27
const [ searchQuery , setSearchQuery ] = useState ( '' ) ;
28
28
const [ isLoading , setIsLoading ] = useState ( false ) ;
29
- const [ searchType , setSearchType ] = useState < 'curated' | 'everything ' > ( 'curated' ) ;
29
+ const [ searchType , setSearchType ] = useState < 'curated' | 'other ' > ( 'curated' ) ;
30
30
const [ searchResult , setSearchResult ] = useState < SearchResponse > ( {
31
31
hits : [ ] ,
32
32
total : 0 ,
@@ -39,7 +39,10 @@ export const NavigationBar = () => {
39
39
const searchData = async ( ) => {
40
40
setIsLoading ( true ) ;
41
41
const result = await fetchJson < SearchResponse > ( SEARCH_API , {
42
- params : { query : searchQuery } ,
42
+ params : {
43
+ query : searchQuery ,
44
+ searchType,
45
+ } ,
43
46
} ) ;
44
47
if ( result ) {
45
48
setSearchResult ( result ) ;
Original file line number Diff line number Diff line change @@ -8,20 +8,20 @@ export class SearchService {
8
8
private readonly SEARCH_API = xpServiceUrl ( 'externalArchive/search' ) ;
9
9
10
10
public getSearchHandler : RequestHandler = async ( req , res ) => {
11
- if ( ! validateQuery ( req . query , [ 'query' ] , [ ] ) ) {
11
+ if ( ! validateQuery ( req . query , [ 'query' ] , [ 'searchType' ] ) ) {
12
12
return res . status ( 400 ) . send ( 'Missing or invalid parameters' ) ;
13
13
}
14
14
15
- const { query } = req . query ;
16
- const searchResponse = await this . search ( query ) ;
15
+ const { query, searchType } = req . query ;
16
+ const searchResponse = await this . search ( query , searchType ) ;
17
17
18
18
return res . status ( 200 ) . json ( searchResponse ) ;
19
19
} ;
20
20
21
- private async search ( query : string ) : Promise < SearchResponse | null > {
21
+ private async search ( query : string , searchType ?: string ) : Promise < SearchResponse | null > {
22
22
const searchResponse = await fetchJson < SearchResponse > ( this . SEARCH_API , {
23
23
headers : { secret : process . env . SERVICE_SECRET } ,
24
- params : { query } ,
24
+ params : { query, searchType } ,
25
25
} ) ;
26
26
27
27
return searchResponse ;
You can’t perform that action at this time.
0 commit comments