@@ -6,17 +6,21 @@ const { loadDatabase, searchDatabase } = require('./googleSpreadsheet');
66
77const app = express ( ) ;
88
9- const recentScans = {
10- assigned : [ ] ,
11- unassigned : [ ] ,
12- } ;
9+ const allScans = [ ] ;
1310
14- const date = new Date ( ) ;
15- const minutes = ( date . getMinutes ( ) < 10 ? '0' : '' ) + date . getMinutes ( ) ;
16- const hour = date . getHours ( ) ;
17- const dayOfWeek = date . getDay ( ) ;
18- const week = [ 'Sunday' , 'Monday' , 'Tuesday' , 'Wednesday' , 'Thursday' , 'Friday' , 'Saturday' , 'Sunday' ] ;
19- const scanTime = week [ dayOfWeek ] + ' ' + hour + ':' + minutes ;
11+ function logScanned ( uuid , fixture ) {
12+ // TRICK: fixture tells if the the uuid was found in database or not
13+ if ( ! / ^ [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 12 } $ / i. test ( uuid ) ) {
14+ return ;
15+ }
16+ const now = new Date ( ) ;
17+ if ( ! fixture ) {
18+ allScans . unshift ( { time : now , status : 'missing' , uuid } ) ;
19+ return ;
20+ }
21+ allScans . map ( item => item . status = ( item . uuid === uuid ) ? 'fixed' : item . status ) ;
22+ allScans . unshift ( { time : now , fixture, uuid } ) ;
23+ }
2024
2125app . set ( 'view engine' , 'ejs' ) ;
2226
@@ -47,21 +51,21 @@ app.get('/qrlist', (req, res) => {
4751} ) ;
4852
4953app . get ( '/recent' , ( req , res ) => {
50- res . render ( 'recent' , { data : recentScans } ) ;
54+ res . render ( 'recent' , { allScans } ) ;
5155} ) ;
5256
5357app . get ( '/:uuid' , ( req , res ) => {
5458 loadDatabase ( ( allItems ) => {
5559 const matches = searchDatabase ( req . params , allItems ) ;
5660 if ( matches . length === 0 ) {
57- recentScans . unassigned . push ( [ scanTime , req . params . uuid ] ) ;
61+ logScanned ( req . params . uuid ) ;
5862 res . render ( 'notFound' , {
5963 item : '' ,
6064 id : req . params . uuid ,
6165 } ) ;
6266 return ;
6367 }
64- recentScans . assigned . push ( [ scanTime , matches [ 0 ] . fixture , req . params . uuid ] ) ;
68+ logScanned ( req . params . uuid , matches [ 0 ] . fixture ) ;
6569 matches . similarItems = searchDatabase ( { fixture : matches [ 0 ] . fixture } , allItems )
6670 . filter ( item => item . uuid !== matches [ 0 ] . uuid )
6771 . splice ( 0 , 3 ) ;
0 commit comments