Skip to content

Commit 608cba9

Browse files
committed
Clearer names in DatabaseController
1 parent 5cbf3eb commit 608cba9

File tree

1 file changed

+31
-39
lines changed

1 file changed

+31
-39
lines changed

src/Controllers/DatabaseController.js

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -598,56 +598,48 @@ DatabaseController.prototype.find = function(className, query, {
598598
}
599599
let isMaster = acl === undefined;
600600
let aclGroup = acl || [];
601-
let schema = null;
602-
let op = typeof query.objectId == 'string' && Object.keys(query).length === 1 ?
603-
'get' :
604-
'find';
605-
return this.loadSchema().then(s => {
606-
schema = s;
601+
let op = typeof query.objectId == 'string' && Object.keys(query).length === 1 ? 'get' : 'find';
602+
return this.loadSchema()
603+
.then(schemaController => {
607604
if (sort) {
608605
mongoOptions.sort = {};
609606
for (let key in sort) {
610-
let mongoKey = this.transform.transformKey(schema, className, key);
607+
let mongoKey = this.transform.transformKey(schemaController, className, key);
611608
mongoOptions.sort[mongoKey] = sort[key];
612609
}
613610
}
614-
615-
if (!isMaster) {
616-
return schema.validatePermission(className, aclGroup, op);
617-
}
618-
return Promise.resolve();
619-
})
620-
.then(() => this.reduceRelationKeys(className, query))
621-
.then(() => this.reduceInRelation(className, query, schema))
622-
.then(() => this.adapter.adaptiveCollection(className))
623-
.then(collection => {
624-
if (!isMaster) {
625-
query = this.addPointerPermissions(schema, className, op, query, aclGroup);
626-
}
627-
if (!query) {
628-
if (op == 'get') {
629-
return Promise.reject(new Parse.Error(Parse.Error.OBJECT_NOT_FOUND,
630-
'Object not found.'));
631-
} else {
632-
return Promise.resolve([]);
611+
return (isMaster ? Promise.resolve() : schemaController.validatePermission(className, aclGroup, op))
612+
.then(() => this.reduceRelationKeys(className, query))
613+
.then(() => this.reduceInRelation(className, query, schemaController))
614+
.then(() => this.adapter.adaptiveCollection(className))
615+
.then(collection => {
616+
if (!isMaster) {
617+
query = this.addPointerPermissions(schemaController, className, op, query, aclGroup);
633618
}
634-
}
635-
if (!isMaster) {
636-
query = addReadACL(query, aclGroup);
637-
}
638-
let mongoWhere = this.transform.transformWhere(schema, className, query);
639-
if (count) {
640-
delete mongoOptions.limit;
641-
return collection.count(mongoWhere, mongoOptions);
642-
} else {
643-
return collection.find(mongoWhere, mongoOptions)
619+
if (!query) {
620+
if (op == 'get') {
621+
return Promise.reject(new Parse.Error(Parse.Error.OBJECT_NOT_FOUND,
622+
'Object not found.'));
623+
} else {
624+
return Promise.resolve([]);
625+
}
626+
}
627+
if (!isMaster) {
628+
query = addReadACL(query, aclGroup);
629+
}
630+
let mongoWhere = this.transform.transformWhere(schemaController, className, query);
631+
if (count) {
632+
delete mongoOptions.limit;
633+
return collection.count(mongoWhere, mongoOptions);
634+
} else {
635+
return collection.find(mongoWhere, mongoOptions)
644636
.then((mongoResults) => {
645637
return mongoResults.map((r) => {
646-
return this.untransformObject(
647-
schema, isMaster, aclGroup, className, r);
638+
return this.untransformObject(schemaController, isMaster, aclGroup, className, r);
648639
});
649640
});
650-
}
641+
}
642+
});
651643
});
652644
};
653645

0 commit comments

Comments
 (0)