diff --git a/README.md b/README.md index c3c6716..b9fbc32 100644 --- a/README.md +++ b/README.md @@ -214,6 +214,9 @@ The `ticket` model came with handy methods to use, to make your building process | `isLocked` |`void` | check if the ticket is locked | `$ticket->isLocked()` | ✗ | `isUnlocked` |`void` | check if the ticket is unlocked | `$ticket->isUnlocked()` | ✗ | `assignTo` |`void` | assign ticket to a user | `$ticket->assignTo($user)` or `$ticket->assignTo(2)` | ✓ +| `makePriorityAsLow` |`void` | make ticket priority as low | `$ticket->makePriorityAsLow()` | ✓ +| `makePriorityAsNormal`|`void`| make ticket priority as normal | `$ticket->makePriorityAsNormal()` | ✓ +| `makePriorityAsHigh` |`void` | make ticket priority as high | `$ticket->makePriorityAsHigh()` | ✓ The __Chainable__ column, is showing the state for the method, that if it can be chained or not, something like ```php @@ -244,6 +247,8 @@ The `ticket` model has also a list of scopes to begin filter with. |---|---|---|---| | `closed` |`void` | get the closed tickets | `Ticket::closed()->get()` | | `opened` |`void` | get the opened tickets | `Ticket::opened()->get()` | +| `archived` |`void` | get the archived tickets | `Ticket::archived()->get()` | +| `unArchived` |`void` | get the unArchived tickets | `Ticket::unArchived()->get()` | | `resolved` |`void` | get the resolved tickets | `Ticket::resolved()->get()` | | `locked` |`void` | get the locked tickets | `Ticket::locked()->get()` | | `unlocked` |`void` | get the unlocked tickets | `Ticket::unlocked()->get()` | diff --git a/src/Concerns/InteractsWithTickets.php b/src/Concerns/InteractsWithTickets.php index b4bc6c8..8f25bf7 100644 --- a/src/Concerns/InteractsWithTickets.php +++ b/src/Concerns/InteractsWithTickets.php @@ -4,6 +4,7 @@ use Coderflex\LaravelTicket\Enums\Status; use Illuminate\Database\Eloquent\Model; +use Coderflex\LaravelTicket\Enums\Priority; trait InteractsWithTickets { @@ -195,4 +196,31 @@ public function assignTo(Model|int $user): self return $this; } + + /** + * make ticket priority as low + */ + public function makePriorityAsLow(): self + { + $this->update(['priority' => Priority::LOW->value]); + return $this; + } + + /** + * make ticket priority as normal + */ + public function makePriorityAsNormal(): self + { + $this->update(['priority' => Priority::NORMAL->value]); + return $this; + } + + /** + * make ticket priority as high + */ + public function makePriorityAsHigh(): self + { + $this->update(['priority' => Priority::HIGH->value]); + return $this; + } } diff --git a/src/Scopes/TicketScope.php b/src/Scopes/TicketScope.php index ce61a36..2db28b1 100644 --- a/src/Scopes/TicketScope.php +++ b/src/Scopes/TicketScope.php @@ -87,4 +87,20 @@ public function scopeWithHighPriority(Builder $builder): Builder { return $builder->where('priority', Priority::HIGH->value); } + + /** + * Get archived tickets + */ + public function scopeArchived(Builder $builder): Builder + { + return $builder->where('status', Status::ARCHIVED->value); + } + + /** + * Get unarchived tickets + */ + public function scopeUnArchived(Builder $builder): Builder + { + return $builder->whereNot('status', Status::ARCHIVED->value); + } } diff --git a/tests/Feature/TicketTest.php b/tests/Feature/TicketTest.php index 75e04fa..3b1e71c 100644 --- a/tests/Feature/TicketTest.php +++ b/tests/Feature/TicketTest.php @@ -16,9 +16,17 @@ 'status' => 'closed', ]); - $this->assertEquals(Ticket::count(), 10); + Ticket::factory() + ->times(6) + ->create([ + 'status' => 'archived', + ]); + + $this->assertEquals(Ticket::count(), 16); $this->assertEquals(Ticket::opened()->count(), 3); $this->assertEquals(Ticket::closed()->count(), 7); + $this->assertEquals(Ticket::archived()->count(), 6); + $this->assertEquals(Ticket::unArchived()->count(), 10); }); it('filters tickets by resolved status', function () { @@ -271,3 +279,33 @@ expect($ticket->assigned_to) ->toBe($agentUser->id); }); + +it('can mark a ticket priority as low', function () { + $ticket = Ticket::factory()->create([ + 'priority' => 'high', + ]); + + $ticket->makePriorityAsLow(); + + $this->assertEquals($ticket->priority, 'low'); +}); + +it('can mark a ticket priority as normal', function () { + $ticket = Ticket::factory()->create([ + 'priority' => 'high', + ]); + + $ticket->makePriorityAsNormal(); + + $this->assertEquals($ticket->priority, 'normal'); +}); + +it('can mark a ticket priority as high', function () { + $ticket = Ticket::factory()->create([ + 'priority' => 'low', + ]); + + $ticket->makePriorityAsHigh(); + + $this->assertEquals($ticket->priority, 'high'); +});