@@ -816,9 +816,6 @@ def get_strategy_notifications():
816816 user_strategy_ids = [r .get ('id' ) for r in rows if r .get ('id' )]
817817 cur .close ()
818818
819- if not user_strategy_ids :
820- return jsonify ({'code' : 1 , 'msg' : 'success' , 'data' : {'items' : []}})
821-
822819 where = []
823820 args = []
824821
@@ -830,9 +827,15 @@ def get_strategy_notifications():
830827 else :
831828 return jsonify ({'code' : 1 , 'msg' : 'success' , 'data' : {'items' : []}})
832829 else :
833- placeholders = "," .join (["?" ] * len (user_strategy_ids ))
834- where .append (f"strategy_id IN ({ placeholders } )" )
835- args .extend (user_strategy_ids )
830+ if user_strategy_ids :
831+ placeholders = "," .join (["?" ] * len (user_strategy_ids ))
832+ where .append (f"(strategy_id IN ({ placeholders } ) OR (strategy_id IS NULL AND user_id = ?))" )
833+ args .extend (user_strategy_ids )
834+ args .append (user_id )
835+ else :
836+ # Only portfolio monitor notifications (strategy_id is NULL)
837+ where .append ("strategy_id IS NULL AND user_id = ?" )
838+ args .append (user_id )
836839
837840 if since_id :
838841 where .append ("id > ?" )
@@ -889,15 +892,18 @@ def mark_notification_read():
889892 if not notification_id :
890893 return jsonify ({'code' : 0 , 'msg' : 'Missing id' }), 400
891894
892- # Only update notifications for user's strategies
895+ # Update notifications for user's strategies OR portfolio monitor notifications
893896 with get_db_connection () as db :
894897 cur = db .cursor ()
895898 cur .execute (
896899 """
897900 UPDATE qd_strategy_notifications SET is_read = 1
898- WHERE id = ? AND strategy_id IN (SELECT id FROM qd_strategies_trading WHERE user_id = ?)
901+ WHERE id = ? AND (
902+ strategy_id IN (SELECT id FROM qd_strategies_trading WHERE user_id = ?)
903+ OR (strategy_id IS NULL AND user_id = ?)
904+ )
899905 """ ,
900- (int (notification_id ), user_id )
906+ (int (notification_id ), user_id , user_id )
901907 )
902908 db .commit ()
903909 cur .close ()
@@ -920,8 +926,9 @@ def mark_all_notifications_read():
920926 """
921927 UPDATE qd_strategy_notifications SET is_read = 1
922928 WHERE strategy_id IN (SELECT id FROM qd_strategies_trading WHERE user_id = ?)
929+ OR (strategy_id IS NULL AND user_id = ?)
923930 """ ,
924- (user_id ,)
931+ (user_id , user_id )
925932 )
926933 db .commit ()
927934 cur .close ()
@@ -944,8 +951,9 @@ def clear_notifications():
944951 """
945952 DELETE FROM qd_strategy_notifications
946953 WHERE strategy_id IN (SELECT id FROM qd_strategies_trading WHERE user_id = ?)
954+ OR (strategy_id IS NULL AND user_id = ?)
947955 """ ,
948- (user_id ,)
956+ (user_id , user_id )
949957 )
950958 db .commit ()
951959 cur .close ()
0 commit comments