def add_row(data, request): try: payload, status = decode_token(request) if status != 200: return {"status": "User not found."}, 404 user_id = payload.get("sub") record = UserWorkflows.add_record(data, user_id) _save_changes(record) return {"id": record.id, "status": "success"}, 201 except IntegrityError as e: return _error_handler("POST", "/user_workflows", e, 500)
def update_row(id, data, request): try: row = UserWorkflows.query.filter_by(id=id, active=True).first() if not row: return {"status": "No object found!"}, 404 payload, status = decode_token(request) if status != 200: return {"status": "User not found."}, 404 user_id = payload.get("sub") UserWorkflows.update_record(row, data, user_id) db.session.commit() return {"status": "Record update successfully"}, 200 except Exception as e: return _error_handler("PUT", "/user_workflows/" + str(id), e, 500)
def delete_row(id, request): row = Workflows.query.filter_by(id=id, active=True).first() if not row: return {"status": "No object found!"}, 404 payload, status = decode_token(request) if status != 200: return {"status": "User not found."}, 404 user_id = payload.get("sub") for details in row.workflow_details: details.last_modified_by = user_id details.active = False row.active = False row.last_modified_by = user_id db.session.commit() return {"status": "Workflow Deleted successfully"}, 200
def update_row(id, data, request): try: row = Workflows.query.filter_by(id=id, active=True).first() if not row: return {"status": "No object found!"}, 404 payload, status = decode_token(request) if status != 200: return {"status": "User not found."}, 404 user_id = payload.get("sub") parsed_data = {} for lang_data in _generate_details(data): parsed_data[lang_data['language']] = lang_data for workflow_detail in row.workflow_details: language_name = workflow_detail.language.name if language_name in data.keys(): WorkflowDetails.update_record(workflow_detail, parsed_data[language_name], user_id) db.session.commit() return {"status": "Record update successfully"}, 200 except Exception as e: return _error_handler("GET", "/workflows/"+str(id), e, 500)