stylist / frontend / src / api / useFetchAllServices.ts
useFetchAllServices.ts
Raw
import { QueryOptions, useQuery } from 'react-query';

import { api } from '.';
//types
import { ServicesScreen } from '@/types/services';

const fetchAllServices = async (id: number | undefined) => {
  if (!id) {
    return undefined;
  }
  return await api.get<never, ServicesScreen[]>(`/services/salon/${id}`);
};

export const useFetchAllServices = (
  id: number | undefined,
  options?: QueryOptions<ServicesScreen[] | undefined>
) => {
  return useQuery(['services/salon', id], () => fetchAllServices(id), options);
};