bugs fix livechat

This commit is contained in:
Linksehat Staging Server
2024-06-03 09:07:12 +07:00
parent 6fb7034e2e
commit 6ce4282a3b
7 changed files with 110 additions and 77 deletions

View File

@@ -67,7 +67,8 @@ class AuthDoctorController extends Controller
$res_data = [
// 'user' => $user,
'token' => $user->createToken('app')->plainTextToken
'token' => $user->createToken('app')->plainTextToken,
'id' => $user->person->id
];
return ApiResponse::apiResponse("Success", $res_data, trans('Message.success'), 200);

View File

@@ -47,6 +47,7 @@ class ChatDoctorController extends Controller
if($chat) {
foreach($chat as $c){
$patient = UserLMS::where('nID',$c->patient_id)->with('detail')->first();
$channel = Channel::where(['doctor_id'=> $c->doctor_id, 'member_id' => $c->patient_id])->first();
if ( $patient->detail) {
$urlAvatarDefault = $patient->detail->nIDJenisKelamin == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/female-avatar.png';
$avatarMember = $patient->detail->sImage ?? $urlAvatarDefault;
@@ -56,14 +57,19 @@ class ChatDoctorController extends Controller
$arr['id'] = $c->id;
$arr['patient_id'] = $patient->nID;
$arr['avatar'] = $avatarMember;
$arr['name'] = $patient->sFirstName .' '.$patient->sLastName; ;
$arr['name'] = $patient->sFirstName .' '.$patient->sLastName;
$arr['channel_id'] = $channel->id;
array_push($dataIncomingChat, $arr);
}
}
$dataChannel = Channel::where('doctor_id',$user->person_id)->get()->toArray();
$dataOnGoing = [];
if ($dataChannel){
$chatOngoing = Livechat::where([
'doctor_id'=> $user->person_id,
'status' => 5
])->get()->first();
if ($chatOngoing && $dataChannel){
foreach($dataChannel as $d){
$user = UserLMS::with('detail')->where('nID', $d['member_id'])->first();
$lastMessage = Message::where('channel_id', $d['id'])
@@ -80,6 +86,7 @@ class ChatDoctorController extends Controller
$arr['avatar'] = $avatarMember;
$arr['name'] = $user->sFirstName .' '.$user->sLastName;
$arr['last_message'] = $lastMessage;
$arr['channel_id'] = $d['id'];
array_push($dataOnGoing, $arr);
}
@@ -145,13 +152,16 @@ class ChatDoctorController extends Controller
'doctor_id' => $livechat->doctor_id
])->first();
$dataNotif = [
'channel_id' => $channel->id,
'livechat_id' => $livechat->id,
'channel_id' => (string) $channel->id,
'livechat_id' => (string) $livechat->id,
'type' => 'decline-chat'
];
$user = UserLMS::where('nID',$livechat->patient_id)->first();
if ($user) {
if ($user->nIDUser) { // Jika Dependent yang request
$user = UserLMS::where('nIDUser',$livechat->patient_id)->first();
}
$user->notify(new SendNotification($title, $body, $dataNotif));
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
} else {
@@ -188,13 +198,16 @@ class ChatDoctorController extends Controller
'doctor_id' => $livechat->doctor_id
])->first();
$dataNotif = [
'channel_id' => $channel->id,
'livechat_id' => $livechat->id,
'channel_id' => (string)$channel->id,
'livechat_id' => (string)$livechat->id,
'type' => 'approve-chat'
];
$user = UserLMS::where('nID',$livechat->patient_id)->first();
if ($user) {
if ($user->nIDUser) { // Jika Dependent yang request
$user = UserLMS::where('nIDUser',$livechat->patient_id)->first();
}
$user->notify(new SendNotification($title, $body, $dataNotif));
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
} else {
@@ -229,14 +242,17 @@ class ChatDoctorController extends Controller
'doctor_id' => $livechat->doctor_id
])->first();
$dataNotif = [
'channel_id' => $channel->id,
'livechat_id' => $livechat->id,
'channel_id' => (string)$channel->id,
'livechat_id' => (string)$livechat->id,
'type' => 'end-chat'
];
$user = UserLMS::where('nID',$livechat->patient_id)->first();
if ($user) {
if ($user->nIDUser) { // Jika Dependent yang request
$user = UserLMS::where('nIDUser',$livechat->patient_id)->first();
}
$user->notify(new SendNotification($title, $body, $dataNotif));
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
} else {