Add to response the list of serials with no warranties. #372

This commit is contained in:
Korina Cordero 2020-04-02 03:58:21 +00:00
parent 719cccf778
commit 135ab10cd3
2 changed files with 8 additions and 5 deletions

View file

@ -143,6 +143,7 @@ class TestAPICommand extends Command
$serial_list = [ $serial_list = [
'AJ34LJADR12134LKJM4', 'AJ34LJADR12134LKJM4',
'AJ34LJADR12134LKJL5', 'AJ34LJADR12134LKJL5',
'test',
]; ];
$params = [ $params = [

View file

@ -523,20 +523,22 @@ class WarrantyController extends APIController
return new APIResponse(false, 'Empty serial numbers list.'); return new APIResponse(false, 'Empty serial numbers list.');
$warranty_list = []; $warranty_list = [];
$warr_not_found_list = [];
foreach ($serial_list as $serial) foreach ($serial_list as $serial)
{ {
$clean_serial = $this->cleanSerial($serial); $clean_serial = $this->cleanSerial($serial);
$warr = $em->getRepository(Warranty::class)->findOneBy(['serial' => $clean_serial]); $warr = $em->getRepository(Warranty::class)->findOneBy(['serial' => $clean_serial]);
if ($warr == null) if ($warr == null)
return new APIResponse(false, 'No warranty found with that serial number.', null, 404); $warr_not_found_list[] = 'Warranty not found for ' . $clean_serial;
else
$warranty_list[] = $this->generateWarrantyData($warr); $warranty_list[] = $this->generateWarrantyData($warr);
} }
$data = [ $data = [
'warranties' => $warranty_list, 'warranties_found' => $warranty_list,
'warranties_not_found' => $warr_not_found_list,
]; ];
return new APIResponse(true, 'Warranties found.', $data); return new APIResponse(true, 'Warranties found.', $data);