コード例 #1
0
 public function __invoke(array $input)
 {
     $employeeId = $input['employeeId'];
     $shiftId = $input['shiftId'];
     // Make sure this is a valid employee
     $Employee = new Employee();
     if (!$Employee->load($employeeId)) {
         return ErrorPayload::create('Employee not found');
     }
     // Make sure this is a valid shift
     $Shift = new Shift();
     if (!$Shift->load($shiftId)) {
         return ErrorPayload::create('Shift not found');
     }
     if ($Shift->employee_id == $employeeId) {
         return SuccessPayload::create(['message' => 'Employee already assigned to this shift']);
     } else {
         // make sure this employee doesn't have any overlapping shifts that would conflict...
         $filters = [];
         $filters[] = ['key' => 'employee_id', 'value' => $employeeId];
         if ($Shifts = $Shift->filter($Shift->start_time, $Shift->end_time, $filters)) {
             if (count($Shifts)) {
                 return ErrorPayload::create('Assiging the employee to this shift would result in overlapping shifts for this employee');
             }
         }
         try {
             $Shift->update(['employee_id' => $employeeId]);
             return SuccessPayload::create(['message' => 'Shift updated successfully']);
         } catch (\Exception $e) {
             return ErrorPayload::create('There was an error updating this shift');
         }
     }
 }
コード例 #2
0
 public function __invoke(array $input)
 {
     $employeeId = $input['employeeId'];
     $shiftId = $input['shiftId'];
     // Make sure this employee isn't looking at another employee's information
     if (Auth::isEmployee() && Auth::getId() != $employeeId) {
         return InvalidPayload::create('You can not list coworkers for another employee');
     }
     // Make sure this is a valid employee
     $Employee = new Employee();
     if (!$Employee->load($employeeId)) {
         return ErrorPayload::create('Employee not found');
     }
     // Make sure this is a valid shift
     $Shift = new Shift();
     if (!$Shift->load($shiftId)) {
         return ErrorPayload::create('Shift not found');
     }
     // Make sure that this employee is assigned to this shift
     if ($Shift->employee_id != $employeeId) {
         return ErrorPayload::create('You do not work this shift');
     }
     $coworkers = $Shift->listCoworkers();
     if (count($coworkers)) {
         return SuccessPayload::create($coworkers);
     } else {
         return ErrorPayload::create('No coworkers found for this shift');
     }
 }
コード例 #3
0
 public function __invoke(array $input)
 {
     // Validate the startTime and endTime variables
     if (empty($input['startTime']) || empty($input['endTime'])) {
         return InvalidPayload::create('Missing required inputs: startTime and endTime are required');
     } else {
         try {
             $startTime = Carbon::createFromFormat('Y-m-d H:i:s', urldecode($input['startTime']));
             $endTime = Carbon::createFromFormat('Y-m-d H:i:s', urldecode($input['endTime']));
         } catch (\Exception $e) {
             return InvalidPayload::create('Invalid date format: startTime and endTime must be in "Y-m-d H:i:s" format');
         }
     }
     $error_message = null;
     if ($startTime > $endTime) {
         $error_message = "startTime must be before endTime";
     } elseif ($startTime->diffInHours($endTime) > 24) {
         $error_message = "startTime and endTime can not differ by more than 24 hours";
     }
     if ($error_message) {
         return ErrorPayload::create($error_message);
     }
     // Load shift
     $shiftId = $input['shiftId'];
     $Shift = new Shift();
     if (!$Shift->load($shiftId)) {
         return ErrorPayload::create('Shift not found');
     }
     $update_array = ['start_time' => $startTime->format("Y-m-d H:i:s"), 'end_time' => $endTime->format("Y-m-d H:i:s")];
     try {
         $Shift->update($update_array);
         return SuccessPayload::create(['message' => 'Shift updated successfully']);
     } catch (\Exception $e) {
         return ErrorPayload::create('There was an error updating this shift');
     }
 }