Merge branch '256-privacy-policy-for-warranty' into 'master'

Resolve "Privacy policy for warranty"

Closes #256

See merge request jankstudio/resq!304
This commit is contained in:
Kendrick Chan 2019-08-30 01:53:34 +00:00
commit 4f95933742
6 changed files with 84 additions and 5 deletions

View file

@ -80,6 +80,14 @@ class TestAPICommand extends Command
];
$api->post('/capi/warranties/'. $id, $params);
// warranty set privacy policy
$id = 86811;
$policy_id = 2;
$params = [
'privacy_policy_id' => $policy_id,
];
$api->post('/capi/warranties/' . $id .'/privacypolicy', $params);
// warranty claim
$id = 86811;
$serial = 'AJ34LJADR12134LKJL5';

View file

@ -24,7 +24,8 @@ abstract class APIController extends Controller
else
{
$check = $req->request->get($param);
if (empty($check))
//if (empty($check))
if (!isset($check))
$missing[] = $param;
}
}

View file

@ -102,6 +102,12 @@ capi_warranty_delete:
controller: App\Controller\CAPI\WarrantyController::delete
methods: [POST]
# set privacy policy of warranty
capi_warranty_privacy_policy:
path: /capi/warranties/{id}/privacypolicy
controller: App\Controller\CAPI\WarrantyController::setPrivacyPolicy
methods: [POST]
# customer vehicle api
# find customer vehicle by id

View file

@ -49,7 +49,7 @@ use App\Entity\PrivacyPolicy;
use DateTime;
use Exception;
// mobile API
class APIController extends Controller
{
protected $session;

View file

@ -16,6 +16,7 @@ use App\Entity\BatterySize;
use App\Entity\SAPBattery;
use App\Entity\SAPBatterySize;
use App\Entity\SAPBatteryBrand;
use App\Entity\PrivacyPolicy;
use App\Ramcar\NameValue;
use App\Ramcar\WarrantyClass;
@ -24,6 +25,7 @@ use DateTime;
use Catalyst\APIBundle\Access\Generator as ACLGenerator;
// third party API
class WarrantyController extends APIController
{
protected $acl_gen;
@ -445,4 +447,50 @@ class WarrantyController extends APIController
return new APIResponse(true, 'Warranty deleted successfully.');
}
public function setPrivacyPolicy(Request $req, EntityManagerInterface $em, $id)
{
$this->denyAccessUnlessGranted('warranty.set.privacypolicy', null, 'No access.');
// find warranty
$warr = $em->getRepository(Warranty::class)->find($id);
if ($warr == null)
{
return new APIResponse(false, 'No warranty found with that id.', null, 404);
}
$params = [
'privacy_policy_id',
];
$msg = $this->checkRequiredParameters($req, $params);
error_log('msg - ' . $msg);
if ($msg)
return new APIResponse(false, $msg);
$privacy_policy_id = $req->request->get('privacy_policy_id');
if ($privacy_policy_id == 0)
{
$warr->setPrivacyPolicy(null);
}
else
{
// find privacy policy
$privacy_policy = $em->getRepository(PrivacyPolicy::class)->find($privacy_policy_id);
if ($privacy_policy == null)
{
return new APIResponse(false, 'No privacy policy found with that id.', null, 404);
}
// set privacy policy of warranty
$warr->setPrivacyPolicy($privacy_policy);
}
$em->persist($warr);
$em->flush();
return new APIResponse(true, 'Privacy policy for warranty set successfully.');
}
}

View file

@ -48,6 +48,16 @@ class PrivacyPolicy
*/
protected $cust_promo;
/**
* @ORM\OneToMany(targetEntity="Warranty", mappedBy="privacy_policy")
*/
protected $warranties;
public function __construct()
{
$this->warranties = new ArrayCollection();
}
public function getID()
{
return $this->id;
@ -108,9 +118,15 @@ class PrivacyPolicy
return $this->cust_promo;
}
public function addWarranty(Warranty $warranty)
{
$this->warranties[] = $warranty;
return $this;
}
public function getWarrantiess()
{
return $this->warranties;
}
}