Merge branch '250-invalidate-warranty-via-api' into 'master'

Resolve "Invalidate warranty via api"

Closes #250

See merge request jankstudio/resq!295
This commit is contained in:
Korina Cordero 2019-08-27 04:22:20 +00:00
commit f20fd4b44b
4 changed files with 73 additions and 1 deletions

View file

@ -73,9 +73,17 @@ class TestAPICommand extends Command
];
$api->post('/capi/warranties/' . $id . '/claim', $params);
// warranty cancel
$id = 86811;
$api->get('/capi/warranties/' . $id . '/cancel');
// plate warranty
$api->get('/capi/plates/' . $plate_num . '/warranties');
// warranty delete
$id = 86811;
$api->post('/capi/warranties/' . $id . '/delete');
// battery
$api->get('/capi/battery_brands');
$api->get('/capi/battery_sizes');

View file

@ -12,6 +12,10 @@ access_keys:
label: Register Battery
- id: warranty.claim
label: Claim
- id: warranty.cancel
label: Cancel
- id: warranty.delete
label: Delete
- id: batterybrand
label: Battery Brand Access
acls:

View file

@ -84,6 +84,18 @@ capi_warranty_get_all:
controller: App\Controller\CAPI\WarrantyController::getAll
methods: [GET]
# cancel warranty
capi_warranty_cancel:
path: /capi/warranties/{id}/cancel
controller: App\Controller\CAPI\WarrantyController::cancel
methods: [GET]
# delete warranty
capi_warranty_delete:
path: /capi/warranties/{id}/delete
controller: App\Controller\CAPI\WarrantyController::delete
methods: [POST]
# customer vehicle api

View file

@ -60,7 +60,6 @@ class WarrantyController extends APIController
'status' => (string) $warr->getStatus(),
'date_create' => (string) $warr->getDateCreate()->format('YmdHis'),
'date_purchase' => (string) $warr->getDatePurchase()->format('Ymd'),
'date_expire' => (string) $warr->getDateExpire()->format('Ymd'),
'flag_activated' => (boolean) $warr->isActivated(),
];
@ -70,6 +69,12 @@ class WarrantyController extends APIController
else
$data['date_claim'] = (string) $warr->getDateClaim()->format('Ymd');
$date_expire = $warr->getDateExpire();
if ($date_expire == null)
$data['date_expire'] = null;
else
$data['date_expire'] = (string) $warr->getDateExpire()->format('Ymd');
return $data;
}
@ -310,4 +315,47 @@ class WarrantyController extends APIController
return new APIResponse(true, 'Warranties loaded.', $data);
}
public function cancel(Request $req, EntityManagerInterface $em, $id)
{
$this->denyAccessUnlessGranted('warranty.cancel', 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);
}
if ($warr->getStatus() == WarrantyStatus::CANCELLED)
{
return new APIResponse(false, 'Warranty already cancelled.');
}
// set status to cancelled
$warr->setStatus(WarrantyStatus::CANCELLED);
$em->persist($warr);
$em->flush();
return new APIResponse(true, 'Warranty cancelled successfully.');
}
public function delete(EntityManagerInterface $em, $id)
{
$this->denyAccessUnlessGranted('warranty.delete', 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);
}
// delete the warranty
$em->remove($warr);
$em->flush();
return new APIResponse(true, 'Warranty deleted successfully.');
}
}