dashpresshq/dashpress

View on GitHub
src/frontend/lib/data/useApi/tableDataParamsToQueryString.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import qs from "qs";

import type { IPaginatedDataState } from "@/shared/types/data";

export const tableDataParamsToQueryString = (
  dataState: IPaginatedDataState<unknown>
): string => {
  const sortBy = dataState?.sortBy?.[0]?.id;
  const orderBy = dataState?.sortBy?.[0]?.desc ? "desc" : "asc";

  return `?${qs.stringify({
    page: dataState.pageIndex + 1,
    take: dataState.pageSize,
    orderBy,
    sortBy,
    filters: dataState.filters,
  })}`;
};