Agregar, editar y eliminar promociones
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Incoviba\Controller\API\Ventas\Promotions;
|
||||
use PDOException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
@ -78,6 +80,58 @@ class Promotion extends Ideal\Service
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return Model\Venta\Promotion
|
||||
* @throws Exception\ServiceAction\Create
|
||||
*/
|
||||
public function add(array $data): Model\Venta\Promotion
|
||||
{
|
||||
try {
|
||||
$filteredData = $this->promotionRepository->filterData($data);
|
||||
#throw new \Exception(var_export($filteredData, true));
|
||||
$promotion = $this->promotionRepository->create($filteredData);
|
||||
#throw new \Exception(var_export($promotion, true));
|
||||
$promotion = $this->promotionRepository->save($promotion);
|
||||
return $this->process($promotion);
|
||||
} catch (PDOException $exception) {
|
||||
throw new Exception\ServiceAction\Create(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model\Venta\Promotion $promotion
|
||||
* @param array $data
|
||||
* @return Model\Venta\Promotion
|
||||
* @throws Exception\ServiceAction\Update
|
||||
*/
|
||||
public function edit(Model\Venta\Promotion $promotion, array $data): Model\Venta\Promotion
|
||||
{
|
||||
try {
|
||||
$filteredData = $this->promotionRepository->filterData($data);
|
||||
$promotion = $this->promotionRepository->edit($promotion, $filteredData);
|
||||
return $this->process($promotion);
|
||||
} catch (PDOException | Implement\Exception\EmptyResult $exception) {
|
||||
throw new Exception\ServiceAction\Update(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $promotion_id
|
||||
* @return Model\Venta\Promotion
|
||||
* @throws Exception\ServiceAction\Delete
|
||||
*/
|
||||
public function remove(int $promotion_id): Model\Venta\Promotion
|
||||
{
|
||||
try {
|
||||
$promotion = $this->promotionRepository->fetchById($promotion_id);
|
||||
$this->promotionRepository->remove($promotion);
|
||||
return $promotion;
|
||||
} catch (PDOException | Implement\Exception\EmptyResult $exception) {
|
||||
throw new Exception\ServiceAction\Delete(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function process(Model\Venta\Promotion $model): Model\Venta\Promotion
|
||||
{
|
||||
|
Reference in New Issue
Block a user