/**
  * @param $request
  * @route 'plot/iterinary/end'
  * @return json
  * */
 public function endIterinary(Request $request)
 {
     //TODO
     // update pivot status column to done.
     // calculate routes columns
     $token = Input::get('token');
     if (!$token) {
         return response()->json('kuwang input', 400);
     }
     $user = UserSessionHandler::user($token);
     $current_iterinary = $user->current_iterinary()->first();
     if (!$current_iterinary) {
         return response()->json('you have no iterinaries', 403);
     }
     $title = Input::get('title');
     $route = $current_iterinary->route;
     if (!$route) {
         $current_iterinary->delete();
         // e delete nalang
         return response()->json('walay route');
     }
     UserSessionHandler::endIterinary($user, $current_iterinary, $title);
     $pivot = ['status' => 'done', 'title' => $title];
     $user->iterinaries()->updateExistingPivot($current_iterinary->id, $pivot, true);
     //dd($user_id, $iterinary_id);
     $message = ['code' => 200, 'message' => 'success'];
     return response()->json('success', 200);
 }