Пример #1
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]);
 }
Пример #2
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]);
 }
Пример #3
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);
 }
Пример #4
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);
 }
Пример #5
0
 /**
  * Do any conversion from the database to actual data
  *
  * @param $arr
  *
  * @return array
  */
 protected function convertData($arr)
 {
     $arr = $this->convertTimestampsToCarbon($arr);
     $arr['manager'] = $this->user_repository->find($arr['manager_id']);
     $arr['employee'] = $this->user_repository->find($arr['employee_id']);
     return $arr;
 }
Пример #6
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);
 }