PredictorProjector.php 667 Bytes
<?php

namespace FootyRoom\Queries\Predictor;

use FootyRoom\Support\MongoClient;
use FootyRoom\Core\Predictor\PredictionStakeRaised;

class PredictorProjector
{
    /**
     * @var \FootyRoom\Support\MongoClient
     */
    protected $mongo;

    public function __construct(MongoClient $mongo)
    {
        $this->mongo = $mongo;
    }

    public function whenPredictionStakeRaised(PredictionStakeRaised $event): void
    {
        $this->mongo->footyroom->selectCollection('predictor.players')->updateOne(
            ['userId' => $event->prediction->getUserId()],
            ['$inc' => ['stake' => $event->raise, 'locked' => $event->raise]]
        );
    }
}