Start using parse format schema in transformQueryKeyValue
This commit is contained in:
@@ -124,7 +124,6 @@ describe('SchemaController', () => {
|
|||||||
var obj;
|
var obj;
|
||||||
createTestUser()
|
createTestUser()
|
||||||
.then(user => {
|
.then(user => {
|
||||||
console.log(user);
|
|
||||||
return config.database.loadSchema()
|
return config.database.loadSchema()
|
||||||
// Create a valid class
|
// Create a valid class
|
||||||
.then(schema => schema.validateObject('Stuff', {foo: 'bar'}))
|
.then(schema => schema.validateObject('Stuff', {foo: 'bar'}))
|
||||||
|
|||||||
@@ -168,12 +168,12 @@ function transformQueryKeyValue(schema, className, key, value, { validate } = {}
|
|||||||
if (!(value instanceof Array)) {
|
if (!(value instanceof Array)) {
|
||||||
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'bad $or format - use an array value');
|
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'bad $or format - use an array value');
|
||||||
}
|
}
|
||||||
return {key: '$or', value: value.map(subQuery => transformWhere(schema, className, subQuery, parseFormatSchema))};
|
return {key: '$or', value: value.map(subQuery => transformWhere(schema, className, subQuery, {}, parseFormatSchema))};
|
||||||
case '$and':
|
case '$and':
|
||||||
if (!(value instanceof Array)) {
|
if (!(value instanceof Array)) {
|
||||||
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'bad $and format - use an array value');
|
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'bad $and format - use an array value');
|
||||||
}
|
}
|
||||||
return {key: '$and', value: value.map(subQuery => transformWhere(schema, className, subQuery, parseFormatSchema))};
|
return {key: '$and', value: value.map(subQuery => transformWhere(schema, className, subQuery, {}, parseFormatSchema))};
|
||||||
default:
|
default:
|
||||||
// Other auth data
|
// Other auth data
|
||||||
const authDataMatch = key.match(/^authData\.([a-zA-Z0-9_]+)\.id$/);
|
const authDataMatch = key.match(/^authData\.([a-zA-Z0-9_]+)\.id$/);
|
||||||
@@ -187,18 +187,19 @@ function transformQueryKeyValue(schema, className, key, value, { validate } = {}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let expected = undefined;
|
|
||||||
if (schema && schema.getExpectedType) {
|
|
||||||
expected = schema.getExpectedType(className, key);
|
|
||||||
}
|
|
||||||
if ((expected && expected.type == 'Pointer') ||
|
|
||||||
(!expected && value && value.__type == 'Pointer')) {
|
|
||||||
key = '_p_' + key;
|
|
||||||
}
|
|
||||||
const expectedTypeIsArray =
|
const expectedTypeIsArray =
|
||||||
parseFormatSchema &&
|
parseFormatSchema &&
|
||||||
parseFormatSchema.fields[key] &&
|
parseFormatSchema.fields[key] &&
|
||||||
parseFormatSchema.fields[key].type === 'Array'
|
parseFormatSchema.fields[key].type === 'Array';
|
||||||
|
|
||||||
|
const expectedTypeIsPointer =
|
||||||
|
parseFormatSchema &&
|
||||||
|
parseFormatSchema.fields[key] &&
|
||||||
|
parseFormatSchema.fields[key].type === 'Pointer';
|
||||||
|
|
||||||
|
if (expectedTypeIsPointer || !parseFormatSchema && value && value.__type === 'Pointer') {
|
||||||
|
key = '_p_' + key;
|
||||||
|
}
|
||||||
|
|
||||||
// Handle query constraints
|
// Handle query constraints
|
||||||
if (transformConstraint(value, expectedTypeIsArray) !== CannotTransform) {
|
if (transformConstraint(value, expectedTypeIsArray) !== CannotTransform) {
|
||||||
|
|||||||
Reference in New Issue
Block a user