@autofleet/sheilta 1.2.4 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/formatter/index.js
CHANGED
|
@@ -31,10 +31,12 @@ const formatInclude = (include, associationsMap = {}) => {
|
|
|
31
31
|
const formatQuery = (query, associationModels) => Object.keys(query).reduce((acc, queryItemKey) => (Object.assign(Object.assign({}, acc), { [utils_1.isAttributeByAssociation(queryItemKey, associationModels)
|
|
32
32
|
? utils_1.wrapAttributeWithOperator(queryItemKey) : queryItemKey]: query[queryItemKey] })), {});
|
|
33
33
|
const formatSearchTerm = (searchTerm, attributesToSend, rawAttributes) => ({
|
|
34
|
-
$
|
|
35
|
-
[
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
$and: searchTerm.split(' ').map(term => ({
|
|
35
|
+
$or: attributesToSend.filter(attrKey => rawAttributes[attrKey].type.key === 'STRING').map(attr => ({
|
|
36
|
+
[attr]: {
|
|
37
|
+
$iLike: `%${term}%`,
|
|
38
|
+
},
|
|
39
|
+
})),
|
|
38
40
|
})),
|
|
39
41
|
});
|
|
40
42
|
const formatPayload = ({ order, page = utils_1.PAGE_DEFAULT, perPage = utils_1.PER_PAGE_DEFAULT, include = [], query = {}, attributes = null, searchTerm = null, }, model) => {
|
|
@@ -65,13 +65,67 @@ describe('formatting test', () => {
|
|
|
65
65
|
});
|
|
66
66
|
expect(JSON.stringify(query)).toBe(JSON.stringify({
|
|
67
67
|
$and: [{ 'json.field': { $gt: 4 } }, {
|
|
68
|
-
$
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
$and: [{
|
|
69
|
+
$or: [
|
|
70
|
+
{
|
|
71
|
+
startTime: {
|
|
72
|
+
$iLike: `%${searchTerm}%`,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
}],
|
|
77
|
+
}],
|
|
78
|
+
}));
|
|
79
|
+
});
|
|
80
|
+
it('query with searchTerm with spaces', () => {
|
|
81
|
+
const searchTerm = 'aviv good guy';
|
|
82
|
+
const splitSearch = searchTerm.split(' ');
|
|
83
|
+
const { query } = _1.default({
|
|
84
|
+
order: [],
|
|
85
|
+
query: {
|
|
86
|
+
'json.field': {
|
|
87
|
+
$gt: 4,
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
searchTerm,
|
|
91
|
+
}, {
|
|
92
|
+
rawAttributes: {
|
|
93
|
+
startTime: {
|
|
94
|
+
type: {
|
|
95
|
+
key: 'STRING',
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
endTime: {
|
|
99
|
+
type: {
|
|
100
|
+
key: 'NUMBER',
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
expect(JSON.stringify(query)).toBe(JSON.stringify({
|
|
106
|
+
$and: [{ 'json.field': { $gt: 4 } }, {
|
|
107
|
+
$and: [{
|
|
108
|
+
$or: [
|
|
109
|
+
{
|
|
110
|
+
startTime: {
|
|
111
|
+
$iLike: `%${splitSearch[0]}%`,
|
|
112
|
+
},
|
|
113
|
+
}
|
|
114
|
+
],
|
|
115
|
+
}, {
|
|
116
|
+
$or: [{
|
|
117
|
+
startTime: {
|
|
118
|
+
$iLike: `%${splitSearch[1]}%`,
|
|
119
|
+
},
|
|
120
|
+
}],
|
|
73
121
|
},
|
|
74
|
-
|
|
122
|
+
{
|
|
123
|
+
$or: [{
|
|
124
|
+
startTime: {
|
|
125
|
+
$iLike: `%${splitSearch[2]}%`,
|
|
126
|
+
},
|
|
127
|
+
}],
|
|
128
|
+
}],
|
|
75
129
|
}],
|
|
76
130
|
}));
|
|
77
131
|
});
|
package/package.json
CHANGED