All files / app/src/entities/nomenclature/model get-nomenclature-diameters-by-connection-query.ts

100% Statements 26/26
100% Branches 3/3
100% Functions 2/2
100% Lines 26/26

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 26 27 28 29 30 31 32 33 34 35 36 37 38 391x             1x 1x 1x 1x   1x 9x 9x 9x 9x 9x 9x 9x   1x 9x 9x       9x 9x   9x 9x 9x 9x 9x 9x 9x 9x  
import { useRouter } from 'next/router'
import { queryFetchDiametersByConnection } from './nomenclature-requests'
import { queryFactory, QueryParams } from '@/shared/lib'
import { CollectionResponse, Nullable } from '@/shared/@types'
import { SELECT_INITIAL_FILTERS } from '@/shared/config'
import { NOMENCLATURE_DIAMETERS_BY_CONNECTION_PRIMARY_KEY, NomenclatureDiameter } from '../lib'
 
const NOMENCLATURE_DIAMETER_BY_CONNECTION_QUERY_FILTERS = {
  ...SELECT_INITIAL_FILTERS,
  value: null as Nullable<string>,
}
 
const nomenclatureDiametersByConnectionCollectionQuery = (id: string) =>
  queryFactory(
    NOMENCLATURE_DIAMETERS_BY_CONNECTION_PRIMARY_KEY,
    queryFetchDiametersByConnection(id),
    NOMENCLATURE_DIAMETER_BY_CONNECTION_QUERY_FILTERS
  )(filters => ({
    params: filters,
  }))
 
export const useNomenclatureDiametersByConnectionCollection = (
  id: string,
  params?: QueryParams<
    CollectionResponse<NomenclatureDiameter>,
    typeof NOMENCLATURE_DIAMETER_BY_CONNECTION_QUERY_FILTERS
  >
) => {
  const { locale } = useRouter()
 
  return nomenclatureDiametersByConnectionCollectionQuery(id).useHookInitializer({
    ...params,
    filters: {
      locale,
      ...params?.filters,
    },
  })
}