Exemplo n.º 1
0
 /**
  * Handle domain logic for an action.
  *
  * @param array $input
  *
  * @return PayloadInterface
  */
 public function __invoke(array $input)
 {
     /* @var Token $token */
     $token = $input[AuthHandler::TOKEN_ATTRIBUTE];
     $user = $this->user_repository->getFromInputToken($input);
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput(['token' => $token->getToken(), 'user' => $user]);
 }
Exemplo n.º 2
0
 /**
  * Handle domain logic for an action.
  *
  * @param array $input
  *
  * @return PayloadInterface
  */
 public function __invoke(array $input)
 {
     $user = $this->user_repository->getFromInputToken($input);
     if ($user->role !== 'manager') {
         throw new AuthException('Only managers have access to do that');
     }
     if (empty($input['id'])) {
         throw new \DomainException('You must supply the shift id');
     }
     if (!empty($input['start_time'])) {
         $input['start_time'] = date('Y-m-d G:i:s', strtotime($input['start_time']));
         if ($input['start_time'] === false) {
             throw new \DomainException("Could not parse 'start time'");
         }
     }
     if (!empty($input['end_time'])) {
         $input['end_time'] = date('Y-m-d G:i:s', strtotime($input['end_time']));
         if ($input['end_time'] === false) {
             throw new \DomainException("Could not parse 'end time'");
         }
     }
     // only grab the necessary fields
     $values = array_intersect_key($input, array_flip(['id', 'manager_id', 'employee_id', 'break', 'start_time', 'end_time']));
     $shift = $this->shift_repository->update($input['id'], $values);
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput([$shift]);
 }
Exemplo n.º 3
0
 /**
  * @inheritDoc
  */
 public function __invoke(array $input)
 {
     $name = 'world';
     if (!empty($input['name'])) {
         $name = $input['name'];
     }
     return $this->payload->withStatus(PayloadInterface::STATUS_OK)->withOutput(['hello' => $name]);
 }
Exemplo n.º 4
0
 /**
  * @inheritDoc
  */
 public function __invoke(array $input)
 {
     if (empty($input['text'])) {
         return $this->payload->withStatus(PayloadInterface::INVALID)->withOutput(['error' => 'Missing `text` field on input']);
     }
     $wordCounts = $this->wordCount->countWords($input['text']);
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput(['wordcounts' => $wordCounts]);
 }
Exemplo n.º 5
0
 function __invoke(array $input)
 {
     if (!empty($input['id'])) {
         $users = $this->user_repository->find($input['id']);
         $users = [$users];
     } else {
         $users = $this->user_repository->findBy([]);
     }
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput($users);
 }
Exemplo n.º 6
0
 /**
  * Handle domain logic for an action.
  *
  * @param array $input
  *
  * @return PayloadInterface
  */
 public function __invoke(array $input)
 {
     $user = $this->user_repository->getFromInputToken($input);
     if ($user->role === 'employee') {
         $shifts = $this->shift_repository->getShiftsForEmployee($user->id, $input);
     } elseif ($user->role === 'manager') {
         $shifts = $this->shift_repository->getShiftsForManager($input);
     } else {
         throw new \DomainException('Unknown user role');
     }
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput($shifts);
 }
Exemplo n.º 7
0
 /**
  * @inheritDoc
  */
 public function __invoke(array $input)
 {
     $token = $input['spark/auth:token'];
     $role = $token->getMetadata('role');
     $isEmployee = strcmp($role, 'employee') === 0;
     if ($isEmployee) {
         $coworkers = $this->getCoworkers($input['shift']);
     } else {
         throw new AuthException('This action is not available to managers.');
     }
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput(["coworkers", $coworkers]);
 }
Exemplo n.º 8
0
 /**
  * @inheritDoc
  */
 public function __invoke(array $input)
 {
     $token = $input['spark/auth:token'];
     $role = $token->getMetadata('role');
     $isEmployee = strcmp($role, 'employee') === 0;
     if ($isEmployee) {
         $shifts = $this->getEmployeeShifts($token->getMetadata('id'));
     } else {
         $shifts = $this->getManagerShifts($input);
     }
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput(["shifts", $shifts]);
 }
Exemplo n.º 9
0
 /**
  * @inheritDoc
  */
 public function __invoke(array $input)
 {
     $token = $input['spark/auth:token'];
     $role = $token->getMetadata('role');
     $isEmployee = strcmp($role, 'employee') === 0;
     if ($isEmployee) {
         throw new AuthException('This action is not available to employees.');
     } else {
         $employee = User::load($input['employee'])->jsonSerialize();
     }
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput(["employee", $employee]);
 }
Exemplo n.º 10
0
 /**
  * @inheritDoc
  */
 public function __invoke(array $input)
 {
     $token = $input['spark/auth:token'];
     $role = $token->getMetadata('role');
     $isEmployee = strcmp($role, 'employee') === 0;
     if ($isEmployee) {
         throw new AuthException('This action is not available to employees.');
     } else {
         $shift = $this->updateShift($input);
     }
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput(["shift", $shift]);
 }
Exemplo n.º 11
0
 /**
  * @inheritDoc
  */
 public function __invoke(array $input)
 {
     $token = $input['spark/auth:token'];
     $role = $token->getMetadata('role');
     $isEmployee = strcmp($role, 'employee') === 0;
     if ($isEmployee) {
         $user_id = $token->getMetadata('id');
         $summary = $this->getSummary($user_id);
     } else {
         throw new AuthException('This action is not available to managers.');
     }
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput(["summary", $summary]);
 }
Exemplo n.º 12
0
 /**
  * @inheritDoc
  */
 public function __invoke(array $input)
 {
     $return_obj = $this->_validateUserRequest($input);
     if ($return_obj) {
         return $return_obj;
     }
     if ($this->_user_role != self::ROLE_MANAGER) {
         return $this->_returnAuthError($this->payload);
     }
     $id = $input['id'];
     $user = new \Equip\Project\DAL\User($id);
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput($user->toArray());
 }
Exemplo n.º 13
0
 /**
  * @inheritDoc
  */
 public function __invoke(array $input)
 {
     $composer = __DIR__ . '/../../composer.json';
     $composer = json_decode(file_get_contents($composer), true);
     return $this->payload->withStatus(PayloadInterface::STATUS_OK)->withOutput(['appName' => $composer['name'], 'equipVersion' => $composer['require']['equip/framework'], 'hello' => '/hello/:name']);
 }
Exemplo n.º 14
0
 /**
  * Handle domain logic for an action.
  *
  * @param array $input
  *
  * @return PayloadInterface
  */
 public function __invoke(array $input)
 {
     $user = $this->user_repository->getFromInputToken($input);
     $data = $this->shift_repository->getEmployeeShiftSummary($user->id, !empty($input['year']) ? $input['year'] : null);
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput($data);
 }