Delete Submission
Signed-off-by: Jonas Rittershofer <jotoeri@users.noreply.github.com>
This commit is contained in:
parent
bb9bca3667
commit
8a96e16413
6 changed files with 84 additions and 6 deletions
|
|
@ -714,4 +714,31 @@ class ApiController extends Controller {
|
|||
|
||||
return new Http\JSONResponse([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function deleteSubmission(int $id): Http\JSONResponse {
|
||||
$this->logger->debug('Delete Submission: {id}', [
|
||||
'id' => $id,
|
||||
]);
|
||||
|
||||
try {
|
||||
$submission = $this->submissionMapper->findById($id);
|
||||
$form = $this->formMapper->findById($submission->getFormId());
|
||||
} catch (IMapperException $e) {
|
||||
$this->logger->debug('Could not find form or submission');
|
||||
return new Http\JSONResponse([], Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
|
||||
if ($form->getOwnerId() !== $this->userId) {
|
||||
$this->logger->debug('This form is not owned by the current user');
|
||||
return new Http\JSONResponse([], Http::STATUS_FORBIDDEN);
|
||||
}
|
||||
|
||||
// Delete submission (incl. Answers)
|
||||
$this->submissionMapper->delete($submission);
|
||||
|
||||
return new Http\JSONResponse($id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue