Skip to content

Commit

Permalink
fix: boolean handling in GET list
Browse files Browse the repository at this point in the history
  • Loading branch information
typicode committed May 13, 2024
1 parent 8fb0f72 commit 827c5c3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@ const post1 = {
id: '1',
title: 'a',
views: 100,
published: true,
author: { name: 'foo' },
tags: ['foo', 'bar'],
}
const post2 = {
id: '2',
title: 'b',
views: 200,
published: false,
author: { name: 'bar' },
tags: ['bar'],
}
const post3 = {
id: '3',
title: 'c',
views: 300,
published: false,
author: { name: 'baz' },
tags: ['foo'],
}
Expand Down Expand Up @@ -183,7 +186,16 @@ await test('find', async (t) => {
params: { _sort: '-views,id' },
res: [post3, post2, post1],
},

{
name: POSTS,
params: { published: 'true' },
res: [post1],
},
{
name: POSTS,
params: { published: 'false' },
res: [post2, post3],
},
{
name: POSTS,
params: { _start: 0, _end: 2 },
Expand Down
18 changes: 16 additions & 2 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,26 @@ export class Service {
}
// item_ne=value
case Condition.ne: {
if (!(itemValue != paramValue)) return false
switch (typeof itemValue) {
case 'number':
return itemValue !== parseInt(paramValue)
case 'string':
return itemValue !== paramValue
case 'boolean':
return itemValue !== (paramValue === 'true')
}
break
}
// item=value
case Condition.default: {
if (!(itemValue == paramValue)) return false
switch (typeof itemValue) {
case 'number':
return itemValue === parseInt(paramValue)
case 'string':
return itemValue === paramValue
case 'boolean':
return itemValue === (paramValue === 'true')
}
}
}
}
Expand Down

0 comments on commit 827c5c3

Please sign in to comment.