Skip to content

Commit

Permalink
fix: To reflect the UI choice of not showing pickup barcodes into the
Browse files Browse the repository at this point in the history
API. Pickup tasks will return `barcode: null`
  • Loading branch information
r0xsh committed Nov 20, 2024
1 parent e7adbae commit 7e294fd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
6 changes: 5 additions & 1 deletion src/Entity/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -1326,8 +1326,12 @@ public static function fixTimeWindow(Task $task)
/**
* @Groups({"barcode"})
*/
public function getBarcodes(): array
public function getBarcodes(): ?array
{
if ($this->getType() !== Task::TYPE_DROPOFF) {
return null;
}

$task_code = BarcodeUtils::getRawBarcodeFromTask($this);
$barcodes = [
'task' => [$task_code, BarcodeUtils::getToken($task_code)],
Expand Down
30 changes: 17 additions & 13 deletions src/Serializer/TaskNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,23 @@ public function normalize($object, $format = null, array $context = array())
}
}

$barcode = BarcodeUtils::getRawBarcodeFromTask($object);
$barcode_token = BarcodeUtils::getToken($barcode);
$data['barcode'] = [
'barcode' => $barcode,
'label' => [
'token' => $barcode_token,
'url' => $this->urlGenerator->generate(
'task_label_pdf',
['code' => $barcode, 'token' => $barcode_token],
UrlGeneratorInterface::ABSOLUTE_URL
)
]
];
if ($data['type'] === Task::TYPE_DROPOFF) {
$barcode = BarcodeUtils::getRawBarcodeFromTask($object);
$barcode_token = BarcodeUtils::getToken($barcode);
$data['barcode'] = [
'barcode' => $barcode,
'label' => [
'token' => $barcode_token,
'url' => $this->urlGenerator->generate(
'task_label_pdf',
['code' => $barcode, 'token' => $barcode_token],
UrlGeneratorInterface::ABSOLUTE_URL
)
]
];
} else {
$data['barcode'] = null;
}

if (!is_null($object->getPrefetchedPackagesAndWeight())) {
$data['packages'] = !is_null($object->getPrefetchedPackagesAndWeight()['packages']) ? $object->getPrefetchedPackagesAndWeight()['packages'] : [];
Expand Down

0 comments on commit 7e294fd

Please sign in to comment.