type customFunction = { functionName: string, method: "GET" | "POST" | "PUT" | "DELETE", apiName: string body?: any, id?: any, } let GeneralCoreService = (apiInstance: { Get: (endPoint: string, id?: any, params?: any) => void, Post: (endPoint: string, body: any, id?: any, params?: any, publicAPI?: boolean) => void, Put: (endPoint: string, body: any, id: any) => void, Delete: (endPoint: string, id: any) => void }, controller: string, apiName?: string, customFunction?: customFunction[]) => { const { Delete, Get, Put, Post } = apiInstance let obj: any = { Save: (body: any, id?: any) => { if (id) { return Put(`${controller}${apiName ? '/' + apiName : ''}`, body, id) } else { return Post(`${controller}${apiName ? '/' + apiName : ''}`, body) } }, GetOne: (id: any) => { return Get(`${controller}${apiName ? '/' + apiName : ''}`, id) }, GetAll: () => { return Get(`${controller}${apiName ? '/' + apiName : ''}`) }, DeleteOne: (id: any) => { return Delete(`${controller}${apiName ? '/' + apiName : ''}`, id) }, } if (customFunction && customFunction.length > 0) { customFunction.forEach((x: customFunction) => { obj[x.functionName] = (body?: any, id?: any) => { switch (x.method) { case "GET": return Get(`${controller}/${x.apiName ? x.apiName : ''}`, id) case "POST": return Post(`${controller}/${x.apiName ? x.apiName : ""}`, body, id) case "PUT": return Put(`${controller}/${x.apiName ? x.apiName : ""}`, body, id) case "DELETE": return Delete(`${controller}/${apiName ? x.apiName : ""}`, id) } } }); } return obj } export default GeneralCoreService