diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index ff73d17335..23a3860178 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -68,7 +68,7 @@ class Kernel extends ConsoleKernel } - if(config('queue.default') && Ninja::isSelfHost()) { + if(config('queue.default') == 'database' && Ninja::isSelfHost()) { $schedule->command('queue:work')->everyMinute()->withoutOverlapping(); $schedule->command('queue:restart')->everyFiveMinutes()->withoutOverlapping(); } diff --git a/app/Http/Controllers/TaskStatusController.php b/app/Http/Controllers/TaskStatusController.php index 4934e0b5fa..4751ee9d0d 100644 --- a/app/Http/Controllers/TaskStatusController.php +++ b/app/Http/Controllers/TaskStatusController.php @@ -8,6 +8,7 @@ use App\Http\Requests\TaskStatus\DestroyTaskStatusRequest; use App\Http\Requests\TaskStatus\ShowTaskStatusRequest; use App\Http\Requests\TaskStatus\StoreTaskStatusRequest; use App\Http\Requests\TaskStatus\UpdateTaskStatusRequest; +use App\Models\Task; use App\Models\TaskStatus; use App\Repositories\TaskStatusRepository; use App\Transformers\TaskStatusTransformer; @@ -398,8 +399,9 @@ class TaskStatusController extends BaseController */ public function destroy(DestroyTaskStatusRequest $request, TaskStatus $task_status) { - $task_status->delete(); + $this->task_status_repo->delete($task_status); + return $this->itemResponse($task_status->fresh()); } diff --git a/app/Repositories/TaskStatusRepository.php b/app/Repositories/TaskStatusRepository.php index 4ba2c6d63f..6448bac5c3 100644 --- a/app/Repositories/TaskStatusRepository.php +++ b/app/Repositories/TaskStatusRepository.php @@ -11,9 +11,39 @@ namespace App\Repositories; +use App\Models\Task; + /** * Class for task status repository. */ class TaskStatusRepository extends BaseRepository { + + public function delete($task_status) + { + + Task::where('status_id', $task_status->id) + ->where('company_id', $task_status->company_id) + ->update(['status_id' => null]); + + + parent::delete($task_status); + + return $task_status; + + } + + public function archive($task_status) + { + + Task::where('status_id', $task_status->id) + ->where('company_id', $task_status->company_id) + ->update(['status_id' => null]); + + + parent::archive($task_status); + + return $task_status; + + } } diff --git a/tests/Feature/TaskStatusApiTest.php b/tests/Feature/TaskStatusApiTest.php index 7e37c2c61f..c93b28d7e3 100644 --- a/tests/Feature/TaskStatusApiTest.php +++ b/tests/Feature/TaskStatusApiTest.php @@ -122,6 +122,23 @@ class TaskStatusApiTest extends TestCase $this->assertEquals(0, $arr['data'][0]['archived_at']); } + + public function testTaskStatusDeletedFromDELETEROute() + { + $data = [ + 'ids' => [$this->encodePrimaryKey($this->task_status->id)], + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->delete('/api/v1/task_statuses/'.$this->encodePrimaryKey($this->task_status->id)); + + $arr = $response->json(); + + $this->assertTrue($arr['data']['is_deleted']); + } + public function testTaskStatusDeleted() { $data = [