Skip to content

Commit

Permalink
working notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Temuulen Bayanmunkh authored and Temuulen Bayanmunkh committed Oct 20, 2023
1 parent eb9773b commit 56daee0
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 15 deletions.
15 changes: 15 additions & 0 deletions src/Http/Controllers/Internal/v1/NotificationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Fleetbase\Http\Controllers\Internal\v1;

use Fleetbase\Http\Controllers\FleetbaseController;

class NotificationController extends FleetbaseController
{
/**
* The resource to query.
*
* @var string
*/
public $resource = 'notification';
}
26 changes: 26 additions & 0 deletions src/Http/Filter/NotificationFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Fleetbase\Http\Filter;

class NotificationFilter extends Filter
{
public function queryForInternal()
{
$this->builder->where(function ($q) {
$q->where('notifiable_id', $this->session->get('company'));
$q->orWhere('notifiable_id', $this->session->get('user'));
});
}

public function query(?string $query)
{
$this->builder->search($query);
}

public function unread(?bool $unread)
{
if ($unread) {
$this->builder->whereNull('read_at');
}
}
}
6 changes: 3 additions & 3 deletions src/Models/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

namespace Fleetbase\Models;

use Fleetbase\Traits\Filterable;
use Fleetbase\Traits\HasApiModelBehavior;
use Fleetbase\Traits\Searchable;
use Illuminate\Notifications\DatabaseNotification;

class Notification extends DatabaseNotification
{
use HasApiModelBehavior;
use Searchable;
use HasApiModelBehavior, Searchable, Filterable;

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['read_at', 'data'];
protected $fillable = ['read_at', 'data', 'notifiable_id', 'notifiable_type', 'type'];

/**
* The searchable columns.
Expand Down
21 changes: 9 additions & 12 deletions src/Notifications/UserCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,15 @@ public function toBroadcast($notifiable)
public function toArray($notifiable)
{
return [
'id' => $this->notificationId,
'created_at' => $this->sentAt,
'notifiable' => $notifiable->{$notifiable->getKeyName()},
'data' => [
'subject' => '🥳 New Fleetbase Signup!',
'message' => 'New user ' . $this->user->name . ' added to organization ' . $this->company->name,
'id' => $this->user->uuid,
'email' => $this->user->email,
'phone' => $this->user->phone,
'companyId' => $this->company->uuid,
'company' => $this->company->name,
],
'notification_id' => $this->notificationId,
'sent_at' => $this->sentAt,
'subject' => '🥳 New Fleetbase Signup!',
'message' => 'New user ' . $this->user->name . ' added to organization ' . $this->company->name,
'id' => $this->user->uuid,
'email' => $this->user->email,
'phone' => $this->user->phone,
'companyId' => $this->company->uuid,
'company' => $this->company->name,
];
}
}
1 change: 1 addition & 0 deletions src/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ function ($router, $controller) {
}
);
$router->fleetbaseRoutes('transactions');
$router->fleetbaseRoutes('notifications');
}
);
}
Expand Down

0 comments on commit 56daee0

Please sign in to comment.