app/apiHandler/triggersApiSlice.js

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

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

    updateTriggers: builder.mutation({
      query: ({ data }) => ({
        url: `/triggers`,
        method: 'patch',
        withCredentials: true,
        data: { ...data },
      }),
      keepUnusedDataFor: 0,
    }),
  }),
})

/**
 * Hooks for interacting with the orders-related endpoints.
 *
 * @typedef {Object} Hooks
 * @author  Pierre-Yves Léglise <contact@axialdata.net>
 * @property {Function} useGetOrdersListQuery - Hook to trigger the getOrdersList query.
 * @example
 *  const { data, isLoading, isFetching } = useGetOrdersListQuery({
 *    ordersGroupNb: selectedOrdersGroupNb,
 *  })
 * @returns {Object} Object containing order-related endpoint hooks.
 */
export const { useListTriggersQuery, useUpdateTriggersMutation } =
  invoicesApiSlice