@@ -101,7 +101,7 @@ module PlaceOS::Api
101101 render_system_trigger(current_sys_trig, complete: complete)
102102 end
103103
104- record UpdateParams , enabled : Bool ?, important : Bool ?, exec_enabled : Bool ? do
104+ record UpdateParams , enabled : Bool ?, important : Bool ?, exec_enabled : Bool ?, playlists : Array ( String )? do
105105 include JSON ::Serializable
106106 end
107107
@@ -113,6 +113,14 @@ module PlaceOS::Api
113113 current.enabled = args.enabled.as(Bool ) unless args.enabled.nil?
114114 current.important = args.important.as(Bool ) unless args.important.nil?
115115 current.exec_enabled = args.exec_enabled.as(Bool ) unless args.exec_enabled.nil?
116+ # validate the playlist ids
117+ if playlists = args.playlists
118+ if playlists.empty?
119+ current.playlists = playlists
120+ else
121+ current.playlists = ::PlaceOS ::Model ::Playlist .find_all(playlists).map(& .id.as(String ))
122+ end
123+ end
116124 raise Error ::ModelValidation .new(current.errors) unless current.save
117125 current
118126 end
@@ -125,6 +133,9 @@ module PlaceOS::Api
125133 sys_id : String ,
126134 ) : ::PlaceOS ::Model ::TriggerInstance
127135 trig_inst.control_system_id = sys_id
136+ if (playlists = trig_inst.playlists) && ! playlists.empty?
137+ trig_inst.playlists = ::PlaceOS ::Model ::Playlist .find_all(playlists).map(& .id.as(String ))
138+ end
128139 raise Error ::ModelValidation .new(trig_inst.errors) unless trig_inst.save
129140 trig_inst
130141 end
0 commit comments