Untitled
unknown
plain_text
16 days ago
3.1 kB
2
Indexable
Never
@mutation def create_field_details( self, info: Info, input: List[CreateFieldDetailsInput] ) -> CreateFieldDetailsMutationPayload: try: current_user = info.context.current_user.login created_field_details_ids = [] # Define default values field_detail_default = dict( field_format=None, validation_id=None, options=None, rcvd_from_reltio=None, is_dynamic="Y", is_active="Y", is_editable="Y", is_deleted=0, is_visible="Y", is_downstream="Y", is_published="Y", default_option="Y", created_date=datetime.now(), created_by=current_user, updated_by=current_user, ) for field_detail in input: # Merge default values with the input values merged_field_detail = {**field_detail_default, **field_detail.__dict__} new_field_detail = FieldDetails( label=merged_field_detail["label"], name=merged_field_detail["name"], type=merged_field_detail["type"], order=merged_field_detail["order"], field_format=merged_field_detail["field_format"], validation_id=merged_field_detail["validation_id"], options=merged_field_detail["options"], rcvd_from_reltio=merged_field_detail["rcvd_from_reltio"], is_dynamic=merged_field_detail["is_dynamic"], is_active=merged_field_detail["is_active"], is_editable=merged_field_detail["is_editable"], is_deleted=merged_field_detail["is_deleted"], is_visible=merged_field_detail["is_visible"], is_downstream=merged_field_detail["is_downstream"], is_published=merged_field_detail["is_published"], default_option=merged_field_detail["default_option"], created_date=merged_field_detail["created_date"], created_by=merged_field_detail["created_by"], updated_by=merged_field_detail["updated_by"], ) info.context.session.add(new_field_detail) info.context.session.flush() # Ensures the new field detail gets an ID before commit created_field_details_ids.append(new_field_detail.id) info.context.session.commit() created_field_details = ( info.context.session.query(FieldDetails) .filter(FieldDetails.id.in_(created_field_details_ids)) .all() ) return CreateFieldDetailsMutationPayload( field_details=created_field_details, success=True, message="Field details created successfully", ) except Exception as e: info.context.session.rollback() return CreateFieldDetailsMutationPayload( field_details=[], success=False, message=f"Creation failed: {str(e)}", )
Leave a Comment