fix: fix api routes (#1932)
This commit is contained in:
@@ -55,28 +55,16 @@ class ApiNoteController extends ApiController
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
// Validates basic fields to create the entry
|
||||
$validator = Validator::make($request->all(), [
|
||||
'body' => 'required|max:100000',
|
||||
'contact_id' => 'required|integer',
|
||||
'is_favorited' => 'required|integer',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $this->setErrorCode(32)
|
||||
->respondWithError($validator->errors()->all());
|
||||
$isvalid = $this->validateUpdate($request);
|
||||
if ($isvalid !== true) {
|
||||
return $isvalid;
|
||||
}
|
||||
|
||||
try {
|
||||
Contact::where('account_id', auth()->user()->account_id)
|
||||
->where('id', $request->input('contact_id'))
|
||||
->firstOrFail();
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
try {
|
||||
$note = Note::create($request->all());
|
||||
$note = Note::create(
|
||||
$request->all()
|
||||
+ ['account_id' => auth()->user()->account_id]
|
||||
);
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondNotTheRightParameters();
|
||||
}
|
||||
@@ -86,9 +74,6 @@ class ApiNoteController extends ApiController
|
||||
$note->save();
|
||||
}
|
||||
|
||||
$note->account_id = auth()->user()->account_id;
|
||||
$note->save();
|
||||
|
||||
return new NoteResource($note);
|
||||
}
|
||||
|
||||
@@ -108,23 +93,9 @@ class ApiNoteController extends ApiController
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
// Validates basic fields to create the entry
|
||||
$validator = Validator::make($request->all(), [
|
||||
'body' => 'required|max:100000',
|
||||
'contact_id' => 'required|integer',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $this->setErrorCode(32)
|
||||
->respondWithError($validator->errors()->all());
|
||||
}
|
||||
|
||||
try {
|
||||
Contact::where('account_id', auth()->user()->account_id)
|
||||
->where('id', $request->input('contact_id'))
|
||||
->firstOrFail();
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
$isvalid = $this->validateUpdate($request);
|
||||
if ($isvalid !== true) {
|
||||
return $isvalid;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -135,15 +106,44 @@ class ApiNoteController extends ApiController
|
||||
|
||||
if ($request->get('is_favorited')) {
|
||||
$note->favorited_at = now();
|
||||
$note->save();
|
||||
} else {
|
||||
$note->favorited_at = null;
|
||||
$note->save();
|
||||
}
|
||||
$note->save();
|
||||
|
||||
return new NoteResource($note);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(), [
|
||||
'body' => 'required|max:100000',
|
||||
'contact_id' => 'required|integer',
|
||||
'is_favorited' => 'boolean',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $this->respondValidatorFailed($validator);
|
||||
}
|
||||
|
||||
try {
|
||||
Contact::where('account_id', auth()->user()->account_id)
|
||||
->where('id', $request->input('contact_id'))
|
||||
->firstOrFail();
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a note.
|
||||
* @param Request $request
|
||||
|
||||
Reference in New Issue
Block a user