Feature: Delete submission (#137)

* Feature: Delete submission

* Small polishing

---------

Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
formsdev
2023-06-30 19:23:04 +05:30
committed by GitHub
parent 645a3712d6
commit 1d5c6f4895
8 changed files with 126 additions and 19 deletions

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Http\Controllers\Forms;
use App\Http\Controllers\Controller;
use App\Models\Forms\Form;
use Illuminate\Http\Request;
class RecordController extends Controller
{
public function delete(Request $request, $id, $recordId)
{
$form = Form::findOrFail((int) $id);
$this->authorize('delete', $form);
$record = $form->submissions()->where('id', $recordId)->firstOrFail();
$record->delete();
return $this->success([
'message' => 'Record successfully removed.'
]);
}
}

View File

@@ -16,7 +16,7 @@ class FormSubmissionResource extends JsonResource
public function toArray($request)
{
$this->generateFileLinks();
$this->addTimestamp();
$this->addExtraData();
return [
'data' => $this->data,
@@ -25,10 +25,11 @@ class FormSubmissionResource extends JsonResource
];
}
private function addTimestamp()
private function addExtraData()
{
$this->data = array_merge($this->data, [
"created_at" => $this->created_at->toDateTimeString()
"created_at" => $this->created_at->toDateTimeString(),
'id' => $this->id
]);
}

View File

@@ -11,7 +11,7 @@ namespace App\Service\OpenAi\Utils;
* Licensed under MIT license.
*/
use App\Exceptions\Coursework\InvalidJsonException;
use Aws\Exception\InvalidJsonException;
/**
* Attempts to fix truncated JSON by padding contextual counterparts at the end.