@@ -11,15 +11,14 @@ export async function GET(request:Request, context: RoomCodeRouteContext){
1111 try {
1212 const client = await clientPromise ;
1313 const db = client . db ( "get_interval" ) ;
14-
14+ let result : any [ ] = [ ] ;
15+
1516 const results = await db . collection ( "result" ) . find ( { roomcode :context . params . roomcode } ) . limit ( 1 ) . toArray ( ) ;
16- let result = results [ 0 ] . result ;
17- console . log ( result ) ;
18-
19- if ( results . length === 0 ) {
17+
18+ if ( results . length === 0 ) {
2019 const rooms = await db . collection ( "rooms" ) . find ( { roomcode :context . params . roomcode } ) . limit ( 15 ) . toArray ( ) ;
2120
22- // console.log(rooms);
21+ console . log ( rooms ) ;
2322
2423 //to get all the intervals in a single array
2524 let intervals :any [ ] = [ [ ] ] ;
@@ -58,7 +57,6 @@ export async function GET(request:Request, context: RoomCodeRouteContext){
5857 // console.log(finalintervals);
5958
6059 //to get the free intervals
61- let result : any [ ] ;
6260 result = [ [ 0 , finalintervals [ 0 ] [ 0 ] ] ] ;
6361 for ( let i = 1 ; i < finalintervals . length ; i ++ ) {
6462 result [ i ] = [ finalintervals [ i - 1 ] [ 1 ] + 1 , finalintervals [ i ] [ 0 ] - 1 ] ;
@@ -69,6 +67,11 @@ export async function GET(request:Request, context: RoomCodeRouteContext){
6967 await db . collection ( "result" ) . insertOne ( { "roomcode" :context . params . roomcode , "result" :result } ) ;
7068 console . log ( "Saved Successfully!" ) ;
7169 }
70+ else {
71+ result = await results [ 0 ] . result ;
72+ console . log ( result ) ;
73+ }
74+
7275 return new Response ( JSON . stringify ( result ) , { status :200 } ) ;
7376 } catch ( error ) {
7477 return new Response ( "Failed to fetch the data, Try again later!!" , { status :500 } ) ;
0 commit comments