Merge branch 'staging' of https://dev.sismedika.online/febio/aso into staging

This commit is contained in:
Linksehat Staging Server
2024-05-24 09:13:36 +07:00
9 changed files with 252 additions and 23 deletions

View File

@@ -266,6 +266,10 @@ class AuthController extends Controller
$token = $request->token; $token = $request->token;
$status = $request->status; $status = $request->status;
$user->fcm_token = $request->token;
$user->save();
// $userUpdate = User::where
$user->notificationTokens()->updateOrCreate([ $user->notificationTokens()->updateOrCreate([
'device_id' => $device_id, 'device_id' => $device_id,
], [ ], [

View File

@@ -3,6 +3,7 @@
namespace Modules\Linksehat\Http\Controllers\Api\Doctor; namespace Modules\Linksehat\Http\Controllers\Api\Doctor;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Notifications\SendNotification;
use App\Models\User; use App\Models\User;
use App\Models\OLDLMS\User as UserLMS; use App\Models\OLDLMS\User as UserLMS;
use App\Models\Livechat; use App\Models\Livechat;
@@ -132,6 +133,34 @@ class ChatDoctorController extends Controller
$livechat->status = 3; // Decline $livechat->status = 3; // Decline
// Menyimpan perubahan ke database // Menyimpan perubahan ke database
$livechat->save(); $livechat->save();
// Send Notification
$doctorId = $livechat->doctor_id;
$title = 'Decline Livechat';
$body = 'Decline Livechat';
$channel = Channel::where([
'member_id' => $livechat->patient_id,
'doctor_id' => $livechat->doctor_id
])->first();
$dataNotif = [
'channel_id' => $channel->id,
'livechat_id' => $livechat->id,
'type' => 'decline-chat'
];
$user = UserLMS::where('nID',$livechat->patient_id)->first();
if ($user) {
$user->notify(new SendNotification($title, $body, $dataNotif));
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
} else {
return Helper::responseJson(
status: 'Not Found',
statusCode: 404,
message: 'Doctor not found.'
);
}
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200); return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
} else { } else {
return response()->json(['message' => 'Livechat not found'], 404); return response()->json(['message' => 'Livechat not found'], 404);
@@ -147,7 +176,34 @@ class ChatDoctorController extends Controller
$livechat->accept_date = date('Y-m-d H:i:s'); // Accept $livechat->accept_date = date('Y-m-d H:i:s'); // Accept
// Menyimpan perubahan ke database // Menyimpan perubahan ke database
$livechat->save(); $livechat->save();
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
// Send Notification
$doctorId = $livechat->doctor_id;
$title = 'Approve Request Livechat';
$body = 'Approve Livechat';
$channel = Channel::where([
'member_id' => $livechat->patient_id,
'doctor_id' => $livechat->doctor_id
])->first();
$dataNotif = [
'channel_id' => $channel->id,
'livechat_id' => $livechat->id,
'type' => 'approve-chat'
];
$user = UserLMS::where('nID',$livechat->patient_id)->first();
if ($user) {
$user->notify(new SendNotification($title, $body, $dataNotif));
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
} else {
return Helper::responseJson(
status: 'Not Found',
statusCode: 404,
message: 'Doctor not found.'
);
}
} else { } else {
return response()->json(['message' => 'Livechat not found'], 404); return response()->json(['message' => 'Livechat not found'], 404);
} }
@@ -159,10 +215,36 @@ class ChatDoctorController extends Controller
if ($livechat) { if ($livechat) {
// Memperbarui atribut model // Memperbarui atribut model
$livechat->status = 6; // End Chat $livechat->status = 6; // End Chat
$livechat->end_date = date('Y-m-d H:i:s'); // Accept $livechat->end_date = date('Y-m-d H:i:s'); // Endchat
// Menyimpan perubahan ke database // Menyimpan perubahan ke database
$livechat->save(); $livechat->save();
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
// Send Notification
$doctorId = $livechat->doctor_id;
$title = 'End Livechat';
$body = 'End Livechat';
$channel = Channel::where([
'member_id' => $livechat->patient_id,
'doctor_id' => $livechat->doctor_id
])->first();
$dataNotif = [
'channel_id' => $channel->id,
'livechat_id' => $livechat->id,
'type' => 'end-chat'
];
$user = UserLMS::where('nID',$livechat->patient_id)->first();
if ($user) {
$user->notify(new SendNotification($title, $body, $dataNotif));
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
} else {
return Helper::responseJson(
status: 'Not Found',
statusCode: 404,
message: 'Doctor not found.'
);
}
} else { } else {
return response()->json(['message' => 'Livechat not found'], 404); return response()->json(['message' => 'Livechat not found'], 404);
} }

View File

@@ -3,11 +3,14 @@
namespace Modules\Linksehat\Http\Controllers\Api; namespace Modules\Linksehat\Http\Controllers\Api;
use App\Helpers\Helper; use App\Helpers\Helper;
use App\Notifications\SendNotification;
use App\Models\Organization; use App\Models\Organization;
use App\Models\Speciality; use App\Models\Speciality;
use App\Models\Livechat; use App\Models\Livechat;
use App\Models\Channel; use App\Models\Channel;
use App\Models\UserChannel; use App\Models\UserChannel;
use App\Models\User as UserAso;
use App\Models\OLDLMS\User;
use Illuminate\Contracts\Support\Renderable; use Illuminate\Contracts\Support\Renderable;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@@ -285,7 +288,7 @@ class DuitkuController extends Controller
'created_at' => date('Y-m-d H:i:s') 'created_at' => date('Y-m-d H:i:s')
]); ]);
if ($notif->resultCode == "00") { if ($notif->resultCode == "00") { // berhasil melakukan pembayaran
// Action Success // Action Success
$livechat = Livechat::where('uuid', $notif->merchantOrderId)->first(); $livechat = Livechat::where('uuid', $notif->merchantOrderId)->first();
// Update status pembayaran // Update status pembayaran
@@ -329,6 +332,23 @@ class DuitkuController extends Controller
] ]
); );
// Send Notification
$doctorId = $livechat->doctor_id;
$userDokter = UserAso::find($doctorId);
$title = 'Payment Succes Livechat';
$patient = User::where('nID', $livechat->patient_id)->first();
$body = 'Payment Succes Livechat from ' . $patient->sFirstName . ' ' . $patient->sLastName;
$channel = Channel::where([
'member_id' => $livechat->patient_id,
'doctor_id' => $livechat->doctor_id
])->first();
$dataNotif = [
'channel_id' => $channel->id,
'livechat_id' => $livechat->id,
'type' => 'success-payment'
];
$userDokter->notify(new SendNotification($title, $body, $dataNotif));
// Berikan respons yang sesuai ke klien // Berikan respons yang sesuai ke klien
return response()->json(['message' => 'Channel created successfully', 'channel' => $channel]); return response()->json(['message' => 'Channel created successfully', 'channel' => $channel]);
@@ -340,6 +360,22 @@ class DuitkuController extends Controller
$livechat->status = 7; // failed payment $livechat->status = 7; // failed payment
$livechat->save(); $livechat->save();
// Send Notification
$doctorId = $livechat->doctor_id;
$userDokter = UserAso::find($doctorId);
$title = 'Payment Failed Livechat';
$patient = User::where('nID', $livechat->patient_id)->first();
$body = 'Payment Failed Livechat from ' . $patient->sFirstName . ' ' . $patient->sLastName;
$channel = Channel::where([
'member_id' => $livechat->patient_id,
'doctor_id' => $livechat->doctor_id
])->first();
$dataNotif = [
'channel_id' => $channel->id,
'livechat_id' => $livechat->id,
'type' => 'failed-payment'
];
$userDokter->notify(new SendNotification($title, $body, $dataNotif));
return response()->json(['message' => 'User Gagal melakukan pembayaran']); return response()->json(['message' => 'User Gagal melakukan pembayaran']);
} }

View File

@@ -2,6 +2,7 @@
namespace Modules\Linksehat\Http\Controllers\Api; namespace Modules\Linksehat\Http\Controllers\Api;
use App\Notifications\SendNotification;
use App\Helpers\Helper; use App\Helpers\Helper;
use App\Helpers\DuitkuHelper; use App\Helpers\DuitkuHelper;
use App\Services\Duitku; use App\Services\Duitku;
@@ -9,8 +10,10 @@ use App\Models\Organization;
use App\Models\PractitionerRole; use App\Models\PractitionerRole;
use App\Models\Invoice; use App\Models\Invoice;
use App\Models\PaymentsMethods; use App\Models\PaymentsMethods;
use App\Models\Channel;
use App\Models\Livechat; use App\Models\Livechat;
use App\Models\OLDLMS\User; use App\Models\OLDLMS\User;
use App\Models\User as UserAso;
use Illuminate\Routing\Controller; use Illuminate\Routing\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
@@ -133,11 +136,11 @@ class LivechatController extends Controller
'descriptions' => 'required', 'descriptions' => 'required',
], [ ], [
'doctor_id.required' => 'ID Dokter harus diisi', 'doctor_id.required' => 'ID Dokter harus diisi',
'patient_id.required' => 'ID Dokter harus diisi', 'patient_id.required' => 'ID Pasien harus diisi',
'descriptions.required' => 'Description harus diisi', 'descriptions.required' => 'Deskripsi harus diisi',
]); ]);
if ($validator->fails()){ if ($validator->fails()) {
return Helper::responseJson( return Helper::responseJson(
status: 'Bad Request', status: 'Bad Request',
statusCode: 400, statusCode: 400,
@@ -148,24 +151,49 @@ class LivechatController extends Controller
/** /**
* Status Livechat * Status Livechat
* 1=Request, 2=Accept, 3=Decline, 4=Waiting Payment, 5=Success Payment, 6 = End Chat * 1=Request, 2=Accept, 3=Decline, 4=Waiting Payment, 5=Success Payment, 6 = End Chat, 7=Payment Failed
*/ */
$timezone = date_default_timezone_get(); $timezone = date_default_timezone_get();
$data['request_date'] = date('Y-m-d H:i:s'); $data['request_date'] = date('Y-m-d H:i:s');
$data['timezone'] = $timezone; $data['timezone'] = $timezone;
$data['uuid'] = (string) Str::orderedUuid(); $data['uuid'] = (string) Str::orderedUuid();
$data['status'] = 1; $data['status'] = 1; // Request
$livechat = Livechat::create($data); $livechat = Livechat::create($data);
$doctor = $livechat->doctor; $doctor = $livechat->doctor;
$data = [ $responseData = [
'id' => $livechat->id, 'id' => $livechat->id,
'request_date' => $livechat->request_date, 'request_date' => $livechat->request_date,
'image_path' =>'https' 'image_path' => 'https' // Ganti dengan path yang benar jika ada
]; ];
// Send Notification
$doctorId = $livechat->doctor_id;
$user = UserAso::find($doctorId);
$title = 'New Request Livechat';
$patient = User::where('nID', $livechat->patient_id)->first();
$body = 'Request Livechat from ' . $patient->sFirstName . ' ' . $patient->sLastName;
$channel = Channel::where([
'member_id' => $livechat->patient_id,
'doctor_id' => $livechat->doctor_id
])->first();
$dataNotif = [
'channel_id' => $channel->id,
'livechat_id' => $livechat->id,
'type' => 'request-chat'
];
return Helper::responseJson(data: $data); if ($user) {
$user->notify(new SendNotification($title, $body, $dataNotif));
return Helper::responseJson(data: $responseData);
} else {
return Helper::responseJson(
status: 'Not Found',
statusCode: 404,
message: 'Doctor not found.'
);
}
} }
} }
@@ -290,7 +318,6 @@ class LivechatController extends Controller
// Membuat invoice menggunakan DuitkuHelper // Membuat invoice menggunakan DuitkuHelper
$duitku = DuitkuHelper::createInvoice($data); $duitku = DuitkuHelper::createInvoice($data);
return response()->json(['success' => true, 'data' => $duitku], 200); return response()->json(['success' => true, 'data' => $duitku], 200);
} catch (Exception $e) { } catch (Exception $e) {
// Menangkap error dan mengembalikan respon error // Menangkap error dan mengembalikan respon error

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace App\Models; namespace App\Models\OLDLMS;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
@@ -9,11 +9,14 @@ class NotificationToken extends Model
{ {
use HasFactory; use HasFactory;
protected $connection = 'oldlms';
protected $fillable = [ protected $fillable = [
'origin', 'origin',
'type', 'type',
'token', 'token',
'status', 'status',
'device_id'
]; ];
protected $hidden = [ protected $hidden = [

View File

@@ -1,8 +1,6 @@
<?php <?php
namespace App\Models\OLDLMS; namespace App\Models\OLDLMS;
use App\Models\NotificationToken;
use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Foundation\Auth\User as Authenticatable;
@@ -16,7 +14,7 @@ use Illuminate\Notifications\Notifiable;
class User extends Authenticatable class User extends Authenticatable
{ {
use HasFactory, SoftDeletes, HasApiTokens, HasRoles, Notifiable, Notifiable; use HasFactory, SoftDeletes, HasApiTokens, HasRoles, Notifiable;
const CREATED_AT = 'dCreateOn'; const CREATED_AT = 'dCreateOn';
const UPDATED_AT = 'dUpdateOn'; const UPDATED_AT = 'dUpdateOn';
@@ -40,6 +38,7 @@ class User extends Authenticatable
'nIDHubunganKeluarga', 'nIDHubunganKeluarga',
'dUpdateOn', 'dUpdateOn',
'sIPAddress', 'sIPAddress',
'fcm_token',
]; ];
protected function fullName(): Attribute protected function fullName(): Attribute
@@ -73,4 +72,6 @@ class User extends Authenticatable
{ {
return $this->morphMany(NotificationToken::class, 'notifiabletoken'); return $this->morphMany(NotificationToken::class, 'notifiabletoken');
} }
} }

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use NotificationChannels\Fcm\FcmChannel;
use NotificationChannels\Fcm\FcmMessage;
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 = $data;
}
public function via($notifiable)
{
return [FcmChannel::class];
}
public function toFcm($notifiable)
{
return FcmMessage::create()
->setData($this->data) // Menggunakan $this->data
->setNotification([
'title' => $this->title,
'body' => $this->body,
]);
}
}

5
config/fcm.php Normal file
View File

@@ -0,0 +1,5 @@
<?php
return [
'server_key' => env('FCM_SERVER_KEY'),
];

View File

@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('fcm_token')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('fcm_token');
});
}
};