Skip to content

Commit

Permalink
Merge pull request #180 from deanblackborough/v2.11.1
Browse files Browse the repository at this point in the history
v2.10.3
  • Loading branch information
deanblackborough authored May 9, 2020
2 parents 02371b5 + 3f886c9 commit d33650b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

The complete changelog for the Costs to Expect REST API, our changelog follows the format defined at https://keepachangelog.com/en/1.0.0/

## [v2.10.3] - 2020-05-09
### Fixed
- We have updated the delete resource type action; we have added additional checks before we attempt to delete, it was possible to remove relationship values which made the resource type inaccessible.

## [v2.10.2] - 2020-04-30
### Changed
- We have updated all item endpoints to return `updated`; this is the date and time an item was updated, not its category assignments.
Expand Down
43 changes: 35 additions & 8 deletions app/Http/Controllers/ResourceTypeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use App\Models\Category;
use App\Models\ItemType;
use App\Models\PermittedUser;
use App\Models\Resource;
Expand Down Expand Up @@ -295,15 +296,41 @@ public function delete(
true
);

try {
(new ResourceTypeItemType())->instance($resource_type_id)->delete();
(new PermittedUser())->instance($resource_type_id, Auth::user()->id)->delete();
(new ResourceType())->find($resource_type_id)->delete();
UtilityResponse::successNoContent();
} catch (QueryException $e) {
$resource_type_item_type = (new ResourceTypeItemType())->instance($resource_type_id);
$permitted_user = (new PermittedUser())->instance($resource_type_id, Auth::user()->id);
$resource_type = (new ResourceType())->find($resource_type_id);

$categories = (new Category())->total(
$resource_type_id,
$this->permitted_resource_types,
$this->include_public
);

$resources = (new Resource())->totalCount(
$resource_type_id,
$this->permitted_resource_types,
$this->include_public
);

if (
$categories === 0 &&
$resources === 0 &&
$resource_type_item_type !== null &&
$permitted_user !== null &&
$resource_type !== null
) {
try {
$resource_type_item_type->delete();
$permitted_user->delete();
$resource_type->delete();
UtilityResponse::successNoContent();
} catch (QueryException $e) {
UtilityResponse::foreignKeyConstraintError();
} catch (Exception $e) {
UtilityResponse::notFound(trans('entities.resource-type'), $e);
}
} else {
UtilityResponse::foreignKeyConstraintError();
} catch (Exception $e) {
UtilityResponse::notFound(trans('entities.resource-type'), $e);
}
}

Expand Down
4 changes: 2 additions & 2 deletions config/api/app/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
declare(strict_types=1);

return [
'version'=> '2.10.2',
'version'=> '2.10.3',
'prefix' => 'v2',
'release_date' => '2020-04-30',
'release_date' => '2020-05-09',
'changelog' => [
'api' => '/v2/changelog',
'markdown' => 'https://github.com/costs-to-expect/api/blob/master/CHANGELOG.md'
Expand Down
1 change: 1 addition & 0 deletions resources/views/welcome.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ function gtag(){dataLayer.push(arguments);}
<li>We have corrected a typo on the landing page.</li>
<li>We have switched the table we look at to return created at for an item; we should be using the sub table, not the base item table.</li>
<li>We have corrected the `/resource-types/` OPTIONS request; `public` is not a required field.</li>
<li>We have updated the delete resource type action; we have added additional checks before we attempt to delete, it was possible to remove relationship values which made the resource type inaccessible.</li>
</ul>
</div>
</div>
Expand Down

0 comments on commit d33650b

Please sign in to comment.