From e7efa530719265bdb9434af49f62340d294534e6 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sun, 7 Feb 2021 16:33:48 +0100 Subject: [PATCH] [Plugin] Schedule: Allow retraction of service --- flaschengeist/plugins/schedule/event_controller.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/flaschengeist/plugins/schedule/event_controller.py b/flaschengeist/plugins/schedule/event_controller.py index da72d98..dbc829d 100644 --- a/flaschengeist/plugins/schedule/event_controller.py +++ b/flaschengeist/plugins/schedule/event_controller.py @@ -169,9 +169,14 @@ def delete_job(job: Job): def assign_to_job(job: Job, user, value): service = Service.query.get((job.id, user._id)) - if service: - service.value = value + if value < 0: + if not service: + raise BadRequest + db.session.delete(service) else: - service = Service(user_=user, value=value, job_=job) - db.session.add(service) + if service: + service.value = value + else: + service = Service(user_=user, value=value, job_=job) + db.session.add(service) db.session.commit()