Ejemplo n.º 1
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();
     $businessId = $request->input('business');
     $appointment = Appointment::findOrFail($request->input('appointment'));
     $action = $request->input('action');
     $widgetType = $request->input('widget');
     ///////////////////////////////////
     // TODO: AUTHORIZATION GOES HERE //
     ///////////////////////////////////
     // AUTHORIZE:
     //  (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, $businessId, $appointment->id));
     try {
         $appointment = $this->concierge->requestAction(auth()->user(), $appointment, $action);
     } catch (\Exception $e) {
         return response()->json(['code' => 'ERROR', 'html' => '']);
     }
     $contents = ['appointment' => $appointment, '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]);
 }
Ejemplo n.º 2
0
 /**
  * post Action for booking
  *
  * @param  AlterAppointmentRequest $request
  * @return JSON                    Action result object
  */
 public function postAction(AlterAppointmentRequest $request)
 {
     $this->log->info(__METHOD__);
     //////////////////
     // FOR REFACOTR //
     //////////////////
     $issuer = auth()->user();
     $businessId = $request->input('business');
     $appointmentId = $request->input('appointment');
     $action = $request->input('action');
     $widget = $request->input('widget');
     $this->log->info(sprintf("AJAX postAction.request:[issuer:%s, action:%s, business:%s, appointment:%s]", $issuer->email, $action, $businessId, $appointmentId));
     $appointment = Appointment::find($appointmentId);
     switch ($action) {
         case 'annulate':
             $appointment->doAnnulate();
             break;
         case 'confirm':
             $appointment->doConfirm();
             break;
         case 'serve':
             $appointment->doServe();
             break;
         default:
             // Ignore Invalid Action
             $this->log->warning('Invalid Action request');
             return response()->json(['code' => 'ERROR', 'html' => '']);
             break;
     }
     /**
      * Widgets MUST be rendered before being returned on Response
      * as they need to be interpreted as HTML
      */
     switch ($widget) {
         case 'row':
             $html = Widget::AppointmentsTableRow(['appointment' => $appointment, 'user' => auth()->user()])->render();
             break;
         case 'panel':
         default:
             $html = Widget::AppointmentPanel(['appointment' => $appointment, 'user' => auth()->user()])->render();
             break;
     }
     $appointmentPresenter = $appointment->getPresenter();
     $date = $appointment->start_at->toDateString();
     $code = $appointmentPresenter->code();
     Notifynder::category('appointment.' . $action)->from('App\\Models\\User', auth()->user()->id)->to('App\\Models\\Business', $appointment->business->id)->url('http://localhost')->extra(compact('code', 'action', 'date'))->send();
     $this->log->info("postAction.response:[appointment:{$appointment->toJson()}]");
     return response()->json(['code' => 'OK', 'html' => $html]);
 }
Ejemplo n.º 3
0
 /**
  * post Action for booking
  *
  * @param  AlterAppointmentRequest $request
  * @return JSON                    Action result object
  */
 public function postAction(AlterAppointmentRequest $request)
 {
     $this->log->info('BookingController: postAction');
     $issuer = auth()->user();
     $businessId = $request->input('business');
     $appointmentId = $request->input('appointment');
     $action = $request->input('action');
     $widget = $request->input('widget');
     $this->log->info("AJAX postAction.request:[issuer:{$issuer->email}, action:{$action}, business:{$businessId}, appointment:{$appointmentId}]");
     $appointment = Appointment::find($appointmentId);
     switch ($action) {
         case 'annulate':
             $appointment->doAnnulate();
             break;
         case 'confirm':
             $appointment->doConfirm();
             break;
         case 'serve':
             $appointment->doServe();
             break;
         default:
             # Ignore Invalid Action
             $this->log->warning('Invalid Action request');
             break;
     }
     /**
      * Widgets MUST be rendered before being returned on Response
      * as they need to be interpreted as HTML
      *
      */
     switch ($widget) {
         case 'row':
             $html = Widget::AppointmentsTableRow(['appointment' => $appointment, 'user' => auth()->user()])->render();
             break;
         case 'panel':
         default:
             $html = Widget::AppointmentPanel(['appointment' => $appointment, 'user' => auth()->user()])->render();
             break;
     }
     $appointmentPresenter = $appointment->getPresenter();
     // TODO: It is probably possible to move Notifynder to a more proper place
     $date = $appointment->start_at->toDateString();
     $code = $appointmentPresenter->code();
     Notifynder::category('appointment.' . $action)->from('App\\User', auth()->user()->id)->to('App\\Business', $appointment->business->id)->url('http://localhost')->extra(compact('code', 'action', 'date'))->send();
     $this->log->info("postAction.response:[appointment:{$appointment->toJson()}]");
     return response()->json(['code' => 'OK', 'html' => $html]);
 }
Ejemplo n.º 4
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]);
 }