feature/cierres (#30)
Reservas agregar y aprobar Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl> Reviewed-on: #30
This commit is contained in:
@ -11,7 +11,8 @@ class Reservations
|
||||
{
|
||||
use withJson;
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Reservation $reservationService): ResponseInterface
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Venta\Reservation $reservationService): ResponseInterface
|
||||
{
|
||||
$reservations = [];
|
||||
try {
|
||||
@ -22,6 +23,18 @@ class Reservations
|
||||
|
||||
return $this->withJson($response, compact('reservations'));
|
||||
}
|
||||
public function getByProject(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Venta\Reservation $reservationService, int $project_id): ResponseInterface
|
||||
{
|
||||
$reservations = [];
|
||||
try {
|
||||
$reservations = $reservationService->getByProject($project_id);
|
||||
} catch (ServiceAction\Read $exception) {
|
||||
return $this->withError($response, $exception);
|
||||
}
|
||||
|
||||
return $this->withJson($response, compact('reservations'));
|
||||
}
|
||||
public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Reservation $reservationService, int $reservation_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
@ -47,8 +60,8 @@ class Reservations
|
||||
'partial' => false,
|
||||
'errors' => [],
|
||||
];
|
||||
|
||||
try {
|
||||
var_dump($input);
|
||||
/*try {
|
||||
$output['reservations'] []= [
|
||||
'reservation' => $reservationService->add($input),
|
||||
'success' => true
|
||||
@ -56,7 +69,7 @@ class Reservations
|
||||
$output['partial'] = true;
|
||||
} catch (ServiceAction\Create $exception) {
|
||||
$output['errors'] []= $this->parseError($exception);
|
||||
}
|
||||
}*/
|
||||
|
||||
if (count($input['reservations']) === count($output['reservations'])) {
|
||||
$output['success'] = true;
|
||||
@ -64,6 +77,31 @@ class Reservations
|
||||
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function addOne(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Reservation $reservationService): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'reservation' => null,
|
||||
'success' => false,
|
||||
'errors' => [],
|
||||
];
|
||||
$data = [];
|
||||
foreach ($input as $key => $value) {
|
||||
if (!str_starts_with($key, 'add_')) {
|
||||
continue;
|
||||
}
|
||||
$data[substr($key, 4)] = $value;
|
||||
}
|
||||
try {
|
||||
$output['reservation'] = $reservationService->add($data);
|
||||
$output['success'] = true;
|
||||
} catch (ServiceAction\Create $exception) {
|
||||
$output['errors'] []= $this->parseError($exception);
|
||||
}
|
||||
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Reservation $reservationService, int $reservation_id): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
@ -100,4 +138,76 @@ class Reservations
|
||||
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
|
||||
public function active(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Venta\Reservation $reservationService, int $project_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'project_id' => $project_id,
|
||||
'reservations' => [],
|
||||
'success' => false,
|
||||
];
|
||||
try {
|
||||
$output['reservations'] = $reservationService->getActive($project_id);
|
||||
$output['success'] = true;
|
||||
} catch (ServiceAction\Read) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function pending(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Venta\Reservation $reservationService, int $project_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'project_id' => $project_id,
|
||||
'reservations' => [],
|
||||
'success' => false,
|
||||
];
|
||||
try {
|
||||
$output['reservations'] = $reservationService->getPending($project_id);
|
||||
$output['success'] = true;
|
||||
} catch (ServiceAction\Read) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function rejected(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Venta\Reservation $reservationService, int $project_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'project_id' => $project_id,
|
||||
'reservations' => [],
|
||||
'success' => false,
|
||||
];
|
||||
try {
|
||||
$output['reservations'] = $reservationService->getRejected($project_id);
|
||||
$output['success'] = true;
|
||||
} catch (ServiceAction\Read) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
|
||||
public function approve(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Venta\Reservation $reservationService, int $reservation_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'reservation_id' => $reservation_id,
|
||||
'success' => false,
|
||||
];
|
||||
try {
|
||||
$reservation = $reservationService->get($reservation_id);
|
||||
$reservationService->approve($reservation);
|
||||
$output['success'] = true;
|
||||
} catch (ServiceAction\Read | ServiceAction\Update) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function reject(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Venta\Reservation $reservationService, int $reservation_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'reservation_id' => $reservation_id,
|
||||
'success' => false,
|
||||
];
|
||||
try {
|
||||
$reservation = $reservationService->get($reservation_id);
|
||||
$reservationService->reject($reservation);
|
||||
$output['success'] = true;
|
||||
} catch (ServiceAction\Read | ServiceAction\Update) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user