All files / apps/huella-legal/layers/search/app/composables useArticleSearch.ts

100% Statements 14/14
100% Branches 2/2
100% Functions 6/6
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25    2x 8x 8x   8x 5x 2x     8x 1x 4x   8x   8x 2x   8x   7x    
import type { RouteLocationRaw } from "vue-router";
 
export const useArticleSearch = async () => {
    const route = useRoute();
    const { link, navigate } = useListingQuery({ page: "1", query: "" });
 
    const term = computed<string>({
        get: () => (typeof route.query.query === "string" ? route.query.query.trim() : ""),
        set: (value) => void navigate({ query: value.trim() }),
    });
 
    const request = useCachedFetch<ArticleSearch>("/api/search", {
        query: computed(() => ({ query: term.value, page: route.query.page })),
        enabled: () => term.value !== "",
    });
    const { data: search, status } = request;
 
    const pageLink = (page: number): RouteLocationRaw =>
        link({ query: term.value, page: String(page) });
 
    await useFailOnError(request, { refetches: true });
 
    return { search, term, status, pageLink };
};