Skip to content

Commit 522d44f

Browse files
committed
Adds ability to override CLP op from RestQuery.execute
1 parent af7336e commit 522d44f

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/Controllers/DatabaseController.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -711,10 +711,10 @@ DatabaseController.prototype.find = function(className, query, {
711711
acl,
712712
sort = {},
713713
count,
714-
} = {}) {
714+
} = {}, op) {
715715
let isMaster = acl === undefined;
716716
let aclGroup = acl || [];
717-
let op = typeof query.objectId == 'string' && Object.keys(query).length === 1 ? 'get' : 'find';
717+
op = op || (typeof query.objectId == 'string' && Object.keys(query).length === 1 ? 'get' : 'find');
718718
let classExists = true;
719719
return this.loadSchema()
720720
.then(schemaController => {

src/RestQuery.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ function RestQuery(config, auth, className, restWhere = {}, restOptions = {}, cl
111111
// Returns a promise for the response - an object with optional keys
112112
// 'results' and 'count'.
113113
// TODO: consolidate the replaceX functions
114-
RestQuery.prototype.execute = function() {
114+
RestQuery.prototype.execute = function(executeOptions) {
115115
return Promise.resolve().then(() => {
116116
return this.buildRestWhere();
117117
}).then(() => {
118-
return this.runFind();
118+
return this.runFind(executeOptions);
119119
}).then(() => {
120120
return this.runCount();
121121
}).then(() => {
@@ -385,13 +385,13 @@ RestQuery.prototype.replaceDontSelect = function() {
385385

386386
// Returns a promise for whether it was successful.
387387
// Populates this.response with an object that only has 'results'.
388-
RestQuery.prototype.runFind = function() {
388+
RestQuery.prototype.runFind = function(options = {}) {
389389
if (this.findOptions.limit === 0) {
390390
this.response = {results: []};
391391
return Promise.resolve();
392392
}
393393
return this.config.database.find(
394-
this.className, this.restWhere, this.findOptions).then((results) => {
394+
this.className, this.restWhere, this.findOptions, options.op).then((results) => {
395395
if (this.className === '_User') {
396396
for (var result of results) {
397397
delete result.password;
@@ -479,23 +479,22 @@ function includePath(config, auth, response, path) {
479479
return response;
480480
}
481481
let pointersHash = {};
482-
var objectIds = {};
483482
for (var pointer of pointers) {
484483
if (!pointer) {
485484
continue;
486485
}
487486
let className = pointer.className;
488487
// only include the good pointers
489488
if (className) {
490-
pointersHash[className] = pointersHash[className] || [];
491-
pointersHash[className].push(pointer.objectId);
489+
pointersHash[className] = pointersHash[className] || new Set();
490+
pointersHash[className].add(pointer.objectId);
492491
}
493492
}
494493

495494
let queryPromises = Object.keys(pointersHash).map((className) => {
496-
var where = {'objectId': {'$in': pointersHash[className]}};
495+
let where = {'objectId': {'$in': Array.from(pointersHash[className])}};
497496
var query = new RestQuery(config, auth, className, where);
498-
return query.execute().then((results) => {
497+
return query.execute({op: 'get'}).then((results) => {
499498
results.className = className;
500499
return Promise.resolve(results);
501500
})

0 commit comments

Comments
 (0)