Add tasks to customer jobs
Phase 1, item 7, in the Jobs module (tasks are part of a job, and my jobs needs their assignees): - Tasks with name, work type, assignees, status (waiting, in progress, in review, done), due date, estimated hours and description. - Tasks can be added once the job is a quote request or later, not to an archived job. The work type must belong to the job's service units or the shared ones and be in use; assignees must be active. What a task already has stays allowed after being taken out of use. - Job page: a Tehtävät section with a status select per task (announced, focus kept), edit links and delete with a confirmation dialog. Task form with work types grouped by unit and service. - Access: adding, changing and removing for everyone but subcontractors; subcontractors may change task statuses on jobs they are attached to. - Task assignees now count in my jobs (list, Kanban, job access). - Spec and CLAUDE.md updated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Domain\Contracts;
|
||||
|
||||
use App\Modules\Jobs\Domain\Entities\Task;
|
||||
|
||||
interface TaskRepository
|
||||
{
|
||||
/**
|
||||
* Null when the task does not exist or belongs to another job.
|
||||
*/
|
||||
public function findForJob(int $jobId, int $taskId): ?Task;
|
||||
|
||||
public function save(Task $task): Task;
|
||||
|
||||
public function delete(Task $task): void;
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Domain\Entities;
|
||||
|
||||
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
||||
use App\Modules\Jobs\Domain\Enums\TaskStatus;
|
||||
use App\Modules\Jobs\Domain\Exceptions\TasksNotAllowedYet;
|
||||
use App\Modules\Jobs\Domain\ValueObjects\EstimatedHours;
|
||||
use App\Modules\Jobs\Domain\ValueObjects\TaskTitle;
|
||||
use DateTimeImmutable;
|
||||
|
||||
/**
|
||||
* A task (tehtävä) of a customer job: one step of the work, done by its
|
||||
* assignees under one work type. Time entries are recorded on tasks.
|
||||
*/
|
||||
final class Task
|
||||
{
|
||||
/**
|
||||
* @param list<int> $assigneeUserIds
|
||||
*/
|
||||
private function __construct(
|
||||
private ?int $id,
|
||||
private int $jobId,
|
||||
private int $workTypeId,
|
||||
private TaskTitle $title,
|
||||
private ?string $description,
|
||||
private TaskStatus $status,
|
||||
private ?DateTimeImmutable $dueOn,
|
||||
private ?EstimatedHours $estimatedHours,
|
||||
private array $assigneeUserIds,
|
||||
private int $createdBy,
|
||||
) {
|
||||
$this->assigneeUserIds = self::normaliseIds($assigneeUserIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $assigneeUserIds
|
||||
*
|
||||
* @throws TasksNotAllowedYet
|
||||
*/
|
||||
public static function create(
|
||||
int $jobId,
|
||||
JobStatus $jobStatus,
|
||||
int $workTypeId,
|
||||
TaskTitle $title,
|
||||
?string $description,
|
||||
TaskStatus $status,
|
||||
?DateTimeImmutable $dueOn,
|
||||
?EstimatedHours $estimatedHours,
|
||||
array $assigneeUserIds,
|
||||
int $createdBy,
|
||||
): self {
|
||||
if (! $jobStatus->allowsTasks()) {
|
||||
throw new TasksNotAllowedYet;
|
||||
}
|
||||
|
||||
return new self(null, $jobId, $workTypeId, $title, self::text($description), $status, $dueOn, $estimatedHours, $assigneeUserIds, $createdBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $assigneeUserIds
|
||||
*/
|
||||
public static function reconstitute(
|
||||
int $id,
|
||||
int $jobId,
|
||||
int $workTypeId,
|
||||
TaskTitle $title,
|
||||
?string $description,
|
||||
TaskStatus $status,
|
||||
?DateTimeImmutable $dueOn,
|
||||
?EstimatedHours $estimatedHours,
|
||||
array $assigneeUserIds,
|
||||
int $createdBy,
|
||||
): self {
|
||||
return new self($id, $jobId, $workTypeId, $title, $description, $status, $dueOn, $estimatedHours, $assigneeUserIds, $createdBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $assigneeUserIds
|
||||
*/
|
||||
public function changeDetails(
|
||||
int $workTypeId,
|
||||
TaskTitle $title,
|
||||
?string $description,
|
||||
TaskStatus $status,
|
||||
?DateTimeImmutable $dueOn,
|
||||
?EstimatedHours $estimatedHours,
|
||||
array $assigneeUserIds,
|
||||
): void {
|
||||
$this->workTypeId = $workTypeId;
|
||||
$this->title = $title;
|
||||
$this->description = self::text($description);
|
||||
$this->status = $status;
|
||||
$this->dueOn = $dueOn;
|
||||
$this->estimatedHours = $estimatedHours;
|
||||
$this->assigneeUserIds = self::normaliseIds($assigneeUserIds);
|
||||
}
|
||||
|
||||
public function changeStatus(TaskStatus $status): void
|
||||
{
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
public function id(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function jobId(): int
|
||||
{
|
||||
return $this->jobId;
|
||||
}
|
||||
|
||||
public function workTypeId(): int
|
||||
{
|
||||
return $this->workTypeId;
|
||||
}
|
||||
|
||||
public function title(): TaskTitle
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function description(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function status(): TaskStatus
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
public function dueOn(): ?DateTimeImmutable
|
||||
{
|
||||
return $this->dueOn;
|
||||
}
|
||||
|
||||
public function estimatedHours(): ?EstimatedHours
|
||||
{
|
||||
return $this->estimatedHours;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<int>
|
||||
*/
|
||||
public function assigneeUserIds(): array
|
||||
{
|
||||
return $this->assigneeUserIds;
|
||||
}
|
||||
|
||||
public function createdBy(): int
|
||||
{
|
||||
return $this->createdBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $ids
|
||||
* @return list<int>
|
||||
*/
|
||||
private static function normaliseIds(array $ids): array
|
||||
{
|
||||
$ids = array_values(array_unique($ids));
|
||||
sort($ids);
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
private static function text(?string $value): ?string
|
||||
{
|
||||
$value = $value === null ? '' : trim($value);
|
||||
|
||||
return $value === '' ? null : $value;
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,14 @@ enum JobStatus: string
|
||||
return $this === self::Invoiced || $this === self::Billed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tasks can be added from a quote request on (K36), not to an archived job.
|
||||
*/
|
||||
public function allowsTasks(): bool
|
||||
{
|
||||
return ! in_array($this, [self::Prospect, self::Tentative, self::Archived], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Kanban columns: every status except archived.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Domain\Enums;
|
||||
|
||||
/**
|
||||
* Status of a task (spec 8.2). Per-service-unit columns come in phase 3.
|
||||
*/
|
||||
enum TaskStatus: string
|
||||
{
|
||||
case Waiting = 'waiting';
|
||||
case InProgress = 'in_progress';
|
||||
case InReview = 'in_review';
|
||||
case Done = 'done';
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Domain\Exceptions;
|
||||
|
||||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||
|
||||
/**
|
||||
* The chosen work type or assignee does not fit the task's job.
|
||||
*/
|
||||
final class InvalidTaskReference extends DomainException
|
||||
{
|
||||
public function __construct(public readonly string $field)
|
||||
{
|
||||
parent::__construct("The task's {$field} is not a valid choice.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Domain\Exceptions;
|
||||
|
||||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||
|
||||
final class InvalidTaskTitle extends DomainException
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('The task name must be 1–255 characters.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Domain\Exceptions;
|
||||
|
||||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||
|
||||
/**
|
||||
* The task does not exist or belongs to another job.
|
||||
*/
|
||||
final class TaskNotFound extends DomainException
|
||||
{
|
||||
public function __construct(public readonly int $jobId, public readonly int $taskId)
|
||||
{
|
||||
parent::__construct("Task {$taskId} of job {$jobId} was not found.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Domain\Exceptions;
|
||||
|
||||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||
|
||||
final class TasksNotAllowedYet extends DomainException
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('Tasks can be added once the job is a quote request or later, and not to an archived job.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Domain\ValueObjects;
|
||||
|
||||
use App\Modules\Jobs\Domain\Exceptions\InvalidTaskTitle;
|
||||
|
||||
final readonly class TaskTitle
|
||||
{
|
||||
public const int MAX_LENGTH = 255;
|
||||
|
||||
public string $value;
|
||||
|
||||
public function __construct(string $value)
|
||||
{
|
||||
$value = trim(preg_replace('/\s+/u', ' ', $value) ?? $value);
|
||||
|
||||
if ($value === '' || mb_strlen($value) > self::MAX_LENGTH) {
|
||||
throw new InvalidTaskTitle;
|
||||
}
|
||||
|
||||
$this->value = $value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user