Skip to content

Commit

Permalink
bug: added requirements and logic handling for duplicate requests on …
Browse files Browse the repository at this point in the history
…the same day
  • Loading branch information
e-tayfw committed Oct 25, 2024
1 parent ebffeff commit 85a4ef9
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions backend-api/app/Http/Controllers/RequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,25 @@ public function createRecurringRequest(Request $request)

// Condition 2b: Check if any of the recurringDates clash with existingRequests
foreach ($recurringDates as $date) {
$duplicate = $existingRequests->where('Date_Requested', $date)->first();
if ($duplicate) {
return response()->json([
'message' => "Duplicate request found on {$date}. Cannot create recurring requests with overlapping dates.",
'success' => false,
'day' => $dayChosen,
'startDate' => $startDate,
'endDate' => $endDate,
'arrangement' => $arrangement,
'reason' => $reason,
], 409); // 409 Conflict
// Get all existing requests on that date
$duplicates = $existingRequests->where('Date_Requested', $date);
// Step 4a: If there is a duplicate for date_requested, check if the arrangement is the same
if ($duplicates->isNotEmpty()) {
$recurringArrangement = $arrangement;
foreach($duplicates as $duplicate) {
$duplicateArrangement = $duplicate->Duration;
// Condition 4a: If one of the arrangement is FD, duplicate is not allowed
if ($recurringArrangement === 'FD' || $duplicateArrangement === 'FD') {
return response()->json(['message' => 'Duplicate requests cannot be made'], 400);
}
// Condition 4b: If one of the arrangement is AM and the other is PM vice cersa, duplicate will be allowed
elseif ($recurringArrangement === 'AM' && $duplicateArrangement === 'AM' || $recurringArrangement === 'PM' && $duplicateArrangement === 'PM') {
return response()->json(['message' => 'Duplicate requests cannot be made'], 400);
}
else {
continue;
}
}
}
}

Expand Down

0 comments on commit 85a4ef9

Please sign in to comment.