public static void CanReorder(ReorderFields command, Schema schema) { Guard.NotNull(command, nameof(command)); IArrayField?arrayField = null; if (command.ParentFieldId.HasValue) { arrayField = GuardHelper.GetArrayFieldOrThrow(schema, command.ParentFieldId.Value, false); } Validate.It(e => { if (command.FieldIds == null) { e(Not.Defined(nameof(command.FieldIds)), nameof(command.FieldIds)); } if (arrayField == null) { ValidateFieldIds(command, schema.FieldsById, e); } else { ValidateFieldIds(command, arrayField.FieldsById, e); } }); }
public static void CanAdd(AddField command, Schema schema) { Guard.NotNull(command, nameof(command)); Validate.It(e => { if (!command.Name.IsPropertyName()) { e(Not.ValidJavascriptName(nameof(command.Name)), nameof(command.Name)); } if (command.Properties == null) { e(Not.Defined(nameof(command.Properties)), nameof(command.Properties)); } else { var errors = FieldPropertiesValidator.Validate(command.Properties); errors.Foreach((x, _) => x.WithPrefix(nameof(command.Properties)).AddTo(e)); } if (command.ParentFieldId.HasValue) { var arrayField = GuardHelper.GetArrayFieldOrThrow(schema, command.ParentFieldId.Value, false); if (arrayField.FieldsByName.ContainsKey(command.Name)) { e(T.Get("schemas.fieldNameAlreadyExists")); } } else { if (command.ParentFieldId == null && !command.Partitioning.IsValidPartitioning()) { e(Not.Valid("Partitioning"), nameof(command.Partitioning)); } if (schema.FieldsByName.ContainsKey(command.Name)) { e(T.Get("schemas.fieldNameAlreadyExists")); } } }); }