def delete(label_dict=None, raw=False): content = label_dict if label_dict else request.json user_id = label_dict["user_id"] if label_dict else get_jwt_identity() user = User.objects(id=user_id).first() task = Task.objects(id=content["task_id"]).first() if task in user.tasks: label = Label.objects(id=content["id"]).first() if label and label in task.labels: task.labels.remove(label) task.save() return (jsonify(), 200) if not raw else None abort(404)
def update(label_dict=None, raw=False): content = label_dict if label_dict else request.json user_id = label_dict["user_id"] if label_dict else get_jwt_identity() user = User.objects(id=user_id).first() task = Task.objects(id=content["task_id"]).first() if task in user.tasks: label = Label.objects(id=content["id"]).first() if label and label in task.labels: color = content.get("color", None) name = content.get("name", None) isthing = content.get("isthing", None) label.color = color if color is not None else label.color label.name = name if name is not None else label.name label.isthing = isthing if isthing is not None else label.isthing label.save() return (label.to_json(), 200) if not raw else label abort(404)