Skip to content

Commit

Permalink
🔧 fix(filter)
Browse files Browse the repository at this point in the history
- добавление возможности указазывать значение фильтра как undefined
  • Loading branch information
wmakeev committed Oct 11, 2019
1 parent 0e85772 commit bb51fd0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion dist/moysklad.js
Original file line number Diff line number Diff line change
Expand Up @@ -2977,7 +2977,7 @@ module.exports = function buildFilter (filter) {
const value = part[2]
switch (true) {
case value === undefined:
throw new TypeError(`filter "${key}" key value is undefined`)
return null

case value === null:
return [key, operator, '']
Expand All @@ -2994,6 +2994,7 @@ module.exports = function buildFilter (filter) {
throw new TypeError(`filter "${key}" key value is incorrect`)
}
})
.filter(it => it)
.map(part => `${part[0]}${part[1]}${part[2]}`)
.sort((p1, p2) => {
if (p1 > p2) { return 1 }
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "moysklad",
"version": "0.6.1",
"version": "0.6.2",
"description": "Библиотека для работы с API сервиса МойСклад",
"main": "index.js",
"types": "index.d.ts",
Expand Down
11 changes: 5 additions & 6 deletions src/tools/__tests__/buildFilter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,11 @@ test('buildFilter with query selectors combined with sub fields', t => {
name: {
$gt: 15,
$eq: 'foo',
sub: 'bar'
}
$lte: undefined,
sub: 'bar',
empty: undefined
},
empty: undefined
}

t.deepEqual(buildFilter(filter), 'id=5;name.sub=bar;name=foo;name>15')
Expand All @@ -170,10 +173,6 @@ test('buildFilter errors', t => {
buildFilter()
}, /filter must to be an object/)

t.throws(() => {
buildFilter({ foo: undefined })
}, /filter "foo" key value is undefined/)

t.throws(() => {
buildFilter({ foo: Symbol('foo') })
}, /filter "foo" key value is incorrect/)
Expand Down
3 changes: 2 additions & 1 deletion src/tools/buildFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ module.exports = function buildFilter (filter) {
const value = part[2]
switch (true) {
case value === undefined:
throw new TypeError(`filter "${key}" key value is undefined`)
return null

case value === null:
return [key, operator, '']
Expand All @@ -152,6 +152,7 @@ module.exports = function buildFilter (filter) {
throw new TypeError(`filter "${key}" key value is incorrect`)
}
})
.filter(it => it)
.map(part => `${part[0]}${part[1]}${part[2]}`)
.sort((p1, p2) => {
if (p1 > p2) { return 1 }
Expand Down

0 comments on commit bb51fd0

Please sign in to comment.