| 312 | } |
| 313 | |
| 314 | pub async fn update(dp: DeviceProfile) -> Result<DeviceProfile, Error> { |
| 315 | dp.validate() |
| 316 | .map_err(|e| Error::Validation(e.to_string()))?; |
| 317 | |
| 318 | let dp: DeviceProfile = diesel::update(device_profile::dsl::device_profile.find(&dp.id)) |
| 319 | .set(( |
| 320 | device_profile::updated_at.eq(Utc::now()), |
| 321 | device_profile::name.eq(&dp.name), |
| 322 | device_profile::description.eq(&dp.description), |
| 323 | device_profile::region.eq(&dp.region), |
| 324 | device_profile::mac_version.eq(&dp.mac_version), |
| 325 | device_profile::reg_params_revision.eq(&dp.reg_params_revision), |
| 326 | device_profile::adr_algorithm_id.eq(&dp.adr_algorithm_id), |
| 327 | device_profile::payload_codec_runtime.eq(&dp.payload_codec_runtime), |
| 328 | device_profile::payload_codec_script.eq(&dp.payload_codec_script), |
| 329 | device_profile::flush_queue_on_activate.eq(&dp.flush_queue_on_activate), |
| 330 | device_profile::uplink_interval.eq(&dp.uplink_interval), |
| 331 | device_profile::device_status_req_interval.eq(&dp.device_status_req_interval), |
| 332 | device_profile::supports_otaa.eq(&dp.supports_otaa), |
| 333 | device_profile::supports_class_b.eq(&dp.supports_class_b), |
| 334 | device_profile::supports_class_c.eq(&dp.supports_class_c), |
| 335 | device_profile::tags.eq(&dp.tags), |
| 336 | device_profile::measurements.eq(&dp.measurements), |
| 337 | device_profile::auto_detect_measurements.eq(&dp.auto_detect_measurements), |
| 338 | device_profile::region_config_id.eq(&dp.region_config_id), |
| 339 | device_profile::allow_roaming.eq(&dp.allow_roaming), |
| 340 | device_profile::rx1_delay.eq(&dp.rx1_delay), |
| 341 | device_profile::abp_params.eq(&dp.abp_params), |
| 342 | device_profile::class_b_params.eq(&dp.class_b_params), |
| 343 | device_profile::class_c_params.eq(&dp.class_c_params), |
| 344 | device_profile::relay_params.eq(&dp.relay_params), |
| 345 | device_profile::app_layer_params.eq(&dp.app_layer_params), |
| 346 | device_profile::device_id.eq(&dp.device_id), |
| 347 | device_profile::firmware_version.eq(&dp.firmware_version), |
| 348 | device_profile::vendor_profile_id.eq(&dp.vendor_profile_id), |
| 349 | device_profile::supported_uplink_data_rates.eq(&dp.supported_uplink_data_rates), |
| 350 | )) |
| 351 | .get_result(&mut get_async_db_conn().await?) |
| 352 | .await |
| 353 | .map_err(|e| error::Error::from_diesel(e, dp.id.to_string()))?; |
| 354 | |
| 355 | info!(id = %dp.id, "Device-profile updated"); |
| 356 | Ok(dp) |
| 357 | } |
| 358 | |
| 359 | pub async fn set_measurements(id: Uuid, m: &fields::Measurements) -> Result<DeviceProfile, Error> { |
| 360 | let dp: DeviceProfile = |