Fix battery info endpoint to work with warranty serials instead #783
This commit is contained in:
parent
8860796db2
commit
eebd1d93c4
1 changed files with 19 additions and 16 deletions
|
|
@ -24,7 +24,8 @@ use App\Entity\RiderAPISession;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use App\Entity\ApiUser as APIUser;
|
use App\Entity\ApiUser as APIUser;
|
||||||
use App\Entity\JobOrder;
|
use App\Entity\JobOrder;
|
||||||
|
use App\Entity\SAPBattery;
|
||||||
|
use App\Entity\WarrantySerial;
|
||||||
use App\Service\RedisClientProvider;
|
use App\Service\RedisClientProvider;
|
||||||
use App\Service\RiderCache;
|
use App\Service\RiderCache;
|
||||||
use App\Service\MQTTClient;
|
use App\Service\MQTTClient;
|
||||||
|
|
@ -1174,26 +1175,28 @@ class RiderAppController extends ApiController
|
||||||
return new APIResponse(false, 'No rider found.');
|
return new APIResponse(false, 'No rider found.');
|
||||||
|
|
||||||
// find battery given serial/sap_code and flag_active is true
|
// find battery given serial/sap_code and flag_active is true
|
||||||
$batts = $em->getRepository(Battery::class)->findBy(['flag_active' => true, 'sap_code' => $serial]);
|
$serial = $em->getRepository(WarrantySerial::class)->find($serial);
|
||||||
|
|
||||||
$batt_data = [];
|
if (empty($serial)) {
|
||||||
foreach ($batts as $batt)
|
return new APIResponse(false, 'Warranty serial number not found.');
|
||||||
{
|
|
||||||
$batt_data[] = [
|
|
||||||
'id' => $batt->getID(),
|
|
||||||
'model_id' => $batt->getModel()->getID(),
|
|
||||||
'model_name' => $batt->getModel()->getName(),
|
|
||||||
'size_id' => $batt->getSize()->getID(),
|
|
||||||
'size_name' => $batt->getSize()->getName(),
|
|
||||||
'selling_price' => $batt->getSellingPrice(),
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = [
|
$sap_battery = $em->getRepository(SAPBattery::class)->find($serial->getSKU());
|
||||||
'batteries' => $batt_data,
|
|
||||||
|
if (empty($sap_battery)) {
|
||||||
|
return new APIResponse(false, 'No battery info found.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$battery = [
|
||||||
|
'id' => $sap_battery->getID(),
|
||||||
|
'brand' => $sap_battery->getBrand()->getName(),
|
||||||
|
'size' => $sap_battery->getSize()->getName(),
|
||||||
|
'container_size' => $sap_battery->getContainerSize()->getName(),
|
||||||
];
|
];
|
||||||
|
|
||||||
return new APIResponse(true, 'Battery info found.', $data);
|
return new APIResponse(true, 'Battery info found.', [
|
||||||
|
'battery' => $battery,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateJobOrder(Request $req, EntityManagerInterface $em, InvoiceGeneratorInterface $ic)
|
public function updateJobOrder(Request $req, EntityManagerInterface $em, InvoiceGeneratorInterface $ic)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue