- modify type -> interface and import path, param name

This commit is contained in:
2021-12-30 14:32:45 +09:00
parent 0ebb2571c2
commit 0ea85b9246
6 changed files with 11 additions and 11 deletions

View File

@@ -1,8 +1,8 @@
import { merge } from 'lodash' import { merge } from 'lodash'
import type { AxiosError, AxiosInstance, AxiosRequestConfig, CancelTokenSource } from 'axios' import type { AxiosError, AxiosInstance, AxiosRequestConfig, CancelTokenSource } from 'axios'
import axios from 'axios' import axios from 'axios'
import { HTTP_METHODS } from '../../constants'
import { getError, parseResponse } from './parse' import { getError, parseResponse } from './parse'
import { HTTP_METHODS } from '~/constants'
import { config } from '~/configs' import { config } from '~/configs'
import type { RequestOptions } from '~/types/models/requestOptions' import type { RequestOptions } from '~/types/models/requestOptions'
@@ -16,12 +16,12 @@ const axiosInstance = axios.create({
const axiosInstanceSource = CancelToken.source() const axiosInstanceSource = CancelToken.source()
export function setAxiosRequestConfig( export function setAxiosRequestConfig(
api: AxiosInstance, source: CancelTokenSource, methodType: string, url: string, options?: RequestOptions, api: AxiosInstance, { token: cancelToken }: CancelTokenSource, method: string, url: string, options?: RequestOptions,
) { ) {
const requestConfig = merge({ const requestConfig = merge({
url, url,
cancelToken: source.token, cancelToken,
method: methodType, method,
}, options) }, options)
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
@@ -44,8 +44,8 @@ export function getHttpMethodsWithCancel(
source = axiosInstanceSource, source = axiosInstanceSource,
parse = parseResponse, parse = parseResponse,
) { ) {
const getApiPromise = (methodType: string, url: string, options?: RequestOptions) => const getApiPromise = (method: string, url: string, options?: RequestOptions) =>
setAxiosRequestConfig(api, source, methodType, url, options) setAxiosRequestConfig(api, source, method, url, options)
.then(parse) .then(parse)
.catch((error: AxiosError) => { .catch((error: AxiosError) => {
getError(error) getError(error)

View File

@@ -2,7 +2,7 @@ import type { AxiosError, AxiosResponse } from 'axios'
import { import {
ERROR_CODE, ERROR_CODE,
HTTP_STATUS_CODE, HTTP_STATUS_CODE,
} from '../../constants' } from '~/constants'
import type { ResponseModel } from '~/types/models/responseModel' import type { ResponseModel } from '~/types/models/responseModel'
export const getError = (responseError: AxiosError) => { export const getError = (responseError: AxiosError) => {

View File

@@ -1,6 +1,6 @@
import type { HeroModel } from '~/types/models/heroModel' import type { HeroModel } from '~/types/models/heroModel'
export type HeroStateType = { export interface HeroStateType {
heroes: HeroModel[] heroes: HeroModel[]
hero: HeroModel hero: HeroModel
loading: boolean loading: boolean

View File

@@ -1,4 +1,4 @@
export type HeroModel = { export interface HeroModel {
id: string id: string
firstName: string firstName: string
lastName: string lastName: string

View File

@@ -1,5 +1,5 @@
// Example API Request Options // Example API Request Options
export type RequestOptions<D = any> = { export interface RequestOptions<D = any> {
url: string url: string
data?: D data?: D
params?: any params?: any

View File

@@ -1,5 +1,5 @@
// Example API Response Model // Example API Response Model
export type ResponseModel = { export interface ResponseModel {
data?: any data?: any
success?: boolean success?: boolean
errorCode?: string errorCode?: string