Merge remote-tracking branch 'origin/staging' into origin/production

This commit is contained in:
Linksehat Staging Server
2024-05-28 10:56:28 +07:00
51 changed files with 3643 additions and 377 deletions

View File

@@ -477,7 +477,7 @@ class Helper
public static function calculateAge($date_brith_day){
// Konversi tanggal lahir ke dalam format UNIX timestamp
$dob = strtotime($date_brith_day);
// Hitung umur berdasarkan tanggal lahir
$umur = date('Y') - date('Y', $dob);
@@ -498,5 +498,34 @@ class Helper
return $start->diffInDays($end) + 1;
}
public static function getStatusLivechat($status) {
switch ($status) {
case 1:
return 'Requested'; // Clearer status name
break;
case 2:
return 'Accepted';
break;
case 3:
return 'Declined';
break;
case 4:
return 'Waiting Payment';
break;
case 5:
return 'Payment Successful';
break;
case 6:
return 'Chat Ended';
break;
case 7:
return 'Payment Failed';
break;
default:
return 'Unknown Status'; // Handle unknown statuses
break;
}
}
}

View File

@@ -16,6 +16,7 @@ class Kernel extends HttpKernel
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\App\Http\Middleware\LinksehatOldAuthMiddleware::class,
\Illuminate\Http\Middleware\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,

View File

@@ -5,6 +5,8 @@ namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Models\OLDLMS\PersonalAccessToken;
use Laravel\Sanctum\Sanctum;
class LinksehatOldAuthMiddleware
{
@@ -17,12 +19,12 @@ class LinksehatOldAuthMiddleware
*/
public function handle(Request $request, Closure $next)
{
if ($request->header('authorization') == 'Bearer LpMbGm0NQvFC3lUBiy1Ch3NzS0CIPSmanR12FcdP') {
Auth::loginUsingId(1);
return $next($request);
}
// if ($request->header('authorization') == 'Bearer LpMbGm0NQvFC3lUBiy1Ch3NzS0CIPSmanR12FcdP') {
// Auth::loginUsingId(1);
return abort(401, "Unauthenticated");
// return $next($request);
// }
Sanctum::usePersonalAccessTokenModel(PersonalAccessToken::class);
return $next($request);
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Models\OLDLMS;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class NotificationToken extends Model
{
use HasFactory;
protected $connection = 'oldlms';
protected $fillable = [
'origin',
'type',
'token',
'status',
'device_id'
];
protected $hidden = [
'notifiabletoken_type',
'notifiabletoken_id',
'created_at',
'updated_at'
];
public function notifiabletoken()
{
return $this->morphTo();
}
}

View File

@@ -1,7 +1,6 @@
<?php
namespace App\Models\OLDLMS;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
@@ -15,7 +14,7 @@ use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use HasFactory, SoftDeletes, HasApiTokens, HasRoles, Notifiable, Notifiable;
use HasFactory, SoftDeletes, HasApiTokens, HasRoles, Notifiable;
const CREATED_AT = 'dCreateOn';
const UPDATED_AT = 'dUpdateOn';
@@ -39,6 +38,7 @@ class User extends Authenticatable
'nIDHubunganKeluarga',
'dUpdateOn',
'sIPAddress',
'fcm_token',
];
protected function fullName(): Attribute
@@ -62,7 +62,7 @@ class User extends Authenticatable
{
return $this->hasOne(UserDetail::class, 'nIDUser', 'nID');
}
public function insurances()
{
return $this->hasMany(UserInsurance::class, 'nIDUser', 'nID');
@@ -72,4 +72,9 @@ class User extends Authenticatable
{
return $this->morphMany(NotificationToken::class, 'notifiabletoken');
}
public function routeNotificationForFcm()
{
return $this->notificationTokens()->pluck('token')->toArray();
}
}

View File

@@ -86,7 +86,7 @@ class User extends Authenticatable
{
return $this->belongsToMany(Corporate::class, 'corporate_manager', 'user_id', 'corporate_id');
}
public function metas()
{
return $this->morphMany(Meta::class, 'metaable');
@@ -102,13 +102,18 @@ class User extends Authenticatable
return $this->hasMany(Person::class, 'owner_user_id');
}
public function getOrganization()
{
return $this->hasOne(OrganizationUser::class, 'user_id');
}
public function notificationTokens()
{
return $this->morphMany(NotificationToken::class, 'notifiabletoken');
}
public function getOrganization()
public function routeNotificationForFcm()
{
return $this->hasOne(OrganizationUser::class, 'user_id');
return $this->notificationTokens()->pluck('token')->toArray();
}
}

View File

@@ -0,0 +1,90 @@
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Kreait\Firebase\Messaging\CloudMessage;
use Kreait\Laravel\Firebase\Facades\Firebase;
use NotificationChannels\Fcm\FcmChannel;
use NotificationChannels\Fcm\FcmMessage;;
use NotificationChannels\Fcm\Resources\AndroidConfig;
use NotificationChannels\Fcm\Resources\AndroidFcmOptions;
use NotificationChannels\Fcm\Resources\AndroidNotification;
use NotificationChannels\Fcm\Resources\ApnsConfig;
use NotificationChannels\Fcm\Resources\ApnsFcmOptions;
use NotificationChannels\Fcm\Resources\Notification as FcmNotification;
class SendNotification extends Notification
{
use Queueable;
private $title;
private $body;
private $data;
public function __construct($title, $body, $data)
{
$this->title = $title;
$this->body = $body;
$this->data = is_array($data) ? $data : (array) $data; // Pastikan data adalah array
}
public function via($notifiable)
{
return [FcmChannel::class];
}
// public function toFcm($notifiable)
// {
// return FcmMessage::create()
// ->setData($this->data)
// ->setNotification([
// 'title' => $this->title,
// 'body' => $this->body,
// ]);
// }
public function toFcm($notifiable)
{
$deviceTokens = $notifiable->routeNotificationFor('fcm');
$notification = [
'title' => $this->title,
'body' => $this->body,
];
if (count($deviceTokens)){
foreach($deviceTokens as $token) {
$message = CloudMessage::withTarget('token', $token)
->withNotification($notification) // optional
->withData($this->data);
Firebase::messaging()->send($message);
}
}
$dataFcm = FcmMessage::create()
->setToken($deviceTokens[0])
->setData([])
->setNotification(
FcmNotification::create()
->setTitle('ini title')
->setBody('ini body')
)
->setAndroid(
AndroidConfig::create()
->setFcmOptions(AndroidFcmOptions::create()->setAnalyticsLabel('analytics'))
->setNotification(AndroidNotification::create()->setColor('#0A0A0A'))
)->setApns(
ApnsConfig::create()
->setFcmOptions(ApnsFcmOptions::create()->setAnalyticsLabel('analytics_ios'))
);
return $dataFcm;
}
public function fcmProject($notifiable, $message){
return 'app';
}
}

View File

@@ -206,7 +206,7 @@ class AppServiceProvider extends ServiceProvider
$this->logAuditTrail($model, 'deleted');
});
Sanctum::usePersonalAccessTokenModel(PersonalAccessToken::class);
// Sanctum::usePersonalAccessTokenModel(PersonalAccessToken::class);
}
private function logAuditTrail($model, $action)