remove schema from transformWhere
This commit is contained in:
@@ -106,7 +106,7 @@ describe('parseObjectToMongoObjectForCreate', () => {
|
|||||||
|
|
||||||
describe('transformWhere', () => {
|
describe('transformWhere', () => {
|
||||||
it('objectId', (done) => {
|
it('objectId', (done) => {
|
||||||
var out = transform.transformWhere(dummySchema, null, {objectId: 'foo'});
|
var out = transform.transformWhere(null, {objectId: 'foo'});
|
||||||
expect(out._id).toEqual('foo');
|
expect(out._id).toEqual('foo');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -115,7 +115,7 @@ describe('transformWhere', () => {
|
|||||||
var input = {
|
var input = {
|
||||||
objectId: {'$in': ['one', 'two', 'three']},
|
objectId: {'$in': ['one', 'two', 'three']},
|
||||||
};
|
};
|
||||||
var output = transform.transformWhere(dummySchema, null, input);
|
var output = transform.transformWhere(null, input);
|
||||||
jequal(input.objectId, output._id);
|
jequal(input.objectId, output._id);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -177,13 +177,7 @@ export class MongoStorageAdapter {
|
|||||||
deleteObjectsByQuery(className, query, schemaController, validate, parseFormatSchema) {
|
deleteObjectsByQuery(className, query, schemaController, validate, parseFormatSchema) {
|
||||||
return this.adaptiveCollection(className)
|
return this.adaptiveCollection(className)
|
||||||
.then(collection => {
|
.then(collection => {
|
||||||
let mongoWhere = transform.transformWhere(
|
let mongoWhere = transform.transformWhere(className, query, { validate }, parseFormatSchema);
|
||||||
schemaController,
|
|
||||||
className,
|
|
||||||
query,
|
|
||||||
{ validate },
|
|
||||||
parseFormatSchema
|
|
||||||
);
|
|
||||||
return collection.deleteMany(mongoWhere)
|
return collection.deleteMany(mongoWhere)
|
||||||
})
|
})
|
||||||
.then(({ result }) => {
|
.then(({ result }) => {
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ const valueAsDate = value => {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function transformQueryKeyValue(schema, className, key, value, { validate } = {}, parseFormatSchema) {
|
function transformQueryKeyValue(className, key, value, { validate } = {}, parseFormatSchema) {
|
||||||
switch(key) {
|
switch(key) {
|
||||||
case 'createdAt':
|
case 'createdAt':
|
||||||
if (valueAsDate(value)) {
|
if (valueAsDate(value)) {
|
||||||
@@ -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(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(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$/);
|
||||||
@@ -222,13 +222,13 @@ function transformQueryKeyValue(schema, className, key, value, { validate } = {}
|
|||||||
// restWhere is the "where" clause in REST API form.
|
// restWhere is the "where" clause in REST API form.
|
||||||
// Returns the mongo form of the query.
|
// Returns the mongo form of the query.
|
||||||
// Throws a Parse.Error if the input query is invalid.
|
// Throws a Parse.Error if the input query is invalid.
|
||||||
function transformWhere(schema, className, restWhere, { validate = true } = {}, parseFormatSchema) {
|
function transformWhere(className, restWhere, { validate = true } = {}, parseFormatSchema) {
|
||||||
let mongoWhere = {};
|
let mongoWhere = {};
|
||||||
if (restWhere['ACL']) {
|
if (restWhere['ACL']) {
|
||||||
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot query on ACL.');
|
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot query on ACL.');
|
||||||
}
|
}
|
||||||
for (let restKey in restWhere) {
|
for (let restKey in restWhere) {
|
||||||
let out = transformQueryKeyValue(schema, className, restKey, restWhere[restKey], { validate }, parseFormatSchema);
|
let out = transformQueryKeyValue(className, restKey, restWhere[restKey], { validate }, parseFormatSchema);
|
||||||
mongoWhere[out.key] = out.value;
|
mongoWhere[out.key] = out.value;
|
||||||
}
|
}
|
||||||
return mongoWhere;
|
return mongoWhere;
|
||||||
|
|||||||
@@ -184,13 +184,7 @@ DatabaseController.prototype.update = function(className, query, update, {
|
|||||||
throw error;
|
throw error;
|
||||||
})
|
})
|
||||||
.then(parseFormatSchema => {
|
.then(parseFormatSchema => {
|
||||||
var mongoWhere = this.transform.transformWhere(
|
var mongoWhere = this.transform.transformWhere(className, query, {validate: !this.skipValidation}, parseFormatSchema);
|
||||||
schemaController,
|
|
||||||
className,
|
|
||||||
query,
|
|
||||||
{validate: !this.skipValidation},
|
|
||||||
parseFormatSchema
|
|
||||||
);
|
|
||||||
mongoUpdate = this.transform.transformUpdate(
|
mongoUpdate = this.transform.transformUpdate(
|
||||||
schemaController,
|
schemaController,
|
||||||
className,
|
className,
|
||||||
@@ -664,7 +658,7 @@ DatabaseController.prototype.find = function(className, query, {
|
|||||||
throw error;
|
throw error;
|
||||||
})
|
})
|
||||||
.then(parseFormatSchema => {
|
.then(parseFormatSchema => {
|
||||||
let mongoWhere = this.transform.transformWhere(schemaController, className, query, {}, parseFormatSchema);
|
let mongoWhere = this.transform.transformWhere(className, query, {}, parseFormatSchema);
|
||||||
if (count) {
|
if (count) {
|
||||||
delete mongoOptions.limit;
|
delete mongoOptions.limit;
|
||||||
return collection.count(mongoWhere, mongoOptions);
|
return collection.count(mongoWhere, mongoOptions);
|
||||||
|
|||||||
Reference in New Issue
Block a user