@@ -34,18 +34,18 @@ class QueueService {
3434 throw new Error ( "Queue not found" ) ;
3535 }
3636 } ) ;
37-
37+
3838 const usersPromise = this . queues . doc ( queueId ) . collection ( "users" ) . get ( )
39- . then ( snapshot => {
40- const users = [ ] ;
41- snapshot . forEach ( doc => {
42- users . push ( doc . data ( ) )
43- } ) ;
44- return users ;
45- } )
46- . catch ( err => {
47- throw new Error ( 'Error getting users from queue' , err ) ;
39+ . then ( snapshot => {
40+ const users = [ ] ;
41+ snapshot . forEach ( doc => {
42+ users . push ( doc . data ( ) )
4843 } ) ;
44+ return users ;
45+ } )
46+ . catch ( err => {
47+ throw new Error ( 'Error getting users from queue' , err ) ;
48+ } ) ;
4949
5050 return {
5151 name : await namePromise ,
@@ -55,12 +55,17 @@ class QueueService {
5555
5656 addtoQueue ( name , contact , queueId ) {
5757 return this . queues . doc ( queueId )
58- . collection ( "users" )
59- . add ( { name : name , contact : contact } )
60- . then ( docRef => docRef . id )
61- . catch ( ( ) => console . log ( "Error adding to queue" ) ) ;
58+ . collection ( "users" ) . add ( {
59+ name : name , contact : contact , "timestamp" : firebase . firestore . Timestamp . now ( )
60+ } )
61+ . then ( docRef => docRef . id ) . catch ( ( ) => console . log ( "Error adding to queue" ) ) ;
6262
6363 }
64+ async userIndexQueue ( queueId , tokenId ) {
65+ const users = this . queues . doc ( queueId ) . collection ( "users" ) ;
66+ const timeStamp = await users . doc ( tokenId ) . get ( ) . then ( doc => doc . data ( ) . timestamp ) ;
67+ return users . where ( "timestamp" , "<" , timeStamp ) . get ( ) . then ( snapshot => snapshot . size ) ;
68+ }
6469}
6570
6671
0 commit comments