fix: 🐛 quick-serialize records before applying boolean filter

This commit is contained in:
Randall Morey committed 2021-10-21 09:08:50 -04:00
1 parent 71108c3509
commit 0c20ccfde0
2 files changed
+21 -2

No files matched your search

+2 -1
View File
@@ -438,8 +438,9 @@ export default function () {
sessionModel?.scope?.scope?.id === scope_id
);
});
} else {
resultSet = sessions.where((session) => session.scopeId === scope_id);
}
resultSet = sessions.where((session) => session.scopeId === scope_id);
return resultSet.filter(makeBooleanFilter(filter));
}
);
+19 -1
View File
@@ -1,4 +1,19 @@
import { makeEvaluator } from 'js-bexpr';
import { underscore } from '@ember/string';
/**
* Because Mirage, a record cannot be serialized outside of a route handler
* context. Here is a quick and dirty attempt to serialize attribute names
* to underscore format. This is not entirely realistic, but may suffice.
*/
const quickSerialize = (item) => {
const json = item.toJSON();
Object.keys(json).forEach((key) => {
const newKey = underscore(key);
json[newKey] = json[key];
});
return json;
};
/**
* Creates a filter function that operates on a single object, which itself
@@ -8,7 +23,10 @@ export default (expression) => {
if (expression) {
const evaluator = makeEvaluator(expression);
// Since API query selectors begin with `/item`, the instance is wrapped.
return (item) => evaluator({ item });
return (item) => {
const json = quickSerialize(item);
return evaluator({ item: json });
};
} else {
// If no expression was passed, always return true,
// thus filtering out none.