index.ts 2.9 KB
import { DeviceInfoItemType, DeviceTypeItem, PageParams, ScriptTestParams } from './model';
import { TBPaginationResult } from '/#/axios';
import { ScriptLanguageEnum } from '/@/enums/scriptEnum';
import { defHttp } from '/@/utils/http/axios';

enum Api {
  GET_DEVICE_INFOS = '/tenant/deviceInfos',
  GET_DEVICE_TYPE = '/device/types',
  TENANT_QUEUE = '/tenant/queues',
  TEST_SCRIPT = '/ruleChain/testScript',
}

enum Entity {
  DEVICES = '/tenant/devices',
  ASSETS = '/tenant/assets',
  ENTITY_VIEW = '/tenant/entityViews',
  TENANT = '/tenant',
  CUSTOMER = '/customers',
  DASHBOARD = '/tenant/dashboards',
  USER = '/users',
  EDGE = '/tenant/edges',
}

export const getDeviceInfos = () => {
  return defHttp.get<TBPaginationResult<DeviceInfoItemType>>(
    {
      url: Api.GET_DEVICE_INFOS,
    },
    { joinPrefix: false }
  );
};

export const getDeviceTypes = () => {
  return defHttp.get<TBPaginationResult<DeviceTypeItem[]>>(
    {
      url: Api.GET_DEVICE_TYPE,
    },
    { joinPrefix: false }
  );
};

export const getTenantQueue = (params: Recordable) => {
  return defHttp.get<string[]>(
    {
      url: Api.TENANT_QUEUE,
      params,
    },
    { joinPrefix: false }
  );
};

export const getEntityDevice = (params: PageParams) => {
  return defHttp.get(
    {
      url: Entity.DEVICES,
      params,
    },
    {
      joinPrefix: false,
    }
  );
};

export const getEntityAssets = (params: PageParams) => {
  return defHttp.get(
    {
      url: Entity.ASSETS,
      params,
    },
    {
      joinPrefix: false,
    }
  );
};

export const getEntityViews = (params: PageParams) => {
  return defHttp.get(
    {
      url: Entity.ENTITY_VIEW,
      params,
    },
    {
      joinPrefix: false,
    }
  );
};

export const getEntityTenant = (params: Record<'tenantId', string>) => {
  return defHttp.get(
    {
      url: `${Entity.TENANT}/${params.tenantId}`,
      params,
    },
    {
      joinPrefix: false,
    }
  );
};

export const getEntityCustomer = (params: PageParams) => {
  return defHttp.get(
    {
      url: Entity.CUSTOMER,
      params,
    },
    {
      joinPrefix: false,
    }
  );
};

export const getEntityUser = (params: PageParams) => {
  return defHttp.get(
    {
      url: Entity.USER,
      params,
    },
    {
      joinPrefix: false,
    }
  );
};

export const getEntityDashboard = (params: PageParams) => {
  return defHttp.get(
    {
      url: Entity.DASHBOARD,
      params,
    },
    {
      joinPrefix: false,
    }
  );
};

export const getEntityEdge = (params: PageParams) => {
  return defHttp.get(
    {
      url: Entity.EDGE,
      params,
    },
    {
      joinPrefix: false,
    }
  );
};

export const testScript = (
  data: ScriptTestParams,
  scriptLang: ScriptLanguageEnum = ScriptLanguageEnum.JavaScript
) => {
  return defHttp.post<Record<'error' | 'output', string>>(
    {
      url: `${Api.TEST_SCRIPT}?scriptLang=${scriptLang}`,
      data,
    },
    { joinPrefix: false }
  );
};