コード例 #1
0
 public function __invoke(array $input)
 {
     if (!$this->auth->authorizeEndpoint('ShowEmployee')) {
         return $this->auth->errorPayload;
     }
     $user = User::find($input['id']);
     return (new Payload())->withStatus(Payload::OK)->withOutput($user->toArray());
 }
コード例 #2
0
 public function __invoke(array $input)
 {
     if (!$this->auth->authorizeEndpoint('ShowWorkweekByDate')) {
         return $this->auth->errorPayload;
     }
     $my_id = $this->auth->User->id;
     $workweek = Shift::hoursByWeek($input['date'], $my_id);
     return (new Payload())->withStatus(Payload::OK)->withOutput($workweek);
 }
コード例 #3
0
 public function __invoke(array $input)
 {
     if (!$this->auth->authorizeEndpoint('CreateShift')) {
         return $this->auth->errorPayload;
     }
     $shift = new Shift();
     if (!isset($input['manager_id'])) {
         // if no manager_id provided, default to the manager creating the shift
         $input['manager_id'] = $this->auth->User->id;
     }
     if ($shift->validate($input)) {
         $shift = new Shift($input);
         $shift->save();
     } else {
         return (new Payload())->withStatus(Payload::INVALID)->withOutput(['error' => 'Missing required fields.']);
     }
     return (new Payload())->withStatus(Payload::OK)->withOutput($shift->toArray());
 }
コード例 #4
0
ファイル: ListShifts.php プロジェクト: simonbacquie/shift-api
 public function __invoke(array $input)
 {
     if (!$this->auth->authorizeEndpoint('ListShifts')) {
         return $this->auth->errorPayload;
     }
     if (!isset($input['start_time']) || !isset($input['end_time'])) {
         return (new Payload())->withStatus(Payload::INVALID)->withOutput(['error' => 'start_time and end_time fields are required.']);
     }
     $shifts = Shift::shiftsInTimeRange($input['start_time'], $input['end_time']);
     $shifts = $shifts->with('manager')->get();
     return (new Payload())->withStatus(Payload::OK)->withOutput($shifts->toArray());
 }
コード例 #5
0
 public function __invoke(array $input)
 {
     if (!$this->auth->authorizeEndpoint('ShowMyShift')) {
         return $this->auth->errorPayload;
     }
     $my_id = $this->auth->User->id;
     $my_shift = Shift::where('id', $input['id'])->first();
     if ($my_shift->employee_id != $my_id) {
         return (new Payload())->withStatus(Payload::INVALID)->withOutput($overlapping_shifts->toArray());
     }
     $overlapping_shifts = Shift::shiftsInTimeRange($my_shift->start_time, $my_shift->end_time);
     $overlapping_shifts = $overlapping_shifts->with('employee')->get();
     return (new Payload())->withStatus(Payload::OK)->withOutput(['overlapping_shifts' => $overlapping_shifts->toArray()]);
 }
コード例 #6
0
 public function __invoke(array $input)
 {
     if (!$this->auth->authorizeEndpoint('ListMyShifts')) {
         return $this->auth->errorPayload;
     }
     $my_id = $this->auth->User->id;
     $my_shifts = \ShiftApi\Model\Shift::where('employee_id', $my_id);
     $my_shifts = $my_shifts->with('manager');
     // $my_shifts = $my_shifts->with('overlapping_shifts');
     if ($this->helper->checkTrue($input, 'unassigned')) {
         $my_shifts = $my_shifts->orWhereNull('employee_id');
     }
     $my_shifts = $my_shifts->get();
     return (new Payload())->withStatus(Payload::OK)->withOutput($my_shifts->toArray());
 }
コード例 #7
0
 public function __invoke(array $input)
 {
     if (!$this->auth->authorizeEndpoint('UpdateShift')) {
         return $this->auth->errorPayload;
     }
     // wow, PHP doesn't automatically parse incoming data if it's a PUT...
     // ideally $input should contain the parsed data
     // leaving this hack here for now
     parse_str(file_get_contents("php://input"), $input);
     $shift = Shift::findOrFail($input['id']);
     $updated_fields = array_merge($shift->toArray(), $input);
     if ($shift->validate($updated_fields)) {
         $shift->fill($updated_fields);
         $shift->save();
     } else {
         return (new Payload())->withStatus(Payload::INVALID)->withOutput(['error' => 'Missing required fields.']);
     }
     return (new Payload())->withStatus(Payload::OK)->withOutput($shift->toArray());
 }