@@ -1489,9 +1489,6 @@ async function processQuery(
14891489 nextAnalysisDate . setDate (
14901490 nextAnalysisDate . getDate ( ) + ( query . frequency === "daily" ? 1 : 7 )
14911491 ) ;
1492-
1493- // Then set to midnight of that next day
1494- nextAnalysisDate . setHours ( 0 , 0 , 0 , 0 ) ;
14951492
14961493 console . log (
14971494 ` Updating Supabase for query ${
@@ -1744,13 +1741,20 @@ export async function POST(req: Request) {
17441741 mode_id : mode_id
17451742 } ) ;
17461743
1744+ // --- Calculate Next Analysis Date ---
1745+ const nextAnalysisDate = new Date ( ) ;
1746+ nextAnalysisDate . setDate (
1747+ nextAnalysisDate . getDate ( ) + ( frequency === "daily" ? 1 : 7 )
1748+ ) ;
17471749 // --- NOW Insert Query with Results ---
17481750 console . log ( `Inserting query "${ query } " with successful results for user ${ user_id } ` ) ;
1751+ console . log ( `Next analysis scheduled for: ${ nextAnalysisDate . toISOString ( ) } ` ) ;
17491752 sentryServer . logger . info ( `Inserting query "${ query } " with successful results for user ${ user_id } ` , {
17501753 log_source : 'schedule_query' ,
17511754 user_id : user_id ,
17521755 query_text : query ,
1753- mode_id : mode_id
1756+ mode_id : mode_id ,
1757+ next_analysis_at : nextAnalysisDate . toISOString ( )
17541758 } ) ;
17551759 const { data : newQueryData , error : insertError } = await supabase
17561760 . from ( "scheduled_queries" )
@@ -1760,8 +1764,8 @@ export async function POST(req: Request) {
17601764 mode : mode || null ,
17611765 user_id : user_id ,
17621766 mode_id : mode_id ,
1763- next_analysis_at : now ,
1764- last_analysis_at : now , // Set since we just analyzed it
1767+ next_analysis_at : nextAnalysisDate . toISOString ( ) , // ✅ Correctly calculated future date
1768+ last_analysis_at : now , // ✅ Set since we just analyzed it
17651769 status : "active" ,
17661770 location : location ,
17671771 results : [ initialAnalysis . newAnalysisRun ] , // Insert with actual results!
0 commit comments