Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filters-parsers update to allow filters on smart fields with belongsTo reference #803

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/services/filters-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ function FiltersParser(modelSchema, timezone, options) {

this.formatCondition = async (condition) => {
const isTextField = this.isTextField(condition.field);

if (this.isSmartField(modelSchema, condition.field)) {
const fieldFound = modelSchema.fields.find((field) => field.field === condition.field);
const fieldFound = modelSchema.fields.find(function (field) {
return (!!field.isVirtual && field.field === condition.field) || (!!field.reference && field.field === condition.field.split(':')[0]);
});

if (!fieldFound.filter) throw new Error(`"filter" method missing on smart field "${fieldFound.field}"`);

Expand Down Expand Up @@ -123,7 +126,9 @@ function FiltersParser(modelSchema, timezone, options) {
};

this.isSmartField = (schema, fieldName) => {
const fieldFound = schema.fields.find((field) => field.field === fieldName);
const fieldFound = schema.fields.find(function (field) {
return (!!field.isVirtual && field.field === fieldName) || (!!field.reference && field.field === fieldName.split(':')[0]);
});
return !!fieldFound && !!fieldFound.isVirtual;
};

Expand Down