From 7eb4af3db2f5d43e596fbd5710b6d66736ca4425 Mon Sep 17 00:00:00 2001 From: Cynthia Kamau Date: Fri, 7 May 2021 15:57:38 +0300 Subject: [PATCH] bug fix in app protocols --- app/Http/Controllers/API/ResourcesController.php | 14 ++++++++++++++ app/User.php | 10 +++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/API/ResourcesController.php b/app/Http/Controllers/API/ResourcesController.php index 66199bc..d013fa7 100644 --- a/app/Http/Controllers/API/ResourcesController.php +++ b/app/Http/Controllers/API/ResourcesController.php @@ -532,6 +532,20 @@ public function get_hcw_partner_protocols() return new GenericCollection(FacilityProtocol::orderBy('id','desc')->where('facility_id',$hcw->facility_id)->paginate(20)); } + public function get_hcw_facility_protocols() + { + $user = auth()->user(); + + $hcw = HealthCareWorker::where('user_id', $user->id)->first(); + if (is_null($hcw)) + return response()->json([ + 'success' => false, + 'message' => 'You do not belong to a facility. Please contact system admin' + ], 200); + + + return new GenericCollection(FacilityProtocol::orderBy('id','desc')->where('facility_id',$hcw->facility_id)->paginate(20)); + } public function counties() diff --git a/app/User.php b/app/User.php index cdb128d..3a7eebb 100644 --- a/app/User.php +++ b/app/User.php @@ -44,10 +44,10 @@ public function role() return $this->belongsTo('App\Role'); } - // public function partner() - // { - // return $this->hasMany('App\Partner','partner_users'); - // } + public function partner() + { + return $this->hasMany('App\Partner'); + } public function hcw() { @@ -59,7 +59,7 @@ public function toArray() { $data = parent::toArray(); $data['cadre'] = optional(optional($this->hcw)->cadre)->name; $data['dob'] = optional($this->hcw)->dob; - $data['partner'] = optional($this->partner); + $data['partner'] = optional($this->partner)->name; $data['county'] = optional(optional(optional($this->hcw)->facility)->county)->name; $data['sub_county'] = optional(optional(optional($this->hcw)->facility)->sub_county)->name; $data['role'] = $this->role;