limiter l'ajout de vote stack si la limite par poll a été atteinte

#30
This commit is contained in:
Tykayn 2021-05-18 23:46:05 +02:00 committed by tykayn
parent 5716642c09
commit f2edaa49f0
1 changed files with 22 additions and 16 deletions

View File

@ -47,14 +47,22 @@ class VoteController extends EmailsController {
) {
/***
* checks before persisting
*/
$em = $this->getDoctrine()->getManager();
$emPol = $em->getRepository( Poll::class );
$poll = $emPol->findOneByCustomUrl( $custom_url );
// check : existence of poll
if ( ! $poll ) {
return $this->json( [ 'message' => 'poll "' . $custom_url . '" not found' ], 404 );
}
// check : limit of number of participation max
if ( count( $poll->getStacksOfVotes() ) == $poll->getVotesMax() ) {
return $this->json( [ 'message' => 'poll "' . $custom_url . '" not allowed to have more stack of votes than ' . $poll->getVotesMax() ],
403 );
}
$data = $request->getContent();
$data = json_decode( $data, true );
@ -63,9 +71,7 @@ class VoteController extends EmailsController {
$owner = new Owner();
$owner
->addPoll( $poll )
;
->addPoll( $poll );
$newStack = new StackOfVotes();
$newStack
->setPoll( $poll )