Add to response the list of serials with no warranties. #372
This commit is contained in:
parent
719cccf778
commit
135ab10cd3
2 changed files with 8 additions and 5 deletions
|
|
@ -142,7 +142,8 @@ class TestAPICommand extends Command
|
|||
// get warranties given list of serial numbers
|
||||
$serial_list = [
|
||||
'AJ34LJADR12134LKJM4',
|
||||
'AJ34LJADR12134LKJL5',
|
||||
'AJ34LJADR12134LKJL5',
|
||||
'test',
|
||||
];
|
||||
|
||||
$params = [
|
||||
|
|
|
|||
|
|
@ -523,20 +523,22 @@ class WarrantyController extends APIController
|
|||
return new APIResponse(false, 'Empty serial numbers list.');
|
||||
|
||||
$warranty_list = [];
|
||||
$warr_not_found_list = [];
|
||||
foreach ($serial_list as $serial)
|
||||
{
|
||||
$clean_serial = $this->cleanSerial($serial);
|
||||
$warr = $em->getRepository(Warranty::class)->findOneBy(['serial' => $clean_serial]);
|
||||
|
||||
if ($warr == null)
|
||||
return new APIResponse(false, 'No warranty found with that serial number.', null, 404);
|
||||
|
||||
$warranty_list[] = $this->generateWarrantyData($warr);
|
||||
$warr_not_found_list[] = 'Warranty not found for ' . $clean_serial;
|
||||
else
|
||||
$warranty_list[] = $this->generateWarrantyData($warr);
|
||||
}
|
||||
|
||||
|
||||
$data = [
|
||||
'warranties' => $warranty_list,
|
||||
'warranties_found' => $warranty_list,
|
||||
'warranties_not_found' => $warr_not_found_list,
|
||||
];
|
||||
|
||||
return new APIResponse(true, 'Warranties found.', $data);
|
||||
|
|
|
|||
Loading…
Reference in a new issue