All files / api/modules devices.js

92.3% Statements 12/13
75% Branches 3/4
100% Functions 9/9
92.3% Lines 12/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56        2x       1x       1x   1x                       2x   1x       1x       1x       1x       3x       1x       2x      
import { apiGet, apiPost } from "../client";
import { unifyDeviceFields } from "../mappers";
 
function safeId(id) {
  return encodeURIComponent(String(id));
}
 
function mapDevicesResponse(result) {
  Iif (!result.ok) {
    return result;
  }
 
  const devices = result.data?.data?.devices || [];
 
  return {
    ...result,
    data: {
      ...result.data,
      data: {
        ...result.data?.data,
        devices: devices.map(unifyDeviceFields),
      },
    },
  };
}
 
export const devicesApi = {
  async list() {
    return mapDevicesResponse(await apiGet("/api/v1/devices/list"));
  },
 
  status(id, options) {
    return apiGet(`/api/v1/devices/id/${safeId(id)}/status`, options);
  },
 
  reboot(id) {
    return apiGet(`/api/v1/devices/id/${safeId(id)}/reboot`);
  },
 
  action(payload) {
    return apiPost("/api/v1/devices/action", payload);
  },
 
  scanningSetup(options) {
    return apiGet("/api/v1/devices/scanning/setup", options);
  },
 
  scanningAll(options) {
    return apiGet("/api/v1/devices/scanning/all", options);
  },
 
  setupNewDevice(payload) {
    return apiPost("/api/v1/devices/setup/new-device", payload);
  },
};