Untitled
unknown
plain_text
25 days ago
3.2 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 = [] for field_detail in input: new_field_detail = FieldDetails( label=field_detail.label, name=field_detail.name, type=field_detail.type, order=field_detail.order, field_format=field_detail.field_format if field_detail.field_format else None, validation_id=field_detail.validation_id if field_detail.validation_id else None, options=field_detail.options if field_detail.options else None, rcvd_from_reltio=field_detail.rcvd_from_reltio if field_detail.rcvd_from_reltio else None, is_dynamic=field_detail.is_dynamic if field_detail.is_dynamic else "Y", is_active=field_detail.is_active if field_detail.is_active else "Y", is_editable=field_detail.is_editable if field_detail.is_editable else "Y", is_deleted=0, is_visible=field_detail.is_visible if field_detail.is_visible else "Y", is_downstream=field_detail.is_downstream if field_detail.is_downstream else "Y", is_published=field_detail.is_published if field_detail.is_published else "Y", default_option=field_detail.default_option if field_detail.default_option else "Y", created_date=datetime.now(), created_by=current_user, updated_by=current_user, ) 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