phases one of time logged
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Helpdesk\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Modules\Helpdesk\Models\Ticket;
|
||||
|
||||
final class TicketTimeLogController extends Controller
|
||||
{
|
||||
/**
|
||||
* Store a time entry against the selected helpdesk ticket.
|
||||
*/
|
||||
public function store(Request $request, Ticket $ticket): RedirectResponse
|
||||
{
|
||||
$this->authorize('update', $ticket);
|
||||
|
||||
$validated = $request->validate([
|
||||
'minutes' => ['required', 'integer', 'min:1', 'max:1440'],
|
||||
'description' => ['nullable', 'string', 'max:1000'],
|
||||
]);
|
||||
|
||||
$ticket->timeLogs()->create([
|
||||
'user_id' => $request->user()?->id,
|
||||
'minutes' => (int) $validated['minutes'],
|
||||
'description' => $validated['description'] ?? null,
|
||||
'logged_at' => now(),
|
||||
]);
|
||||
|
||||
return back()->with('ticket-action-updated', 'Time logged successfully.');
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Helpdesk\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
final class TimeLog extends Model
|
||||
{
|
||||
protected $table = 'helpdesk_time_logs';
|
||||
|
||||
/** @var list<string> */
|
||||
protected $fillable = [
|
||||
'ticket_id',
|
||||
'user_id',
|
||||
'minutes',
|
||||
'description',
|
||||
'logged_at',
|
||||
];
|
||||
|
||||
/** @var array<string, string> */
|
||||
protected $casts = [
|
||||
'minutes' => 'integer',
|
||||
'logged_at' => 'datetime',
|
||||
];
|
||||
|
||||
/** @return BelongsTo<Ticket, TimeLog> */
|
||||
public function ticket(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Ticket::class, 'ticket_id');
|
||||
}
|
||||
|
||||
/** @return BelongsTo<User, TimeLog> */
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Helpdesk\Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Modules\Helpdesk\Models\Ticket;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class TicketTimeLogTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* It stores a time log for an authorized ticket user.
|
||||
*/
|
||||
public function test_authorized_user_can_log_ticket_time(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$ticket = Ticket::factory()->create();
|
||||
|
||||
$this->actingAs($user)
|
||||
->post(route('helpdesk.tickets.time-logs.store', $ticket), [
|
||||
'minutes' => 45,
|
||||
'description' => 'Investigated the issue and updated the ticket.',
|
||||
])
|
||||
->assertRedirect();
|
||||
|
||||
$this->assertDatabaseHas('helpdesk_time_logs', [
|
||||
'ticket_id' => $ticket->id,
|
||||
'user_id' => $user->id,
|
||||
'minutes' => 45,
|
||||
'description' => 'Investigated the issue and updated the ticket.',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* It rejects invalid logged minutes.
|
||||
*/
|
||||
public function test_ticket_time_log_requires_valid_minutes(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$ticket = Ticket::factory()->create();
|
||||
|
||||
$this->actingAs($user)
|
||||
->from(route('helpdesk.tickets.show', $ticket))
|
||||
->post(route('helpdesk.tickets.time-logs.store', $ticket), [
|
||||
'minutes' => 0,
|
||||
])
|
||||
->assertRedirect(route('helpdesk.tickets.show', $ticket))
|
||||
->assertSessionHasErrors('minutes');
|
||||
}
|
||||
}
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
if (Schema::hasTable('helpdesk_time_logs')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::create('helpdesk_time_logs', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('ticket_id')->constrained('helpdesk_tickets')->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
|
||||
$table->unsignedInteger('minutes');
|
||||
$table->text('description')->nullable();
|
||||
$table->timestamp('logged_at')->useCurrent();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['ticket_id', 'logged_at']);
|
||||
$table->index(['user_id', 'logged_at']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('helpdesk_time_logs');
|
||||
}
|
||||
};
|
||||
@@ -1,42 +0,0 @@
|
||||
<form method="POST" action="{{ route('helpdesk.tickets.time-logs.store', $ticket) }}" class="mb-4 space-y-2">
|
||||
@csrf
|
||||
|
||||
<label class="block text-xs font-bold text-zinc-700 dark:text-zinc-200" for="time_minutes">
|
||||
Log time
|
||||
</label>
|
||||
|
||||
<div class="grid grid-cols-[1fr_auto] gap-2">
|
||||
<input
|
||||
id="time_minutes"
|
||||
name="minutes"
|
||||
type="number"
|
||||
min="1"
|
||||
max="1440"
|
||||
value="{{ old('minutes') }}"
|
||||
placeholder="Minutes"
|
||||
class="block w-full rounded-lg border border-zinc-300 bg-white p-2 text-xs font-semibold text-zinc-900 shadow-sm focus:border-emerald-500 focus:ring-emerald-500 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100"
|
||||
data-dusk="ticket-time-minutes"
|
||||
>
|
||||
|
||||
<button type="submit" dusk="log-ticket-time" data-dusk="log-ticket-time" class="inline-flex items-center justify-center rounded-lg bg-emerald-600 px-3 py-2 text-xs font-black text-white shadow-sm transition hover:bg-emerald-700 focus:outline-none focus:ring-2 focus:ring-emerald-400/70">
|
||||
<i class="fa-solid fa-clock mr-2" aria-hidden="true"></i>
|
||||
<span>Log</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<textarea
|
||||
name="description"
|
||||
rows="2"
|
||||
placeholder="Optional work note"
|
||||
class="block w-full rounded-lg border border-zinc-300 bg-white p-2 text-xs font-semibold text-zinc-900 shadow-sm focus:border-emerald-500 focus:ring-emerald-500 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100"
|
||||
data-dusk="ticket-time-description"
|
||||
>{{ old('description') }}</textarea>
|
||||
|
||||
@error('minutes')
|
||||
<p class="text-xs font-bold text-red-600 dark:text-red-400">{{ $message }}</p>
|
||||
@enderror
|
||||
|
||||
@error('description')
|
||||
<p class="text-xs font-bold text-red-600 dark:text-red-400">{{ $message }}</p>
|
||||
@enderror
|
||||
</form>
|
||||
@@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Modules\Helpdesk\Http\Controllers\TicketTimeLogController;
|
||||
|
||||
Route::post('/tickets/{ticket}/time-logs', [TicketTimeLogController::class, 'store'])
|
||||
->name('tickets.time-logs.store');
|
||||
Reference in New Issue
Block a user