/**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $appointmentId = $this->get('appointment');
     $businessId = $this->get('business');
     $appointment = Appointment::find($appointmentId);
     $authorize = $appointment->issuer->id == auth()->user()->id || auth()->user()->isOwner($businessId);
     logger()->info("Authorize:{$authorize}");
     return $authorize;
 }
Esempio n. 2
0
 /**
  * post Action for booking.
  *
  * @param AlterAppointmentRequest $request
  *
  * @return JSON Action result object
  */
 public function postAction(AlterAppointmentRequest $request)
 {
     logger()->info(__METHOD__);
     //////////////////
     // FOR REFACOTR //
     //////////////////
     $issuer = auth()->user();
     $business = Business::findOrFail($request->input('business'));
     $appointment = Appointment::findOrFail($request->input('appointment'));
     $action = $request->input('action');
     $widgetType = $request->input('widget');
     /////////////////////////////////////////////
     // AUTHORIZATION : AlterAppointmentRequest //
     /////////////////////////////////////////////
     //  (A) auth()->user() is owner of $business
     // OR
     //  (B) auth()->user() is issuer of $appointment
     logger()->info(sprintf('postAction.request:[issuer:%s, action:%s, business:%s, appointment:%s]', $issuer->email, $action, $business->id, $appointment->id));
     $this->concierge->business($business);
     $appointmentManager = $this->concierge->booking()->appointment($appointment->hash);
     switch ($action) {
         case 'cancel':
             $appointment = $appointmentManager->cancel();
             event(new AppointmentWasCanceled($issuer, $appointment));
             break;
         case 'confirm':
             $appointment = $appointmentManager->confirm();
             event(new AppointmentWasConfirmed($issuer, $appointment));
             break;
         case 'serve':
             $appointment = $appointmentManager->serve();
             break;
         default:
             # code...
             break;
     }
     $contents = ['appointment' => $appointment->load('contact'), 'user' => auth()->user()];
     $viewKey = "widgets.appointment.{$widgetType}._body";
     if (!view()->exists($viewKey)) {
         return response()->json(['code' => 'ERROR', 'html' => '']);
     }
     // Widgets MUST be rendered before being returned on Response as they need to be interpreted as HTML
     $html = view($viewKey, $contents)->render();
     logger()->info("postAction.response:[appointment:{$appointment->toJson()}]");
     return response()->json(['code' => 'OK', 'html' => $html]);
 }
Esempio n. 3
0
 private function getAppointments($expression)
 {
     $this->results['appointments'] = Appointment::whereIn('business_id', $this->scope['businessesIds'])->where('hash', 'like', $expression . '%')->get();
 }
Esempio n. 4
0
 /**
  * @covers \Timegridio\Concierge\Models\Appointment::scopeOfBusiness
  * @test
  */
 public function it_scopes_unserved()
 {
     $this->assertInstanceOf(Illuminate\Database\Eloquent\Builder::class, Appointment::unserved());
 }
Esempio n. 5
0
 protected function generateAppointment($issuerId, $businessId, $contactId, $serviceId, Carbon $startAt, Carbon $finishAt, $comments = null, $humanresourceId = null)
 {
     $appointment = new Appointment();
     $appointment->doReserve();
     $appointment->setStartAtAttribute($startAt);
     $appointment->setFinishAtAttribute($finishAt);
     $appointment->business()->associate($businessId);
     $appointment->issuer()->associate($issuerId);
     $appointment->contact()->associate($contactId);
     $appointment->service()->associate($serviceId);
     $appointment->humanresource()->associate($humanresourceId);
     $appointment->comments = $comments;
     $appointment->doHash();
     return $appointment;
 }