Projekt

Obecné

Profil

Stáhnout (1.3 KB) Statistiky
| Větev: | Tag: | Revize:
1
import { axiosInstance } from "./api"
2
import { log } from "../logging/logger"
3

    
4
export interface SearchParams {
5
    inventories?: string[]
6
    rooms?: string[]
7
    artists?: string[]
8
    nationalities?: string[]
9
    subjects?: string[]
10
    techniques?: string[]
11
    isSchoolOfPrague?: boolean
12
    isOriginal?: boolean
13
    isCopy?: boolean
14
    isLowQuality?: boolean
15
    isHighQuality?: boolean
16
    isIdentified?: boolean
17
    institutions?: string[]
18
    cities?: string[]
19
    countries?: string[]
20
    searchQuery?: string
21
    //TODO: add other search params
22
}
23

    
24
const composeSearchParams = (array: string[] | undefined, identifier: string) => {
25
    log.debug("composeSearchParams", array, identifier)
26

    
27
    if (array && array.length > 0) {
28
        return array.map((item) => `&${identifier}=${item}`).join("")
29
    }
30
    return ""
31
}
32

    
33
export const searchRequest = async (params: SearchParams) => {
34
    const url = "/search_v2"
35
    + "?search=" + (params.searchQuery ? params.searchQuery : "")
36
    + composeSearchParams(params.inventories, "inventory")
37
    + composeSearchParams(params.rooms, "room")
38
    + composeSearchParams(params.artists, "persname")
39
    + composeSearchParams(params.nationalities, "nationality")
40
    // TODO add other search params
41
    log.debug("searchRequest url: " + url)
42
    return await axiosInstance.get(url)
43

    
44
}
(7-7/7)