From 384e0449c12618fb6cbc44392f7cf288119636ff Mon Sep 17 00:00:00 2001 From: bp0 Date: Tue, 13 Sep 2022 09:03:55 -0500 Subject: [PATCH] API: allow delete location by id (#14334) * API: allow delete location by id Otherwise impossible to delete location "". * docs/API: location can be name or id for edit and delete --- doc/API/Locations.md | 8 ++++---- includes/html/api_functions.inc.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/API/Locations.md b/doc/API/Locations.md index 2f0405b70c..69524d02c5 100644 --- a/doc/API/Locations.md +++ b/doc/API/Locations.md @@ -65,9 +65,9 @@ Output: Deletes an existing location -Route: `/api/v0/locations/location` +Route: `/api/v0/locations/:location` -- location: name of the location to delete +- location: name or id of the location to delete Example: @@ -89,9 +89,9 @@ Output: Edits a location -Route: `/api/v0/locations/location` +Route: `/api/v0/locations/:location` -- location: name of the location to edit +- location: name or id of the location to edit Input: diff --git a/includes/html/api_functions.inc.php b/includes/html/api_functions.inc.php index 50bfb0f434..9d633f0a5d 100644 --- a/includes/html/api_functions.inc.php +++ b/includes/html/api_functions.inc.php @@ -2855,7 +2855,7 @@ function del_location(Illuminate\Http\Request $request) if (empty($location)) { return api_error(400, 'No location has been provided to delete'); } - $location_id = get_location_id_by_name($location); + $location_id = ctype_digit($location) ? $location : get_location_id_by_name($location); if (empty($location_id)) { return api_error(400, "Failed to delete $location (Does not exists)"); }