mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
⚡ return modifier token when creating a voting stack
This commit is contained in:
parent
087fbafd6a
commit
cfb6b9f65b
@ -321,12 +321,24 @@ class DefaultController extends AbstractController {
|
||||
$data = $request->getContent();
|
||||
$data = json_decode( $data, true );
|
||||
|
||||
$newOwner = new Owner();
|
||||
$newOwner
|
||||
->setEmail( $data[ 'email' ] )
|
||||
->setPseudo( $data[ 'pseudo' ] );
|
||||
|
||||
$emOwner = $this->getDoctrine()->getRepository( Owner::class );
|
||||
$existingOwner = false;
|
||||
$foundOwner = $emOwner->findOneByEmail( trim( $data[ 'email' ] ) );
|
||||
// manage existing or new Owner
|
||||
if ( ! $foundOwner ) {
|
||||
$foundOwner = new Owner();
|
||||
$foundOwner
|
||||
->setEmail( $data[ 'email' ] )
|
||||
->setPseudo( $data[ 'pseudo' ] );
|
||||
} else {
|
||||
$existingOwner = true;
|
||||
}
|
||||
$foundOwner
|
||||
->setModifierToken( $poll->generateAdminKey() );
|
||||
$stack = new StackOfVotes();
|
||||
$stack
|
||||
->setOwner( $foundOwner )
|
||||
->setPseudo( $data[ 'pseudo' ] )
|
||||
->setPoll( $poll );
|
||||
foreach ( $data[ 'votes' ] as $voteInfo ) {
|
||||
@ -354,11 +366,16 @@ class DefaultController extends AbstractController {
|
||||
$em->persist( $stack );
|
||||
$em->persist( $poll );
|
||||
$em->flush();
|
||||
$precision = '';
|
||||
if ( $existingOwner ) {
|
||||
$precision = ' from an existing owner : ' . $foundOwner->getEmail();
|
||||
}
|
||||
|
||||
return $this->json( [
|
||||
'message' => 'you created a vote stack',
|
||||
'vote_stack' => $stack,
|
||||
'json_you_sent' => $data,
|
||||
'message' => 'you created a vote stack' . $precision,
|
||||
'vote_stack' => $stack,
|
||||
'owner_modifier_token' => $foundOwner->getModifierToken(),
|
||||
'json_you_sent' => $data,
|
||||
],
|
||||
201 );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user