Fix battery info endpoint to work with warranty serials instead #783

This commit is contained in:
Ramon Gutierrez 2024-02-08 23:17:32 +08:00
parent 8860796db2
commit eebd1d93c4

View file

@ -24,7 +24,8 @@ use App\Entity\RiderAPISession;
use App\Entity\User;
use App\Entity\ApiUser as APIUser;
use App\Entity\JobOrder;
use App\Entity\SAPBattery;
use App\Entity\WarrantySerial;
use App\Service\RedisClientProvider;
use App\Service\RiderCache;
use App\Service\MQTTClient;
@ -1174,26 +1175,28 @@ class RiderAppController extends ApiController
return new APIResponse(false, 'No rider found.');
// 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 = [];
foreach ($batts as $batt)
{
$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(),
];
if (empty($serial)) {
return new APIResponse(false, 'Warranty serial number not found.');
}
$data = [
'batteries' => $batt_data,
$sap_battery = $em->getRepository(SAPBattery::class)->find($serial->getSKU());
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)