Makes sure pointer includes are interpolated as get (#2747)
* test for repro #2005 * Adds ability to override CLP op from RestQuery.execute * nits
This commit is contained in:
@@ -113,11 +113,11 @@ function RestQuery(config, auth, className, restWhere = {}, restOptions = {}, cl
|
||||
// Returns a promise for the response - an object with optional keys
|
||||
// 'results' and 'count'.
|
||||
// TODO: consolidate the replaceX functions
|
||||
RestQuery.prototype.execute = function() {
|
||||
RestQuery.prototype.execute = function(executeOptions) {
|
||||
return Promise.resolve().then(() => {
|
||||
return this.buildRestWhere();
|
||||
}).then(() => {
|
||||
return this.runFind();
|
||||
return this.runFind(executeOptions);
|
||||
}).then(() => {
|
||||
return this.runCount();
|
||||
}).then(() => {
|
||||
@@ -387,18 +387,22 @@ RestQuery.prototype.replaceDontSelect = function() {
|
||||
|
||||
// Returns a promise for whether it was successful.
|
||||
// Populates this.response with an object that only has 'results'.
|
||||
RestQuery.prototype.runFind = function() {
|
||||
RestQuery.prototype.runFind = function(options = {}) {
|
||||
if (this.findOptions.limit === 0) {
|
||||
this.response = {results: []};
|
||||
return Promise.resolve();
|
||||
}
|
||||
let findOptions = Object.assign({}, this.findOptions);
|
||||
if (this.keys) {
|
||||
this.findOptions.keys = Array.from(this.keys).map((key) => {
|
||||
findOptions.keys = Array.from(this.keys).map((key) => {
|
||||
return key.split('.')[0];
|
||||
});
|
||||
}
|
||||
if (options.op) {
|
||||
findOptions.op = options.op;
|
||||
}
|
||||
return this.config.database.find(
|
||||
this.className, this.restWhere, this.findOptions).then((results) => {
|
||||
this.className, this.restWhere, findOptions).then((results) => {
|
||||
if (this.className === '_User') {
|
||||
for (var result of results) {
|
||||
delete result.password;
|
||||
@@ -473,7 +477,6 @@ function includePath(config, auth, response, path, restOptions = {}) {
|
||||
return response;
|
||||
}
|
||||
let pointersHash = {};
|
||||
var objectIds = {};
|
||||
for (var pointer of pointers) {
|
||||
if (!pointer) {
|
||||
continue;
|
||||
@@ -481,8 +484,8 @@ function includePath(config, auth, response, path, restOptions = {}) {
|
||||
let className = pointer.className;
|
||||
// only include the good pointers
|
||||
if (className) {
|
||||
pointersHash[className] = pointersHash[className] || [];
|
||||
pointersHash[className].push(pointer.objectId);
|
||||
pointersHash[className] = pointersHash[className] || new Set();
|
||||
pointersHash[className].add(pointer.objectId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -504,9 +507,9 @@ function includePath(config, auth, response, path, restOptions = {}) {
|
||||
}
|
||||
|
||||
let queryPromises = Object.keys(pointersHash).map((className) => {
|
||||
var where = {'objectId': {'$in': pointersHash[className]}};
|
||||
let where = {'objectId': {'$in': Array.from(pointersHash[className])}};
|
||||
var query = new RestQuery(config, auth, className, where, includeRestOptions);
|
||||
return query.execute().then((results) => {
|
||||
return query.execute({op: 'get'}).then((results) => {
|
||||
results.className = className;
|
||||
return Promise.resolve(results);
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user