Fix some stuff
This commit is contained in:
@@ -67,8 +67,8 @@ const validateQuery = query => {
|
||||
}
|
||||
|
||||
Object.keys(query).forEach(key => {
|
||||
if (query[key].$regex) {
|
||||
if (typeof query[key].$options === 'string') {g
|
||||
if (query && query[key] && query[key].$regex) {
|
||||
if (typeof query[key].$options === 'string') {
|
||||
if (!query[key].$options.match(/^[imxs]+$/)) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_QUERY, `Bad $options value for query: ${query[key].$options}`);
|
||||
}
|
||||
@@ -764,7 +764,7 @@ DatabaseController.prototype.deleteSchema = function(className) {
|
||||
})
|
||||
.then(schema => {
|
||||
return this.collectionExists(className)
|
||||
.then(exist => this.adapter.count(className))
|
||||
.then(exist => this.adapter.count(className, { fields: {} }))
|
||||
.then(count => {
|
||||
if (count > 0) {
|
||||
throw new Parse.Error(255, `Class ${className} is not empty, contains ${count} objects, cannot drop schema.`);
|
||||
|
||||
@@ -234,6 +234,20 @@ const convertSchemaToAdapterSchema = schema => {
|
||||
return schema;
|
||||
}
|
||||
|
||||
const convertAdapterSchemaToParseSchema = ({...schema}) => {
|
||||
delete schema.fields._rperm;
|
||||
delete schema.fields._wperm;
|
||||
|
||||
schema.fields.ACL = { type: 'ACL' };
|
||||
|
||||
if (schema.className === '_User') {
|
||||
delete schema.fields._hashed_password;
|
||||
schema.fields.password = { type: 'String' };
|
||||
}
|
||||
|
||||
return schema;
|
||||
}
|
||||
|
||||
const injectDefaultSchema = schema => ({
|
||||
className: schema.className,
|
||||
fields: {
|
||||
@@ -316,6 +330,7 @@ class SchemaController {
|
||||
}
|
||||
|
||||
return this._dbAdapter.createClass(className, convertSchemaToAdapterSchema({ fields, classLevelPermissions, className }))
|
||||
.then(convertAdapterSchemaToParseSchema)
|
||||
.catch(error => {
|
||||
if (error && error.code === Parse.Error.DUPLICATE_VALUE) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, `Class ${className} already exists.`);
|
||||
@@ -342,6 +357,8 @@ class SchemaController {
|
||||
}
|
||||
});
|
||||
|
||||
delete existingFields._rperm;
|
||||
delete existingFields._wperm;
|
||||
let newSchema = buildMergedSchemaObject(existingFields, submittedFields);
|
||||
let validationError = this.validateSchemaData(className, newSchema, classLevelPermissions);
|
||||
if (validationError) {
|
||||
|
||||
Reference in New Issue
Block a user