mirror of
http://ghproxy.cn/https://github.com/multunus/onemdm-server
synced 2025-12-06 10:14:59 +00:00
Update device create API
- Update the existing device if a device with existing unique_id is present
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
class DevicesController < ApplicationController
|
||||
skip_before_filter :verify_authenticity_token
|
||||
respond_to :json
|
||||
|
||||
def create
|
||||
device = Device.create(device_params)
|
||||
respond_with device, status: :created
|
||||
device = Device.find_or_initialize_by(unique_id: device_params[:unique_id])
|
||||
device.assign_attributes(device_params)
|
||||
if device.save
|
||||
render json: { access_token: device.access_token }, status: :created
|
||||
else
|
||||
render json: { error: device.errors.full_messages }, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
Reference in New Issue
Block a user