- def undo(self, chore_id):
- with Session(self.engine) as session:
- cmd = select(Chore).where(Chore.id == chore_id)
- chore = session.exec(cmd).first()
-
- if(not chore):
- return f'Not found: {chore_id}'
-
- try:
- cmd = select(Record).where(Record.chore_id == chore_id).where(Record.complete_date >= today())
- results = session.exec(cmd).all()
- for result in results:
- session.delete(result)
- session.commit()
- return f'Marked chore as *not* done: {chore.name}.'
- except Exception as ex:
- return f'Unable to mark chore as done: {ex}'
-
- def remove(self, chore_id):
- try:
- with Session(self.engine) as session:
- chore = get_chore(session, chore_id)
- if(not chore):
- return f'Chore not found: {chore_id}'
-
- sql = text('''
- DELETE FROM Record
- WHERE chore_id = :chore_id
- ''')
- params = {}
- params['chore_id'] = chore_id
- results = session.execute(sql, params)
- logger.debug(results)
- sql = text('''
- DELETE FROM Chore
- WHERE id = :chore_id
- ''')
- results = session.execute(sql, params)
- logger.debug(results)
- session.commit()
- return f'Removed chore {chore_id}'
- except Exception as ex:
- return f'Unable to remove chore: {ex}'