mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-05-07 20:32:26 +00:00
97 lines
3.6 KiB
PHP
97 lines
3.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\V1\TimeEntry;
|
|
|
|
use App\Http\Requests\V1\BaseFormRequest;
|
|
use App\Models\Member;
|
|
use App\Models\Organization;
|
|
use App\Models\Project;
|
|
use App\Models\Tag;
|
|
use App\Models\Task;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Korridor\LaravelModelValidationRules\Rules\ExistsEloquent;
|
|
|
|
/**
|
|
* @property Organization $organization Organization from model binding
|
|
*/
|
|
class TimeEntryUpdateRequest extends BaseFormRequest
|
|
{
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, array<string|ValidationRule>>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
// ID of the organization member that the time entry should belong to
|
|
'member_id' => [
|
|
'string',
|
|
ExistsEloquent::make(Member::class, null, function (Builder $builder): Builder {
|
|
/** @var Builder<Member> $builder */
|
|
return $builder->whereBelongsTo($this->organization, 'organization');
|
|
})->uuid(),
|
|
],
|
|
// ID of the project that the time entry should belong to
|
|
'project_id' => [
|
|
'nullable',
|
|
'string',
|
|
'required_with:task_id',
|
|
ExistsEloquent::make(Project::class, null, function (Builder $builder): Builder {
|
|
/** @var Builder<Project> $builder */
|
|
return $builder->whereBelongsTo($this->organization, 'organization');
|
|
})->uuid(),
|
|
],
|
|
// ID of the task that the time entry should belong to
|
|
'task_id' => [
|
|
'nullable',
|
|
'string',
|
|
ExistsEloquent::make(Task::class, null, function (Builder $builder): Builder {
|
|
/** @var Builder<Task> $builder */
|
|
return $builder->whereBelongsTo($this->organization, 'organization');
|
|
})->uuid(),
|
|
ExistsEloquent::make(Task::class, null, function (Builder $builder): Builder {
|
|
/** @var Builder<Task> $builder */
|
|
return $builder->whereBelongsTo($this->organization, 'organization')
|
|
->where('project_id', $this->input('project_id'));
|
|
})->uuid()->withMessage(__('validation.task_belongs_to_project')),
|
|
],
|
|
// Start of time entry (Format: "Y-m-d\TH:i:s\Z", UTC timezone, Example: "2000-02-22T14:58:59Z")
|
|
'start' => [
|
|
'date_format:Y-m-d\TH:i:s\Z',
|
|
],
|
|
// End of time entry (Format: "Y-m-d\TH:i:s\Z", UTC timezone, Example: "2000-02-22T14:58:59Z")
|
|
'end' => [
|
|
'nullable',
|
|
'date_format:Y-m-d\TH:i:s\Z',
|
|
'after_or_equal:start',
|
|
],
|
|
// Whether time entry is billable
|
|
'billable' => [
|
|
'boolean',
|
|
],
|
|
// Description of time entry
|
|
'description' => [
|
|
'nullable',
|
|
'string',
|
|
'max:500',
|
|
],
|
|
// List of tag IDs
|
|
'tags' => [
|
|
'nullable',
|
|
'array',
|
|
],
|
|
'tags.*' => [
|
|
'string',
|
|
ExistsEloquent::make(Tag::class, null, function (Builder $builder): Builder {
|
|
/** @var Builder<Tag> $builder */
|
|
return $builder->whereBelongsTo($this->organization, 'organization');
|
|
})->uuid(),
|
|
],
|
|
];
|
|
}
|
|
}
|