export function documentNamesFetcher()

in web/src/api/hooks/document.ts [76:112]


export function documentNamesFetcher(
    pageNumber = 1,
    pageSize = pageSizes._100,
    filters: FilterWithDocumentExtraOption<keyof FileDocument>[],
    keyword: string = ''
): Promise<PagedResponse<string>> {
    const nameFieldName = 'original_name';
    const sortConfig = {
        field: nameFieldName,
        direction: SortingDirection.ASC
    };
    const extraFilters: FilterWithDocumentExtraOption<keyof FileDocument>[] = [];
    extraFilters.push({
        field: nameFieldName,
        operator: Operators.DISTINCT
    });
    if (keyword) {
        extraFilters.push({
            field: nameFieldName,
            operator: Operators.ILIKE,
            value: `%${keyword}%`
        });
    }
    const body: SearchBody<FileDocument> = {
        pagination: { page_num: pageNumber, page_size: pageSize },
        filters: [...extraFilters, ...filters],
        sorting: [
            { direction: sortConfig.direction, field: sortConfig.field as keyof FileDocument }
        ]
    };

    return useBadgerFetch<PagedResponse<string>>({
        url: `${filesNamespace}/files/search`,
        method: 'post',
        withCredentials: true
    })(JSON.stringify(body));
}