Skip to content

Commit d4bd21f

Browse files
committed
remove schema from transformWhere
1 parent a926712 commit d4bd21f

File tree

4 files changed

+10
-22
lines changed

4 files changed

+10
-22
lines changed

spec/MongoTransform.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ describe('parseObjectToMongoObjectForCreate', () => {
106106

107107
describe('transformWhere', () => {
108108
it('objectId', (done) => {
109-
var out = transform.transformWhere(dummySchema, null, {objectId: 'foo'});
109+
var out = transform.transformWhere(null, {objectId: 'foo'});
110110
expect(out._id).toEqual('foo');
111111
done();
112112
});
@@ -115,7 +115,7 @@ describe('transformWhere', () => {
115115
var input = {
116116
objectId: {'$in': ['one', 'two', 'three']},
117117
};
118-
var output = transform.transformWhere(dummySchema, null, input);
118+
var output = transform.transformWhere(null, input);
119119
jequal(input.objectId, output._id);
120120
done();
121121
});

src/Adapters/Storage/Mongo/MongoStorageAdapter.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,7 @@ export class MongoStorageAdapter {
177177
deleteObjectsByQuery(className, query, schemaController, validate, parseFormatSchema) {
178178
return this.adaptiveCollection(className)
179179
.then(collection => {
180-
let mongoWhere = transform.transformWhere(
181-
schemaController,
182-
className,
183-
query,
184-
{ validate },
185-
parseFormatSchema
186-
);
180+
let mongoWhere = transform.transformWhere(className, query, { validate }, parseFormatSchema);
187181
return collection.deleteMany(mongoWhere)
188182
})
189183
.then(({ result }) => {

src/Adapters/Storage/Mongo/MongoTransform.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ const valueAsDate = value => {
139139
return false;
140140
}
141141

142-
function transformQueryKeyValue(schema, className, key, value, { validate } = {}, parseFormatSchema) {
142+
function transformQueryKeyValue(className, key, value, { validate } = {}, parseFormatSchema) {
143143
switch(key) {
144144
case 'createdAt':
145145
if (valueAsDate(value)) {
@@ -168,12 +168,12 @@ function transformQueryKeyValue(schema, className, key, value, { validate } = {}
168168
if (!(value instanceof Array)) {
169169
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'bad $or format - use an array value');
170170
}
171-
return {key: '$or', value: value.map(subQuery => transformWhere(schema, className, subQuery, {}, parseFormatSchema))};
171+
return {key: '$or', value: value.map(subQuery => transformWhere(className, subQuery, {}, parseFormatSchema))};
172172
case '$and':
173173
if (!(value instanceof Array)) {
174174
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'bad $and format - use an array value');
175175
}
176-
return {key: '$and', value: value.map(subQuery => transformWhere(schema, className, subQuery, {}, parseFormatSchema))};
176+
return {key: '$and', value: value.map(subQuery => transformWhere(className, subQuery, {}, parseFormatSchema))};
177177
default:
178178
// Other auth data
179179
const authDataMatch = key.match(/^authData\.([a-zA-Z0-9_]+)\.id$/);
@@ -222,13 +222,13 @@ function transformQueryKeyValue(schema, className, key, value, { validate } = {}
222222
// restWhere is the "where" clause in REST API form.
223223
// Returns the mongo form of the query.
224224
// Throws a Parse.Error if the input query is invalid.
225-
function transformWhere(schema, className, restWhere, { validate = true } = {}, parseFormatSchema) {
225+
function transformWhere(className, restWhere, { validate = true } = {}, parseFormatSchema) {
226226
let mongoWhere = {};
227227
if (restWhere['ACL']) {
228228
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot query on ACL.');
229229
}
230230
for (let restKey in restWhere) {
231-
let out = transformQueryKeyValue(schema, className, restKey, restWhere[restKey], { validate }, parseFormatSchema);
231+
let out = transformQueryKeyValue(className, restKey, restWhere[restKey], { validate }, parseFormatSchema);
232232
mongoWhere[out.key] = out.value;
233233
}
234234
return mongoWhere;

src/Controllers/DatabaseController.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,7 @@ DatabaseController.prototype.update = function(className, query, update, {
184184
throw error;
185185
})
186186
.then(parseFormatSchema => {
187-
var mongoWhere = this.transform.transformWhere(
188-
schemaController,
189-
className,
190-
query,
191-
{validate: !this.skipValidation},
192-
parseFormatSchema
193-
);
187+
var mongoWhere = this.transform.transformWhere(className, query, {validate: !this.skipValidation}, parseFormatSchema);
194188
mongoUpdate = this.transform.transformUpdate(
195189
schemaController,
196190
className,
@@ -664,7 +658,7 @@ DatabaseController.prototype.find = function(className, query, {
664658
throw error;
665659
})
666660
.then(parseFormatSchema => {
667-
let mongoWhere = this.transform.transformWhere(schemaController, className, query, {}, parseFormatSchema);
661+
let mongoWhere = this.transform.transformWhere(className, query, {}, parseFormatSchema);
668662
if (count) {
669663
delete mongoOptions.limit;
670664
return collection.count(mongoWhere, mongoOptions);

0 commit comments

Comments
 (0)