Skip to content

Commit

Permalink
Barcode scanner - improve reliability
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMikes committed May 12, 2024
1 parent 40ee985 commit 07ee4fb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion assets/controllers/barcode_scanner_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class extends Controller {
}

isValidEAN(barcode) {
return /^\d{7,}$/.test(barcode);
return /^\d{10,15}$/.test(barcode);
}

disconnect() {
Expand Down
6 changes: 4 additions & 2 deletions src/Query/GetPuzzleOverview.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public function byEan(string $ean): PuzzleOverview
throw new PuzzleNotFound();
}

$ean = ltrim($ean, '0');

$query = <<<SQL
SELECT
puzzle.id AS puzzle_id,
Expand All @@ -49,7 +51,7 @@ public function byEan(string $ean): PuzzleOverview
FROM puzzle
LEFT JOIN puzzle_solving_time ON puzzle_solving_time.puzzle_id = puzzle.id
INNER JOIN manufacturer ON puzzle.manufacturer_id = manufacturer.id
WHERE puzzle.ean = :ean
WHERE puzzle.ean LIKE :ean
GROUP BY puzzle.name, puzzle.pieces_count, manufacturer.name, manufacturer.id, puzzle.alternative_name, puzzle.id
SQL;

Expand Down Expand Up @@ -77,7 +79,7 @@ public function byEan(string $ean): PuzzleOverview
*/
$row = $this->database
->executeQuery($query, [
'ean' => $ean,
'ean' => '%' . $ean,
])
->fetchAssociative();

Expand Down

0 comments on commit 07ee4fb

Please sign in to comment.