86 lines
2.9 KiB
PHP
86 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace Modules\HospitalPortal\Http\Controllers\Api;
|
|
|
|
use App\Helpers\Helper;
|
|
use App\Models\Claim;
|
|
use Illuminate\Contracts\Support\Renderable;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Controller;
|
|
use Modules\HospitalPortal\Helpers\ApiResponse;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class NotificationController extends Controller
|
|
{
|
|
public function getNotifications(Request $request, $hospital_id)
|
|
{
|
|
$data = [
|
|
'hospital_id' => $hospital_id,
|
|
];
|
|
if (!$hospital_id)
|
|
{
|
|
return ApiResponse::apiResponse('Not Found', $data, trans('Message.not_found'), 404);
|
|
}
|
|
else
|
|
{
|
|
try {
|
|
$notifications = DB::table('notifications')
|
|
->join('notification_types', 'notification_types.id', '=', 'notifications.type')
|
|
->select(
|
|
'notifications.id',
|
|
'notifications.title',
|
|
'notifications.description',
|
|
'notifications.avatar',
|
|
'notification_types.type',
|
|
DB::raw('DATE_FORMAT(notifications.created_at, "%Y-%m-%dT%H:%i:%s.000+07:00") as createdAt'),
|
|
'notifications.isUnRead',
|
|
)
|
|
->where('hospital_id', '=', $hospital_id)
|
|
->get();
|
|
$res_data['notifications'] = $notifications;
|
|
return ApiResponse::apiResponse("Success", $res_data, trans('Message.success'), 200);
|
|
}
|
|
catch (\Exception $e) {
|
|
return ApiResponse::apiResponse("Error", $data, $e->getMessage(), 500);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function setReadNotification(Request $request)
|
|
{
|
|
$data = [
|
|
'hospital_id' => $request->hospital_id,
|
|
'id' => $request->id,
|
|
'isUnRead'=> 0,
|
|
];
|
|
$validator = Validator::make($request->all(), [
|
|
'hospital_id' => 'required',
|
|
'id' => 'required'
|
|
], [
|
|
'hospital_id.required' => trans('Validation.required',['attribute' => 'Hospital ID']),
|
|
'id.required' => trans('Validation.required',['attribute' => 'ID']),
|
|
]);
|
|
if ($validator->fails())
|
|
{
|
|
return ApiResponse::apiResponse('Bad Request', $data, $validator->errors(), 400);
|
|
}
|
|
else
|
|
{
|
|
try {
|
|
DB::beginTransaction();
|
|
DB::table('notifications')
|
|
->where('notifications.id', '=', $request->id)
|
|
->update($data);
|
|
DB::commit();
|
|
return ApiResponse::apiResponse("Success", $data, trans('Message.read_notification'), 200);
|
|
|
|
}
|
|
catch (\Exception $e) {
|
|
DB::rollback();
|
|
return ApiResponse::apiResponse("Error", $data, $e->getMessage(), 500);
|
|
}
|
|
}
|
|
}
|
|
|
|
} |