All files / src/api/core/lib apiHelper.ts

88.46% Statements 23/26
100% Branches 6/6
83.33% Functions 5/6
88.46% Lines 23/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 271x 1x 1x 1x 1x 12x 27x 27x 27x 12x 2x 2x 2x 12x       12x 1x 1x 1x 12x 2x 1x 1x 12x  
import { AxiosInstance, AxiosRequestConfig } from 'axios';
 
import { CommonSuccessResponse } from '@/types/service/common';
 
export const createApiHelper = (axios: AxiosInstance) => ({
  get: async <T>(url: string, config?: AxiosRequestConfig): Promise<T> => {
    const response = await axios.get<CommonSuccessResponse<T>>(url, config);
    return response.data.data;
  },
  post: async <T>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<T> => {
    const response = await axios.post<CommonSuccessResponse<T>>(url, data, config);
    return response.data.data;
  },
  put: async <T>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<T> => {
    const response = await axios.put<CommonSuccessResponse<T>>(url, data, config);
    return response.data.data;
  },
  delete: async <T>(url: string, config?: AxiosRequestConfig): Promise<T> => {
    const response = await axios.delete<CommonSuccessResponse<T>>(url, config);
    return response.data.data;
  },
  patch: async <T>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<T> => {
    const response = await axios.patch<CommonSuccessResponse<T>>(url, data, config);
    return response.data.data;
  },
});