Skip to content

Commit

Permalink
fix: Searching by ID in mongoose
Browse files Browse the repository at this point in the history
  • Loading branch information
JonaszJestem committed Dec 16, 2020
1 parent fe77476 commit b6e5675
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/property.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseProperty } from 'admin-bro'
import { BaseProperty, PropertyType } from 'admin-bro'

const ID_PROPERTY = '_id'
const VERSION_KEY_PROPERTY = '__v'
Expand Down Expand Up @@ -53,7 +53,7 @@ class Property extends BaseProperty {
if (this.reference()) {
return 'reference'
}
return 'string'
return 'id' as PropertyType
case 'Decimal128':
return 'float'
default:
Expand Down
13 changes: 13 additions & 0 deletions test/resource/find.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,17 @@ describe('Resource #find', () => {
expect(returnedItems.length).toEqual(limit)
expect(returnedItems[0]).toBeInstanceOf(BaseRecord)
})

it('searches by id', async () => {
const users = await factory.createMany('user', 10)
const resource = new Resource(User)
const limit = 5
const offset = 0

const idFilters = new Filter({ _id: users[0]._id.toHexString() }, resource)
const returnedItems = await resource.find(idFilters, { limit, offset })

expect(returnedItems.length).toEqual(1)
expect(returnedItems[0]).toBeInstanceOf(BaseRecord)
})
})

0 comments on commit b6e5675

Please sign in to comment.