generateAcqSearch(searchType, filters): any {
const baseSearch = JSON.parse(JSON.stringify(defaultSearch[searchType])); // deep copy
+ const coreRecType = Object.keys(defaultSearch[searchType])[0];
+
+ // handle grid filters
+ // note that date filters coming from the grid do not need
+ // to worry about __castdate because the grid filter supplies
+ // both the start and end times
Object.keys(filters).forEach(filterField => {
- const searchTerm: Object = {};
- const coreRecType = Object.keys(defaultSearch[searchType])[0];
- let filterOp = "=";
- let filterVal = "";
- if (Object.keys(filters[filterField][0]).some(x => x === "-not")) {
- filterOp = Object.keys(filters[filterField][0]["-not"][filterField])[0];
- filterVal = filters[filterField][0]["-not"][filterField][filterOp];
- searchTerm["__not"] = true;
- } else {
- filterOp = Object.keys(filters[filterField][0][filterField])[0];
- filterVal = filters[filterField][0][filterField][filterOp];
- if (filterOp === "like" && filterVal.length > 1) {
- if (filterVal[0] === "%" && filterVal[filterVal.length - 1] === "%") {
- filterVal = filterVal.slice(1, filterVal.length - 1);
- } else if (filterVal[filterVal.length - 1] === "%") {
- filterVal = filterVal.slice(0, filterVal.length - 1);
- filterOp = "startswith";
- } else if (filterVal[0] === "%") {
- filterVal = filterVal.slice(1);
- filterOp = "endswith";
+ filters[filterField].forEach(condition => {
+ const searchTerm: Object = {};
+ let filterOp = "=";
+ let filterVal = "";
+ if (Object.keys(condition).some(x => x === "-not")) {
+ filterOp = Object.keys(condition["-not"][filterField])[0];
+ filterVal = condition["-not"][filterField][filterOp];
+ searchTerm["__not"] = true;
+ } else {
+ filterOp = Object.keys(condition[filterField])[0];
+ filterVal = condition[filterField][filterOp];
+ if (filterOp === "like" && filterVal.length > 1) {
+ if (filterVal[0] === "%" && filterVal[filterVal.length - 1] === "%") {
+ filterVal = filterVal.slice(1, filterVal.length - 1);
+ } else if (filterVal[filterVal.length - 1] === "%") {
+ filterVal = filterVal.slice(0, filterVal.length - 1);
+ filterOp = "startswith";
+ } else if (filterVal[0] === "%") {
+ filterVal = filterVal.slice(1);
+ filterOp = "endswith";
+ }
}
}
- }
- searchTerm[filterField] = filterVal;
- if (filterOp in operatorMap) {
- searchTerm[operatorMap[filterOp]] = true;
- }
- baseSearch[coreRecType].push(searchTerm);
+ searchTerm[filterField] = filterVal;
+ if (filterOp in operatorMap) {
+ searchTerm[operatorMap[filterOp]] = true;
+ }
+ baseSearch[coreRecType].push(searchTerm);
+ });
});
console.debug(baseSearch);
return baseSearch;