From 270fa5b829a67a7cb1e003821b86017c874a1ba5 Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 23 Dec 2021 19:20:41 +0200 Subject: [PATCH] using axios function signature --- lib/http.service.ts | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/lib/http.service.ts b/lib/http.service.ts index e50abcf..6526732 100644 --- a/lib/http.service.ts +++ b/lib/http.service.ts @@ -1,34 +1,30 @@ import { Injectable } from '@nestjs/common'; import { Inject } from '@nestjs/common'; -import Axios ,{AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'; +import Axios ,{ AxiosInstance } from 'axios'; import { AXIOS_INSTANCE_TOKEN } from "./http.constants"; @Injectable() export class HttpService { + public readonly put: typeof Axios.put; + public readonly post: typeof Axios.post; + public readonly patch: typeof Axios.patch; + public readonly head: typeof Axios.patch; + public readonly delete: typeof Axios.delete; + public readonly get: typeof Axios.get; + public readonly request: typeof Axios.request; + constructor( @Inject(AXIOS_INSTANCE_TOKEN) private readonly instance: AxiosInstance = Axios, - ) {} - request(config: AxiosRequestConfig): Promise> { - return this.instance.request(config) - } - get(url: string, config?: AxiosRequestConfig): Promise> { - return this.instance.get(url, config); - } - delete(url: string, config?: AxiosRequestConfig): Promise> { - return this.instance.delete(url, config); - } - head(url: string, config?: AxiosRequestConfig): Promise> { - return this.instance.head(url, config); - } - post(url: string, data?: Record, config?: AxiosRequestConfig): Promise> { - return this.instance.post(url, data, config); - } - put(url: string, data?: Record, config?: AxiosRequestConfig): Promise> { - return this.instance.put(url, data, config); - } - patch(url: string, data?: Record, config?: AxiosRequestConfig): Promise> { - return this.instance.patch(url, data, config); + ) { + this.put = this.instance.put; + this.post = this.instance.post; + this.patch = this.instance.patch; + this.head = this.instance.head; + this.head = this.instance.head; + this.delete = this.instance.delete; + this.get = this.instance.get; + this.request = this.instance.request; } get axiosRef(): AxiosInstance {