Skip to content

Commit

Permalink
better names and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
drew-gross committed Apr 26, 2016
1 parent 449ca11 commit 71ae7be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Adapters/Storage/Mongo/MongoStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class MongoStorageAdapter {
// If no objects match, reject with OBJECT_NOT_FOUND. If objects are found and deleted, resolve with undefined.
// If there is some other error, reject with INTERNAL_SERVER_ERROR.

// Currently accepts the validate for lecacy reasons. Currently accepts the schema, that may not actually be necessary.
// Currently accepts validate for legacy reasons. Currently accepts the schema, that may not actually be necessary.
deleteObjectsByQuery(className, query, validate, schema) {
return this.adaptiveCollection(className)
.then(collection => {
Expand Down
24 changes: 12 additions & 12 deletions src/Adapters/Storage/Mongo/MongoTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const valueAsDate = value => {
return false;
}

function transformQueryKeyValue(className, key, value, { validate } = {}, parseFormatSchema) {
function transformQueryKeyValue(className, key, value, { validate } = {}, schema) {
switch(key) {
case 'createdAt':
if (valueAsDate(value)) {
Expand Down Expand Up @@ -168,12 +168,12 @@ function transformQueryKeyValue(className, key, value, { validate } = {}, parseF
if (!(value instanceof Array)) {
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'bad $or format - use an array value');
}
return {key: '$or', value: value.map(subQuery => transformWhere(className, subQuery, {}, parseFormatSchema))};
return {key: '$or', value: value.map(subQuery => transformWhere(className, subQuery, {}, schema))};
case '$and':
if (!(value instanceof Array)) {
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'bad $and format - use an array value');
}
return {key: '$and', value: value.map(subQuery => transformWhere(className, subQuery, {}, parseFormatSchema))};
return {key: '$and', value: value.map(subQuery => transformWhere(className, subQuery, {}, schema))};
default:
// Other auth data
const authDataMatch = key.match(/^authData\.([a-zA-Z0-9_]+)\.id$/);
Expand All @@ -188,16 +188,16 @@ function transformQueryKeyValue(className, key, value, { validate } = {}, parseF
}

const expectedTypeIsArray =
parseFormatSchema &&
parseFormatSchema.fields[key] &&
parseFormatSchema.fields[key].type === 'Array';
schema &&
schema.fields[key] &&
schema.fields[key].type === 'Array';

const expectedTypeIsPointer =
parseFormatSchema &&
parseFormatSchema.fields[key] &&
parseFormatSchema.fields[key].type === 'Pointer';
schema &&
schema.fields[key] &&
schema.fields[key].type === 'Pointer';

if (expectedTypeIsPointer || !parseFormatSchema && value && value.__type === 'Pointer') {
if (expectedTypeIsPointer || !schema && value && value.__type === 'Pointer') {
key = '_p_' + key;
}

Expand All @@ -222,13 +222,13 @@ function transformQueryKeyValue(className, key, value, { validate } = {}, parseF
// restWhere is the "where" clause in REST API form.
// Returns the mongo form of the query.
// Throws a Parse.Error if the input query is invalid.
function transformWhere(className, restWhere, { validate = true } = {}, parseFormatSchema) {
function transformWhere(className, restWhere, { validate = true } = {}, schema) {
let mongoWhere = {};
if (restWhere['ACL']) {
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot query on ACL.');
}
for (let restKey in restWhere) {
let out = transformQueryKeyValue(className, restKey, restWhere[restKey], { validate }, parseFormatSchema);
let out = transformQueryKeyValue(className, restKey, restWhere[restKey], { validate }, schema);
mongoWhere[out.key] = out.value;
}
return mongoWhere;
Expand Down

0 comments on commit 71ae7be

Please sign in to comment.