API detect if new location should be fixed by default (#13637)

This commit is contained in:
Tony Murray
2021-12-27 17:32:50 -06:00
committed by GitHub
parent 0eccd1aac3
commit 4b64d33d13
2 changed files with 6 additions and 6 deletions

View File

@@ -12,7 +12,7 @@ Input:
- location: name of the new location
- lat: latitude
- lng: longitude
- fixed_coordinates: 0 if updated from the device or 1 if the coordinate is fixed (default is fixed)
- fixed_coordinates: 0 if updated from the device or 1 if the coordinate is fixed (default is fixed if lat and lng are valid)
Example:

View File

@@ -2695,11 +2695,11 @@ function add_location(Illuminate\Http\Request $request)
return api_error(400, 'Required fields missing (location, lat and lng needed)');
}
// Set the location
$timestamp = date('Y-m-d H:m:s');
$insert = ['location' => $data['location'], 'lat' => $data['lat'], 'lng' => $data['lng'], 'fixed_coordinates' => $data['fixed_coordinates'] ?? 1, 'timestamp' => $timestamp];
$location_id = dbInsert($insert, 'locations');
if ($location_id != false) {
return api_success_noresult(201, "Location added with id #$location_id");
$location = new \App\Models\Location($data);
$location->fixed_coordinates = $data['fixed_coordinates'] ?? $location->coordinatesValid();
if ($location->save()) {
return api_success_noresult(201, "Location added with id #$location->id");
}
return api_error(500, 'Failed to add the location');