Reduce sonar complexity (#992)
This commit is contained in:
@@ -54,31 +54,9 @@ class ApiActivityController extends ApiController
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
// Validates basic fields to create the entry
|
||||
$validator = Validator::make($request->all(), [
|
||||
'summary' => 'required|max:100000',
|
||||
'description' => 'required|max:1000000',
|
||||
'date_it_happened' => 'required|date',
|
||||
'activity_type_id' => 'integer',
|
||||
'contacts' => 'required|array',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $this->setErrorCode(32)
|
||||
->respondWithError($validator->errors()->all());
|
||||
}
|
||||
|
||||
// Make sure each contact exists and has the right to be associated with
|
||||
// this account
|
||||
$attendeesID = $request->get('contacts');
|
||||
foreach ($attendeesID as $attendeeID) {
|
||||
try {
|
||||
$contact = Contact::where('account_id', auth()->user()->account_id)
|
||||
->where('id', $attendeeID)
|
||||
->firstOrFail();
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
$contact = $this->validateUpdate($request);
|
||||
if (! $contact instanceof Contact) {
|
||||
return $contact;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -126,31 +104,9 @@ class ApiActivityController extends ApiController
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
// Validates basic fields to create the entry
|
||||
$validator = Validator::make($request->all(), [
|
||||
'summary' => 'required|max:100000',
|
||||
'description' => 'required|max:1000000',
|
||||
'date_it_happened' => 'required|date',
|
||||
'activity_type_id' => 'integer',
|
||||
'contacts' => 'required|array',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $this->setErrorCode(32)
|
||||
->respondWithError($validator->errors()->all());
|
||||
}
|
||||
|
||||
// Make sure each contact exists and has the right to be associated with
|
||||
// this account
|
||||
$attendeesID = $request->get('contacts');
|
||||
foreach ($attendeesID as $attendeeID) {
|
||||
try {
|
||||
$contact = Contact::where('account_id', auth()->user()->account_id)
|
||||
->where('id', $attendeeID)
|
||||
->firstOrFail();
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
$isvalid = $this->validateUpdate($request);
|
||||
if ($isvalid !== true) {
|
||||
return $isvalid;
|
||||
}
|
||||
|
||||
// Update the activity itself
|
||||
@@ -206,6 +162,44 @@ class ApiActivityController extends ApiController
|
||||
return new ActivityResource($activity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the request for update.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
private function validateUpdate(Request $request)
|
||||
{
|
||||
// Validates basic fields to create the entry
|
||||
$validator = Validator::make($request->all(), [
|
||||
'summary' => 'required|max:100000',
|
||||
'description' => 'required|max:1000000',
|
||||
'date_it_happened' => 'required|date',
|
||||
'activity_type_id' => 'integer',
|
||||
'contacts' => 'required|array',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $this->setErrorCode(32)
|
||||
->respondWithError($validator->errors()->all());
|
||||
}
|
||||
|
||||
// Make sure each contact exists and has the right to be associated with
|
||||
// this account
|
||||
$attendeesID = $request->get('contacts');
|
||||
foreach ($attendeesID as $attendeeID) {
|
||||
try {
|
||||
$contact = Contact::where('account_id', auth()->user()->account_id)
|
||||
->where('id', $attendeeID)
|
||||
->firstOrFail();
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an activity.
|
||||
* @param Request $request
|
||||
|
||||
Reference in New Issue
Block a user