Merge branch '210-error-when-updating-role-id' into 'master'

Resolve "Error when updating role id"

Closes #210

See merge request jankstudio/resq!246
This commit is contained in:
Kendrick Chan 2019-05-27 02:01:56 +00:00
commit 74f292da52
2 changed files with 15 additions and 2 deletions

View file

@ -9,6 +9,7 @@ use Doctrine\ORM\Query;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
use App\Menu\Generator as MenuGenerator;
use App\Access\Generator as ACLGenerator;
@ -275,7 +276,19 @@ class RoleController extends BaseController
], 422);
} else {
// validated! save the entity
$em->flush();
// catch the exception in case user updated the id
try
{
$em->flush();
}
catch(ForeignKeyConstraintViolationException $e)
{
$error_array['id'] = 'Role has already been assigned to user/s and id cannot be updated';
return $this->json([
'success' => false,
'errors' => $error_array
], 403);
}
// return successful response
return $this->json([

View file

@ -116,7 +116,7 @@
}
});
}).fail(function(response) {
if (response.status == 422) {
if (response.status == 422 || response.status == 403) {
var errors = response.responseJSON.errors;
var firstfield = false;