app/apiHandler/invoicesApiSlice.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.
     */
    getInvoicesList: builder.query({
      query: (params) => ({
        url: `/invoices`,
        method: 'get',
        withCredentials: true,
        params: { ...params },
      }),
    }),

    updateInvoice: builder.mutation({
      query: ({ invoiceId, data }) => ({
        url: `/invoices/${invoiceId}`,
        method: 'patch',
        withCredentials: true,
        data: { ...data },
      }),
      keepUnusedDataFor: 0,
    }),

    updateMany: builder.mutation({
      query: ({ ids, data }) => ({
        url: '/invoices/update-many',
        method: 'PATCH',
        withCredentials: true,
        data: { ids, data },
      }),
      invalidatesTags: ['Invoices'],
    }),

    // updateComment: builder.mutation({
    //   query: ({ orderId, data }) => ({
    //     url: `/orders/${orderId}/comment`,
    //     method: 'patch',
    //     withCredentials: true,
    //     data: { ...data },
    //   }),
    //   keepUnusedDataFor: 0,
    // }),
    // updateStatus: builder.mutation({
    //   query: ({ orderId, data }) => ({
    //     url: `/orders/${orderId}/status`,
    //     method: 'patch',
    //     withCredentials: true,
    //     data: { ...data },
    //   }),
    //   keepUnusedDataFor: 0,
    // }),
    // updateManyInactive: builder.mutation({
    //   query: (data) => ({
    //     url: `/orders/many/isactive`,
    //     method: 'patch',
    //     withCredentials: true,
    //     data: { ...data },
    //   }),
    //   keepUnusedDataFor: 0,
    // }),
    // updateManyOrdersGroup: builder.mutation({
    //   query: (data) => ({
    //     url: `/orders/many/ordersgroup`,
    //     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 {
  useGetInvoicesListQuery,
  useUpdateInvoiceMutation,
  useUpdateManyMutation,
} = invoicesApiSlice