dashboard.ts 1 KB
import { QueryForParams, ServiceResponse } from '@/types/global';
import axios, { AxiosRequestConfig } from 'axios';
import FileSaver from 'file-saver';

export default class useDashboardApi {
  static async userStyle() {
    return axios.get('/dashboard/user-style').then((res) => Promise.resolve(res.data));
  }

  static async activityStyle() {
    return axios.get('/dashboard/activity-style').then((res) => Promise.resolve(res.data));
  }

  static async todo(params?: QueryForParams): Promise<ServiceResponse> {
    return axios.get('/dashboard/todo', { params });
  }

  static async submitWork(params?: QueryForParams) {
    return axios.get('/dashboard/submit-work', { params });
  }

  static async getSubmitWorkExport(fileName: string, params?: QueryForParams) {
    const config = { params: { ...params, fetchType: 'excel' }, timeout: 60000, responseType: 'blob' } as AxiosRequestConfig;
    return axios.get('dashboard/submit-work', config).then(({ data }) => FileSaver.saveAs(data, `${fileName}.xlsx`));
  }
}