import { IFunnel } from "App/mstore/types/funnel" import APIClient from 'App/api_client'; export interface IFunnelService { initClient(client?: APIClient) all(): Promise one(funnelId: string): Promise save(funnel: IFunnel): Promise delete(funnelId: string): Promise fetchInsights(funnelId: string, payload: any): Promise fetchIssues(funnelId?: string, payload?: any): Promise fetchIssue(funnelId: string, issueId: string): Promise } export default class FunnelService implements IFunnelService { private client: APIClient; constructor(client?: APIClient) { this.client = client ? client : new APIClient(); } initClient(client?: APIClient) { this.client = client || new APIClient(); } all(): Promise { return this.client.get('/funnels') .then(response => response.json()) .then(response => response.data || []); } one(funnelId: string): Promise { return this.client.get(`/funnels/${funnelId}`) .then(response => response.json()) } save(funnel: IFunnel): Promise { return this.client.post('/funnels', funnel) .then(response => response.json()) } delete(funnelId: string): Promise { return this.client.delete(`/funnels/${funnelId}`) .then(response => response.json()) } fetchInsights(funnelId: string, payload: any): Promise { return this.client.post(`/funnels/${funnelId}/insights`, payload) .then(response => response.json()) } fetchIssues(funnelId?: string, payload?: any): Promise { const path = funnelId ? `/funnels/${funnelId}/issues` : '/funnels/issues'; return this.client.post(path, payload) .then(response => response.json()) .then(response => response.data || []); } fetchIssue(funnelId: string, issueId: string): Promise { return this.client.post(`/funnels/${funnelId}/issues/${issueId}/sessions`, {}) .then(response => response.json()) .then(response => response.data || {}); } }