Add route for customer vehicle removal. Add call to get locations. #632
This commit is contained in:
parent
61b897d883
commit
ca3fbc21c8
3 changed files with 119 additions and 0 deletions
|
|
@ -205,3 +205,9 @@ api_locations:
|
|||
path: /api/locations
|
||||
controller: App\Controller\APIController::getLocations
|
||||
methods: [GET]
|
||||
|
||||
api_cust_vehicle_remove:
|
||||
path: /api/vehicles/{id}/remove
|
||||
controller: App\Controller\APIController::removeVehicle
|
||||
methods: [DELETE]
|
||||
|
||||
|
|
|
|||
|
|
@ -3648,6 +3648,7 @@ class APIController extends Controller implements LoggedController
|
|||
}
|
||||
else
|
||||
{
|
||||
// TODO: limit locations to 6. If more than 6, pop the first one out
|
||||
// add location to existing customer meta
|
||||
$c_meta->addMetaInfo($name, $loc_info);
|
||||
}
|
||||
|
|
@ -3655,7 +3656,40 @@ class APIController extends Controller implements LoggedController
|
|||
$em->flush();
|
||||
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
public function getLocations(Request $req)
|
||||
{
|
||||
$required_params = [];
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$res = $this->checkParamsAndKey($req, $em, $required_params);
|
||||
if ($res->isError())
|
||||
return $res->getReturnResponse();
|
||||
|
||||
// get customer
|
||||
$cust = $this->session->getCustomer();
|
||||
if ($cust == null)
|
||||
{
|
||||
$res->setError(true)
|
||||
->setErrorMessage('No customer information found');
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
// get the customer meta for customer
|
||||
$locations = [];
|
||||
$cust_meta = $em->getRepository(CustomerMetadata::class)->findOneBy(['customer' => $cust]);
|
||||
if ($cust_meta != null)
|
||||
{
|
||||
$locations[] = $cust_meta->getAllMetaInfo();
|
||||
}
|
||||
|
||||
$data = [
|
||||
'locations' => $locations,
|
||||
];
|
||||
|
||||
$res->setData($data);
|
||||
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
protected function updateWarranty($res, $em, $rt, $trans, $req, $serial, $inv_filename = null, $wcard_filename = null,
|
||||
|
|
|
|||
79
src/Entity/CustomerMetadata.php
Normal file
79
src/Entity/CustomerMetadata.php
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="customer_metadata")
|
||||
* @UniqueEntity("customer")
|
||||
*/
|
||||
|
||||
class CustomerMetadata
|
||||
{
|
||||
// unique id
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
// customer
|
||||
/**
|
||||
* @ORM\OneToOne(targetEntity="Customer")
|
||||
* @ORM\JoinColumn(name="customer_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $customer;
|
||||
|
||||
// other information, like locations
|
||||
/**
|
||||
* @ORM\Column(type="json")
|
||||
*/
|
||||
protected $meta_info;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->meta_info = [];
|
||||
}
|
||||
|
||||
public function getID()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setCustomer(Customer $customer)
|
||||
{
|
||||
$this->customer = $customer;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCustomer()
|
||||
{
|
||||
return $this->customer;
|
||||
}
|
||||
|
||||
public function addMetaInfo($id, $value)
|
||||
{
|
||||
$this->meta_info[$id] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMetaInfo($id)
|
||||
{
|
||||
// return null if we don't have it
|
||||
if (!isset($this->meta_info[$id]))
|
||||
return null;
|
||||
|
||||
return $this->meta_info[$id];
|
||||
}
|
||||
|
||||
public function getAllMetaInfo()
|
||||
{
|
||||
return $this->meta_info;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue