app/apiHandler/ordersGroupsApiSlice.js

/**
 * @file
 * File : ordersGroupsApiSlice.js\
 * Defines API endpoints for managing orders groups using RTK Query.
 * Extends the base API slice with endpoints related to orders groups.
 *
 * @author  Pierre-Yves Léglise <contact@axialdata.net>
 * @name ordersGroupsApiSlice
 */
import { apiSlice } from './apiSlice'

export const ordersGroupsApiSlice = apiSlice.injectEndpoints({
  /**
   * Injects additional endpoints related to orders groups into the base API slice.
   * Defines endpoints for querying orders groups.
   *
   * @category ApiSlice
   * @function
   * @author  Pierre-Yves Léglise <contact@axialdata.net>
   * @param {Object} builder - RTK Query endpoints builder.
   * @example
   *  const { data, isLoading, isFetching } = useGetOrdersGroupsListQuery()
   * @returns {Object} Object containing order groups-related endpoint definitions.
   */
  endpoints: (builder) => ({
    /**
     * Endpoint for retrieving a list of orders groups.
     * Sends a GET request to the `/ordersgroups` endpoint.
     *
     * @method
     * @author  Pierre-Yves Léglise <contact@axialdata.net>
     * @name getOrdersGroupsList
     * @param {Object} [params] - Additional query parameters for filtering or pagination.
     * @example
     *  const { data, isLoading, isFetching } = useGetOrdersGroupsListQuery()
     * @returns {Object} Result of the API request.
     */
    listOrdersGroups: builder.query({
      query: (params) => ({
        url: '/ordersgroups',
        method: 'get',
        withCredentials: true,
        params: { ...params },
      }),
    }),

    createOrdersGroup: builder.mutation({
      query: (data) => ({
        url: '/ordersgroups/new',
        method: 'put',
        withCredentials: true,
        data: { ...data },
      }),
    }),

    updateOrdersGroup: builder.mutation({
      query: ({ id, data }) => ({
        url: `/ordersgroups/${id}`,
        method: 'patch',
        withCredentials: true,
        data: { ...data },
      }),
    }),
  }),
})

/**
 * Hooks for interacting with the orders groups-related endpoints.
 *
 * @typedef {Object} Hooks
 * @author  Pierre-Yves Léglise <contact@axialdata.net>
 * @property {Function} useGetOrdersGroupsListQuery - Hook to trigger the getOrdersGroupsList query.
 * @example
 *  const { data, isLoading, isFetching } = useGetOrdersGroupsListQuery()
 * @returns {Object} Object containing orders groups-related endpoint hooks.
 */
export const {
  useListOrdersGroupsQuery,
  useCreateOrdersGroupMutation,
  useUpdateOrdersGroupMutation,
} = ordersGroupsApiSlice