@@ -2,7 +2,12 @@ const express = require('express');
22
33const qr = require ( 'qr-image' ) ;
44
5- const { loadDatabase, searchDatabase } = require ( './googleSpreadsheet' ) ;
5+ const {
6+ loadDatabase,
7+ searchDatabase,
8+ addMarkdown,
9+ addSimilarItems,
10+ } = require ( './googleSpreadsheet' ) ;
611
712const app = express ( ) ;
813
@@ -56,20 +61,19 @@ app.get('/recent', (req, res) => {
5661
5762app . get ( '/:uuid' , ( req , res ) => {
5863 loadDatabase ( ( allItems ) => {
59- const matches = searchDatabase ( req . params , allItems ) ;
60- if ( matches . length === 0 ) {
64+ const match = searchDatabase ( req . params , allItems ) [ 0 ] ;
65+ if ( match . length === 0 ) {
6166 logScanned ( req . params . uuid ) ;
6267 res . status ( 404 ) . render ( 'notFound' , {
6368 item : '' ,
6469 id : req . params . uuid ,
6570 } ) ;
6671 return ;
6772 }
68- logScanned ( req . params . uuid , matches [ 0 ] . fixture ) ;
69- matches [ 0 ] . similarItems = searchDatabase ( { fixture : matches [ 0 ] . fixture } , allItems )
70- . filter ( item => item . uuid !== matches [ 0 ] . uuid )
71- . splice ( 0 , 3 ) ;
72- res . render ( 'item' , matches [ 0 ] ) ;
73+ addMarkdown ( match ) ;
74+ addSimilarItems ( match , allItems ) ;
75+ logScanned ( req . params . uuid , match . fixture ) ;
76+ res . render ( 'item' , match ) ;
7377 } ) ;
7478} ) ;
7579
0 commit comments