Clearer names in DatabaseController

This commit is contained in:
Drew Gross
2016-04-25 22:12:03 -07:00
parent 5cbf3eb8dd
commit 608cba9e8c

View File

@@ -598,56 +598,48 @@ DatabaseController.prototype.find = function(className, query, {
} }
let isMaster = acl === undefined; let isMaster = acl === undefined;
let aclGroup = acl || []; let aclGroup = acl || [];
let schema = null; let op = typeof query.objectId == 'string' && Object.keys(query).length === 1 ? 'get' : 'find';
let op = typeof query.objectId == 'string' && Object.keys(query).length === 1 ? return this.loadSchema()
'get' : .then(schemaController => {
'find';
return this.loadSchema().then(s => {
schema = s;
if (sort) { if (sort) {
mongoOptions.sort = {}; mongoOptions.sort = {};
for (let key in sort) { for (let key in sort) {
let mongoKey = this.transform.transformKey(schema, className, key); let mongoKey = this.transform.transformKey(schemaController, className, key);
mongoOptions.sort[mongoKey] = sort[key]; mongoOptions.sort[mongoKey] = sort[key];
} }
} }
return (isMaster ? Promise.resolve() : schemaController.validatePermission(className, aclGroup, op))
if (!isMaster) { .then(() => this.reduceRelationKeys(className, query))
return schema.validatePermission(className, aclGroup, op); .then(() => this.reduceInRelation(className, query, schemaController))
} .then(() => this.adapter.adaptiveCollection(className))
return Promise.resolve(); .then(collection => {
}) if (!isMaster) {
.then(() => this.reduceRelationKeys(className, query)) query = this.addPointerPermissions(schemaController, className, op, query, aclGroup);
.then(() => this.reduceInRelation(className, query, schema))
.then(() => this.adapter.adaptiveCollection(className))
.then(collection => {
if (!isMaster) {
query = this.addPointerPermissions(schema, className, op, query, aclGroup);
}
if (!query) {
if (op == 'get') {
return Promise.reject(new Parse.Error(Parse.Error.OBJECT_NOT_FOUND,
'Object not found.'));
} else {
return Promise.resolve([]);
} }
} if (!query) {
if (!isMaster) { if (op == 'get') {
query = addReadACL(query, aclGroup); return Promise.reject(new Parse.Error(Parse.Error.OBJECT_NOT_FOUND,
} 'Object not found.'));
let mongoWhere = this.transform.transformWhere(schema, className, query); } else {
if (count) { return Promise.resolve([]);
delete mongoOptions.limit; }
return collection.count(mongoWhere, mongoOptions); }
} else { if (!isMaster) {
return collection.find(mongoWhere, mongoOptions) query = addReadACL(query, aclGroup);
}
let mongoWhere = this.transform.transformWhere(schemaController, className, query);
if (count) {
delete mongoOptions.limit;
return collection.count(mongoWhere, mongoOptions);
} else {
return collection.find(mongoWhere, mongoOptions)
.then((mongoResults) => { .then((mongoResults) => {
return mongoResults.map((r) => { return mongoResults.map((r) => {
return this.untransformObject( return this.untransformObject(schemaController, isMaster, aclGroup, className, r);
schema, isMaster, aclGroup, className, r);
}); });
}); });
} }
});
}); });
}; };