fix webhook bug

This commit is contained in:
hay-kot 2021-03-15 16:36:40 -08:00
commit 54b93bf1dd
2 changed files with 16 additions and 13 deletions

View file

@ -63,18 +63,17 @@ def get_todays_meal(session: Session, group: Union[int, GroupInDB]) -> Recipe:
if isinstance(group, int):
group: GroupInDB = db.groups.get(session, group)
if group.webhook_enable:
today_slug = None
today_slug = None
for mealplan in group.mealplans:
mealplan: MealPlanInDB
for meal in mealplan.meals:
meal: MealOut
if meal.date == date.today():
today_slug = meal.slug
break
for mealplan in group.mealplans:
mealplan: MealPlanInDB
for meal in mealplan.meals:
meal: MealOut
if meal.date == date.today():
today_slug = meal.slug
break
if today_slug:
return db.recipes.get(session, today_slug)
else:
return None
if today_slug:
return db.recipes.get(session, today_slug)
else:
return None

View file

@ -9,6 +9,10 @@ from sqlalchemy.orm.session import Session
def post_webhooks(group: int, session: Session = None):
session = session if session else create_session()
group_settings: GroupInDB = db.groups.get(session, group)
if not group_settings.webhook_enable:
return
todays_recipe = get_todays_meal(session, group)
if not todays_recipe: