Added rest option: excludeKeys (#5737)
* Added restOption: excludeKeys * improve tests
This commit is contained in:
committed by
Diamond Lewis
parent
378e70afdc
commit
9816285205
@@ -13,6 +13,7 @@ const AlwaysSelectedKeys = ['objectId', 'createdAt', 'updatedAt', 'ACL'];
|
||||
// count
|
||||
// include
|
||||
// keys
|
||||
// excludeKeys
|
||||
// redirectClassNameForKey
|
||||
// readPreference
|
||||
// includeReadPreference
|
||||
@@ -102,6 +103,13 @@ function RestQuery(
|
||||
this.keys = Array.from(new Set(keys));
|
||||
break;
|
||||
}
|
||||
case 'excludeKeys': {
|
||||
const exclude = restOptions.excludeKeys
|
||||
.split(',')
|
||||
.filter(k => AlwaysSelectedKeys.indexOf(k) < 0);
|
||||
this.excludeKeys = Array.from(new Set(exclude));
|
||||
break;
|
||||
}
|
||||
case 'count':
|
||||
this.doCount = true;
|
||||
break;
|
||||
@@ -184,6 +192,9 @@ RestQuery.prototype.execute = function(executeOptions) {
|
||||
.then(() => {
|
||||
return this.handleIncludeAll();
|
||||
})
|
||||
.then(() => {
|
||||
return this.handleExcludeKeys();
|
||||
})
|
||||
.then(() => {
|
||||
return this.runFind(executeOptions);
|
||||
})
|
||||
@@ -705,6 +716,24 @@ RestQuery.prototype.handleIncludeAll = function() {
|
||||
});
|
||||
};
|
||||
|
||||
// Updates property `this.keys` to contain all keys but the ones unselected.
|
||||
RestQuery.prototype.handleExcludeKeys = function() {
|
||||
if (!this.excludeKeys) {
|
||||
return;
|
||||
}
|
||||
if (this.keys) {
|
||||
this.keys = this.keys.filter(k => !this.excludeKeys.includes(k));
|
||||
return;
|
||||
}
|
||||
return this.config.database
|
||||
.loadSchema()
|
||||
.then(schemaController => schemaController.getOneSchema(this.className))
|
||||
.then(schema => {
|
||||
const fields = Object.keys(schema.fields);
|
||||
this.keys = fields.filter(k => !this.excludeKeys.includes(k));
|
||||
});
|
||||
};
|
||||
|
||||
// Augments this.response with data at the paths provided in this.include.
|
||||
RestQuery.prototype.handleInclude = function() {
|
||||
if (this.include.length == 0) {
|
||||
|
||||
Reference in New Issue
Block a user