/** * Handle domain logic for an action. * * @param array $input * @return PayloadInterface * @throws UserNotAuthorized */ public function __invoke(array $input) { //Make sure requested user matches auth user //todo: figure out if managers can access all employees' hours if ($input['id'] != $input[AuthHandler::TOKEN_ATTRIBUTE]->getMetaData('id')) { throw new UserNotAuthorized(); } //Get hours and transform to more readable collection $employee = $this->userRepository->getOneByIdOrFail($input['id']); $hours = $this->shiftRepository->getHoursCountGroupedByWeekFor($employee); $this->collection->setData($hours)->setTransformer($this->hoursTransformer); return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->createData($this->collection)->toArray()); }
/** * @param User $user * @param Request $request * @param HoursTransformer $hoursTransformer * @return \Illuminate\Http\JsonResponse */ public function listHours(User $user, Request $request, HoursTransformer $hoursTransformer) { //Make sure requested user matches auth user // //todo: figure out if managers can access all employees' hours // if ($input['id'] != $input[AuthHandler::TOKEN_ATTRIBUTE]->getMetaData('id')) { // throw new UserNotAuthorized; // } //Get hours and transform to more readable collection $hours = $this->shiftRepository->getHoursCountGroupedByWeekFor($user); return $this->respondWithCollection($hours, $hoursTransformer); }