Fix subscriptions bug
This commit is contained in:
parent
9278aaf89c
commit
9b73c29d04
|
@ -21,7 +21,7 @@ const LandingPage: React.FC = () => {
|
|||
</p>
|
||||
<div className="ButtonContainer">
|
||||
<Link to="/login" className="StyledLink">
|
||||
<button name="CreateAccount" className="StyledButton" onClick={handleSubscribeClick}>Create an Account</button>
|
||||
<button name="CreateAccount" className="StyledButton" onClick={handleSubscribeClick}>Create an Account or Log in</button>
|
||||
</Link>
|
||||
</div>
|
||||
<p className="Description">
|
||||
|
|
|
@ -40,5 +40,10 @@ def remove_subscription(db: Session, user_id: int, flight_id: int):
|
|||
db.commit()
|
||||
|
||||
|
||||
def remove_subscriptions(db: Session, user_id: int):
|
||||
db.query(Subscription).filter(Subscription.user_id == user_id).delete()
|
||||
db.commit()
|
||||
|
||||
|
||||
def send_subscriptions(db: Session, flight: FlightData):
|
||||
return db.query(Subscription).filter(Subscription.flight_id == flight.id).all()
|
||||
|
|
|
@ -14,6 +14,7 @@ from src.api.utils.messages import (
|
|||
get_flight_message,
|
||||
get_invalid_message,
|
||||
get_start_message,
|
||||
get_stop_message,
|
||||
)
|
||||
|
||||
router = APIRouter()
|
||||
|
@ -44,9 +45,14 @@ async def create_chat(
|
|||
background_tasks.add_task(telegram.send_message, chat_id, msg)
|
||||
elif action == "/stop":
|
||||
chat_id = str(message["chat"]["id"])
|
||||
user_id = notif_crud.get_user_from_chat(db=db, chat_id=chat_id).user_id
|
||||
subs_crud.remove_subscriptions(user_id)
|
||||
user = notif_crud.get_user_from_chat(db=db, chat_id=chat_id)
|
||||
if user is None:
|
||||
return Response(status_code=204)
|
||||
user_id = user.user_id
|
||||
subs_crud.remove_subscriptions(db=db, user_id=user_id)
|
||||
notif_crud.remove_chat(db=db, chat_id=chat_id)
|
||||
msg = get_stop_message(str(user_id))
|
||||
background_tasks.add_task(telegram.send_message, chat_id, msg)
|
||||
elif action == "/flight":
|
||||
chat_id = str(message["chat"]["id"])
|
||||
flight_id = int(message["text"].partition(" ")[2])
|
||||
|
|
|
@ -42,3 +42,7 @@ def get_start_message():
|
|||
"\n/flight NUMBER (e.g., /flight 1) for flight details"
|
||||
"\n/stop to stop receiving updates."
|
||||
)
|
||||
|
||||
|
||||
def get_stop_message(user_id):
|
||||
return f"You have successfully stopped receiving updates. Type /start {user_id} to resume updates."
|
||||
|
|
Loading…
Reference in New Issue