Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions drivers/gobright/location_service.cr
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,23 @@ class GoBright::LocationService < PlaceOS::Driver
spaces[space.id] = space.dup
end

# retrieve desk details and perform gobright_desk_name to groups mapping
desks_meta = staff_api.metadata(zone_id, "desks").get.as_h["desks"].as_h
desk_groups_mapping = desks_meta["details"].as_a.map do |desk|
desk_h = desk.as_h
gobright_desk_name = desk_h["gobright_desk_name"].as_s
groups = begin
if (arr = desk_h["groups"].as_a?)
arr.empty? ? ["none"] : arr.map(&.as_s)
elsif desk_h.has_key?("groups") && desk_h["groups"].raw.is_a?(String)
[desk_h.["groups"].as_s]
else
["none"]
end
end
{gobright_desk_name, groups}
end.to_h

# mark if the space is occupied
occupancy = Array(Occupancy).from_json(gobright.live_occupancy(gobright_location_id, @default_space_type).get.to_json)
occupancy.each do |details|
Expand All @@ -174,13 +191,13 @@ class GoBright::LocationService < PlaceOS::Driver

if (occupied = space.occupied?) || @return_empty_spaces
{
location: loc_type,
at_location: occupied ? 1 : 0,
map_id: space.name,
level: zone_id,
building: building_id,
capacity: space.capacity || 1,

location: loc_type,
at_location: occupied ? 1 : 0,
map_id: space.name,
level: zone_id,
building: building_id,
capacity: space.capacity || 1,
group: desk_groups_mapping.fetch(space.name, ["none"]).first,
gobright_location_id: gobright_location_id,
gobright_space_name: space.name,
gobright_space_type: space.type,
Expand Down
23 changes: 23 additions & 0 deletions drivers/gobright/location_service_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ DriverSpecs.mock_driver "GoBright::LocationService" do
"level" => "placeos_zone_id",
"building" => "zone-1234",
"capacity" => 1,
"group" => "HR",
"gobright_location_id" => "level",
"gobright_space_name" => "desk-1",
"gobright_space_type" => "desk",
Expand All @@ -27,6 +28,7 @@ DriverSpecs.mock_driver "GoBright::LocationService" do
"level" => "placeos_zone_id",
"building" => "zone-1234",
"capacity" => 1,
"group" => "none",
"gobright_location_id" => "level",
"gobright_space_name" => "room-1",
"gobright_space_type" => "room",
Expand Down Expand Up @@ -81,6 +83,27 @@ class StaffAPIMock < DriverSpecs::MockDriver
# NOTE:: zone-1234 is the default zone used in the spec runner
[{id: "zone-1234"}]
end

def metadata(id : String, key : String? = nil)
logger.info { "metadata requested from staff api" }

{
"desks": {
"name": "desks",
"description": "",
"details": [
{
"id": "table-07.001.status",
"name": "Desk 07.001",
"groups": ["HR"],
"map_id": "table-07.001.status",
"bookable": true,
"gobright_desk_name": "desk-1",
},
],
},
}
end
end

# :nodoc:
Expand Down
Loading