(command: APICommand)
| 8 | * drivers cannot be managed on them. |
| 9 | */ |
| 10 | export const listOwnedHubs = async (command: APICommand): Promise<Device[]> => { |
| 11 | const hubs = await command.client.devices.list({ type: DeviceIntegrationType.HUB }) |
| 12 | const locationIds = new Set<string>() |
| 13 | hubs.forEach(hub => { |
| 14 | if (hub.locationId !== undefined) { |
| 15 | locationIds.add(hub.locationId) |
| 16 | } else { |
| 17 | command.logger.warn('hub record found without locationId', hub) |
| 18 | } |
| 19 | }) |
| 20 | |
| 21 | // remove shared locations |
| 22 | for (const locationId of locationIds) { |
| 23 | const location = await command.client.locations.get(locationId, { allowed: true }) |
| 24 | |
| 25 | if (!location.allowed?.includes('d:locations')) { |
| 26 | command.logger.warn('filtering out location', location) |
| 27 | locationIds.delete(location.locationId) |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | return hubs.filter(hub => hub.locationId && locationIds.has(hub.locationId)) |
| 32 | } |
no outgoing calls
no test coverage detected