2020-10-12 22:42:02 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-10-12 22:42:02 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-10-12 22:42:02 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-11-03 11:04:15 +01:00
|
|
|
use App\Events\Task\TaskWasCreated;
|
|
|
|
use App\Events\Task\TaskWasUpdated;
|
2020-10-12 22:42:02 +02:00
|
|
|
use App\Factory\TaskFactory;
|
|
|
|
use App\Filters\TaskFilters;
|
|
|
|
use App\Http\Requests\Task\CreateTaskRequest;
|
|
|
|
use App\Http\Requests\Task\DestroyTaskRequest;
|
|
|
|
use App\Http\Requests\Task\EditTaskRequest;
|
|
|
|
use App\Http\Requests\Task\ShowTaskRequest;
|
2021-04-17 00:28:19 +02:00
|
|
|
use App\Http\Requests\Task\SortTaskRequest;
|
2020-10-12 22:42:02 +02:00
|
|
|
use App\Http\Requests\Task\StoreTaskRequest;
|
|
|
|
use App\Http\Requests\Task\UpdateTaskRequest;
|
2021-02-15 22:14:30 +01:00
|
|
|
use App\Http\Requests\Task\UploadTaskRequest;
|
2021-03-07 22:32:38 +01:00
|
|
|
use App\Models\Account;
|
2020-11-03 11:04:15 +01:00
|
|
|
use App\Models\Task;
|
2021-04-17 00:28:19 +02:00
|
|
|
use App\Models\TaskStatus;
|
2020-10-12 22:42:02 +02:00
|
|
|
use App\Repositories\TaskRepository;
|
|
|
|
use App\Transformers\TaskTransformer;
|
2020-11-03 11:04:15 +01:00
|
|
|
use App\Utils\Ninja;
|
2020-10-12 22:42:02 +02:00
|
|
|
use App\Utils\Traits\BulkOptions;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
2021-02-15 22:14:30 +01:00
|
|
|
use App\Utils\Traits\SavesDocuments;
|
2020-10-12 22:42:02 +02:00
|
|
|
use App\Utils\Traits\Uploadable;
|
2020-10-28 11:10:49 +01:00
|
|
|
use Illuminate\Http\Response;
|
2020-10-12 22:42:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class TaskController.
|
|
|
|
*/
|
|
|
|
class TaskController extends BaseController
|
|
|
|
{
|
|
|
|
use MakesHash;
|
|
|
|
use Uploadable;
|
|
|
|
use BulkOptions;
|
2021-02-15 22:14:30 +01:00
|
|
|
use SavesDocuments;
|
2020-10-12 22:42:02 +02:00
|
|
|
|
|
|
|
protected $entity_type = Task::class;
|
|
|
|
|
|
|
|
protected $entity_transformer = TaskTransformer::class;
|
|
|
|
|
|
|
|
/**
|
2023-08-04 10:13:26 +02:00
|
|
|
* @var TaskRepository
|
2020-10-12 22:42:02 +02:00
|
|
|
*/
|
|
|
|
protected $task_repo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TaskController constructor.
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param TaskRepository $task_repo
|
2020-10-12 22:42:02 +02:00
|
|
|
*/
|
|
|
|
public function __construct(TaskRepository $task_repo)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->task_repo = $task_repo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-28 11:10:49 +01:00
|
|
|
* @OA\Get(
|
2020-10-12 22:42:02 +02:00
|
|
|
* path="/api/v1/tasks",
|
|
|
|
* operationId="getTasks",
|
|
|
|
* tags={"tasks"},
|
|
|
|
* summary="Gets a list of tasks",
|
|
|
|
* description="Lists tasks, search and filters allow fine grained lists to be generated.
|
|
|
|
*
|
|
|
|
* Query parameters can be added to performed more fine grained filtering of the tasks, these are handled by the TaskFilters class which defines the methods available",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2020-10-12 22:42:02 +02:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/index"),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="A list of tasks",
|
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Task"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param TaskFilters $filters
|
|
|
|
* @return Response|mixed
|
2020-10-12 22:42:02 +02:00
|
|
|
*/
|
|
|
|
public function index(TaskFilters $filters)
|
|
|
|
{
|
|
|
|
$tasks = Task::filter($filters);
|
|
|
|
|
|
|
|
return $this->listResponse($tasks);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param ShowTaskRequest $request
|
|
|
|
* @param Task $task
|
|
|
|
* @return Response
|
2020-10-12 22:42:02 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/tasks/{id}",
|
|
|
|
* operationId="showTask",
|
|
|
|
* tags={"tasks"},
|
|
|
|
* summary="Shows a client",
|
|
|
|
* description="Displays a client by id",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2020-10-12 22:42:02 +02:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
|
|
|
* description="The Task Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the task object",
|
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Task"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function show(ShowTaskRequest $request, Task $task)
|
|
|
|
{
|
|
|
|
return $this->itemResponse($task);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param EditTaskRequest $request
|
|
|
|
* @param Task $task
|
|
|
|
* @return Response
|
2020-10-12 22:42:02 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/tasks/{id}/edit",
|
|
|
|
* operationId="editTask",
|
|
|
|
* tags={"tasks"},
|
|
|
|
* summary="Shows a client for editting",
|
|
|
|
* description="Displays a client by id",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2020-10-12 22:42:02 +02:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
|
|
|
* description="The Task Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the client object",
|
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Task"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function edit(EditTaskRequest $request, Task $task)
|
|
|
|
{
|
|
|
|
return $this->itemResponse($task);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param UpdateTaskRequest $request
|
|
|
|
* @param Task $task
|
|
|
|
* @return Response
|
2020-10-12 22:42:02 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Put(
|
|
|
|
* path="/api/v1/tasks/{id}",
|
|
|
|
* operationId="updateTask",
|
|
|
|
* tags={"tasks"},
|
|
|
|
* summary="Updates a client",
|
|
|
|
* description="Handles the updating of a client by id",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2020-10-12 22:42:02 +02:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
|
|
|
* description="The Task Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the client object",
|
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Task"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function update(UpdateTaskRequest $request, Task $task)
|
|
|
|
{
|
|
|
|
if ($request->entityIsDeleted($task)) {
|
|
|
|
return $request->disallowUpdate();
|
|
|
|
}
|
|
|
|
|
2021-02-24 03:12:23 +01:00
|
|
|
$old_task = json_decode(json_encode($task));
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2020-10-12 22:42:02 +02:00
|
|
|
$task = $this->task_repo->save($request->all(), $task);
|
2023-04-11 04:23:09 +02:00
|
|
|
|
2022-03-30 04:54:40 +02:00
|
|
|
$task = $this->task_repo->triggeredActions($request, $task);
|
2020-10-12 22:42:02 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if ($task->status_order != $old_task->status_order) {
|
2021-04-14 11:55:43 +02:00
|
|
|
$this->task_repo->sortStatuses($old_task, $task);
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2021-02-24 03:12:23 +01:00
|
|
|
|
2021-05-06 23:12:07 +02:00
|
|
|
event(new TaskWasUpdated($task, $task->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
2020-11-03 11:04:15 +01:00
|
|
|
|
2023-02-01 04:12:44 +01:00
|
|
|
event('eloquent.updated: App\Models\Task', $task);
|
|
|
|
|
2020-10-12 22:42:02 +02:00
|
|
|
return $this->itemResponse($task->fresh());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param CreateTaskRequest $request
|
|
|
|
* @return Response
|
2020-10-12 22:42:02 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/tasks/create",
|
|
|
|
* operationId="getTasksCreate",
|
|
|
|
* tags={"tasks"},
|
|
|
|
* summary="Gets a new blank client object",
|
|
|
|
* description="Returns a blank object with default values",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2020-10-12 22:42:02 +02:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="A blank client object",
|
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Task"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function create(CreateTaskRequest $request)
|
2023-08-06 09:35:19 +02:00
|
|
|
{
|
|
|
|
/** @var \App\Models\User $user */
|
|
|
|
$user = auth()->user();
|
|
|
|
|
|
|
|
$task = TaskFactory::create($user->company()->id, $user->id);
|
2020-10-12 22:42:02 +02:00
|
|
|
|
|
|
|
return $this->itemResponse($task);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param StoreTaskRequest $request
|
|
|
|
* @return Response
|
2020-10-12 22:42:02 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Post(
|
|
|
|
* path="/api/v1/tasks",
|
|
|
|
* operationId="storeTask",
|
|
|
|
* tags={"tasks"},
|
|
|
|
* summary="Adds a client",
|
|
|
|
* description="Adds an client to a company",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2020-10-12 22:42:02 +02:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the saved client object",
|
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Task"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function store(StoreTaskRequest $request)
|
|
|
|
{
|
2023-08-06 09:35:19 +02:00
|
|
|
/** @var \App\Models\User $user */
|
|
|
|
$user = auth()->user();
|
|
|
|
|
|
|
|
$task = $this->task_repo->save($request->all(), TaskFactory::create($user->company()->id, $user->id));
|
2022-03-30 04:54:40 +02:00
|
|
|
$task = $this->task_repo->triggeredActions($request, $task);
|
2020-10-12 22:42:02 +02:00
|
|
|
|
2023-08-06 09:35:19 +02:00
|
|
|
event(new TaskWasCreated($task, $task->company, Ninja::eventVars($user->id)));
|
2020-11-03 11:04:15 +01:00
|
|
|
|
2023-02-01 04:12:44 +01:00
|
|
|
event('eloquent.created: App\Models\Task', $task);
|
|
|
|
|
|
|
|
|
2020-10-12 22:42:02 +02:00
|
|
|
return $this->itemResponse($task);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param DestroyTaskRequest $request
|
|
|
|
* @param Task $task
|
|
|
|
* @return Response
|
2020-10-12 22:42:02 +02:00
|
|
|
*
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @throws \Exception
|
2020-10-12 22:42:02 +02:00
|
|
|
* @OA\Delete(
|
|
|
|
* path="/api/v1/tasks/{id}",
|
|
|
|
* operationId="deleteTask",
|
|
|
|
* tags={"tasks"},
|
|
|
|
* summary="Deletes a client",
|
|
|
|
* description="Handles the deletion of a client by id",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2020-10-12 22:42:02 +02:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
|
|
|
* description="The Task Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns a HTTP status",
|
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function destroy(DestroyTaskRequest $request, Task $task)
|
|
|
|
{
|
|
|
|
//may not need these destroy routes as we are using actions to 'archive/delete'
|
2021-01-17 05:28:03 +01:00
|
|
|
$this->task_repo->delete($task);
|
2020-10-12 22:42:02 +02:00
|
|
|
|
2021-01-17 05:28:03 +01:00
|
|
|
return $this->itemResponse($task->fresh());
|
2020-10-12 22:42:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform bulk actions on the list view.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return Response
|
2020-10-12 22:42:02 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Post(
|
|
|
|
* path="/api/v1/tasks/bulk",
|
|
|
|
* operationId="bulkTasks",
|
|
|
|
* tags={"tasks"},
|
|
|
|
* summary="Performs bulk actions on an array of tasks",
|
|
|
|
* description="",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2020-10-12 22:42:02 +02:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/index"),
|
|
|
|
* @OA\RequestBody(
|
|
|
|
* description="User credentials",
|
|
|
|
* required=true,
|
|
|
|
* @OA\MediaType(
|
|
|
|
* mediaType="application/json",
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="array",
|
|
|
|
* @OA\Items(
|
|
|
|
* type="integer",
|
|
|
|
* description="Array of hashed IDs to be bulk 'actioned",
|
|
|
|
* example="[0,1,2,3]",
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="The Task User response",
|
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Task"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function bulk()
|
|
|
|
{
|
|
|
|
$action = request()->input('action');
|
|
|
|
|
|
|
|
$ids = request()->input('ids');
|
|
|
|
$tasks = Task::withTrashed()->find($this->transformKeys($ids));
|
|
|
|
|
|
|
|
$tasks->each(function ($task, $key) use ($action) {
|
2023-08-06 09:35:19 +02:00
|
|
|
/** @var \App\Models\User $user */
|
|
|
|
$user = auth()->user();
|
|
|
|
if ($user->can('edit', $task)) {
|
2020-10-12 22:42:02 +02:00
|
|
|
$this->task_repo->{$action}($task);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return $this->listResponse(Task::withTrashed()->whereIn('id', $this->transformKeys($ids)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a client statement.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return void [type] [description]
|
2020-10-12 22:42:02 +02:00
|
|
|
*/
|
|
|
|
public function statement()
|
|
|
|
{
|
|
|
|
//todo
|
|
|
|
}
|
2021-02-15 22:14:30 +01:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
/**
|
2021-02-15 22:14:30 +01:00
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param UploadTaskRequest $request
|
|
|
|
* @param Task $task
|
|
|
|
* @return Response
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Put(
|
|
|
|
* path="/api/v1/tasks/{id}/upload",
|
|
|
|
* operationId="uploadTask",
|
|
|
|
* tags={"tasks"},
|
|
|
|
* summary="Uploads a document to a task",
|
|
|
|
* description="Handles the uploading of a document to a task",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2021-02-15 22:14:30 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
|
|
|
* description="The Task Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the Task object",
|
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Task"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function upload(UploadTaskRequest $request, Task $task)
|
|
|
|
{
|
2022-06-21 11:57:17 +02:00
|
|
|
if (! $this->checkFeature(Account::FEATURE_DOCUMENTS)) {
|
2021-03-07 22:32:38 +01:00
|
|
|
return $this->featureFailure();
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->has('documents')) {
|
2023-08-20 06:05:26 +02:00
|
|
|
$this->saveDocuments($request->file('documents'), $task, $request->input('is_public', true));
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2021-02-15 22:14:30 +01:00
|
|
|
|
|
|
|
return $this->itemResponse($task->fresh());
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2021-04-17 08:51:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
2023-08-04 10:13:26 +02:00
|
|
|
* @param SortTaskRequest $request
|
2021-04-17 08:51:24 +02:00
|
|
|
* @return Response
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Post(
|
|
|
|
* path="/api/v1/tasks/stort",
|
|
|
|
* operationId="sortTasks",
|
|
|
|
* tags={"tasks"},
|
|
|
|
* summary="Sort tasks on KanBan",
|
|
|
|
* description="Sorts tasks after drag and drop on the KanBan.",
|
2023-02-10 10:21:10 +01:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
|
2021-04-17 08:51:24 +02:00
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns an Ok, 200 HTTP status",
|
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response="default",
|
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
2021-04-17 00:28:19 +02:00
|
|
|
public function sort(SortTaskRequest $request)
|
|
|
|
{
|
2021-04-17 00:35:36 +02:00
|
|
|
$task_statuses = $request->input('status_ids');
|
|
|
|
$tasks = $request->input('task_ids');
|
2023-08-06 09:35:19 +02:00
|
|
|
|
|
|
|
/** @var \App\Models\User $user */
|
|
|
|
$user = auth()->user();
|
2021-04-17 00:28:19 +02:00
|
|
|
|
2023-08-06 09:35:19 +02:00
|
|
|
collect($task_statuses)->each(function ($task_status_hashed_id, $key) use($user){
|
|
|
|
$task_status = TaskStatus::query()->where('id', $this->decodePrimaryKey($task_status_hashed_id))
|
|
|
|
->where('company_id', $user->company()->id)
|
2021-05-27 01:25:29 +02:00
|
|
|
->withTrashed()
|
2021-04-17 00:28:19 +02:00
|
|
|
->first();
|
|
|
|
|
|
|
|
$task_status->status_order = $key;
|
|
|
|
$task_status->save();
|
|
|
|
});
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
foreach ($tasks as $key => $task_list) {
|
2021-04-17 00:28:19 +02:00
|
|
|
$sort_status_id = $this->decodePrimaryKey($key);
|
2022-06-21 11:57:17 +02:00
|
|
|
|
|
|
|
foreach ($task_list as $key => $task) {
|
2023-08-06 09:35:19 +02:00
|
|
|
$task_record = Task::query()->where('id', $this->decodePrimaryKey($task))
|
|
|
|
->where('company_id', $user->company()->id)
|
2021-05-27 01:25:29 +02:00
|
|
|
->withTrashed()
|
2021-04-17 00:28:19 +02:00
|
|
|
->first();
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-04-17 00:57:07 +02:00
|
|
|
$task_record->status_order = $key;
|
2021-04-17 00:51:24 +02:00
|
|
|
$task_record->status_id = $sort_status_id;
|
|
|
|
$task_record->save();
|
2021-04-17 00:28:19 +02:00
|
|
|
}
|
|
|
|
}
|
2021-04-17 00:35:36 +02:00
|
|
|
|
2021-05-24 11:39:21 +02:00
|
|
|
return response()->json(['message' => 'Ok'], 200);
|
2021-04-17 00:28:19 +02:00
|
|
|
}
|
2020-10-12 22:42:02 +02:00
|
|
|
}
|