Skip to content

Commit

Permalink
fix: add string type to gt/lt/gte/lte type definitions (#2704)
Browse files Browse the repository at this point in the history
  • Loading branch information
damieng authored Jul 12, 2024
1 parent 99f6060 commit 233533d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions docs/content/7.v1/1.getting-started/4.fetching.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ const articles = await this.$content('articles').where({ title: { $eq: 'Home' }

// $gt
const articles = await this.$content('articles').where({ age: { $gt: 18 } }).fetch()
// $lte
const articles = await this.$content('articles').where({ createdDateTime: { $lte: new Date().toISOString() } }).fetch()
// $in
const articles = await this.$content('articles').where({ name: { $in: ['odin', 'thor'] } }).fetch()
```
Expand Down
8 changes: 4 additions & 4 deletions src/types/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export interface ContentQueryBuilderWhere extends Partial<Record<keyof ParsedCon
})
```
*/
$gt?: number
$gt?: number | string
/**
* Check if item is greater than or equal to condition
*
Expand All @@ -137,7 +137,7 @@ export interface ContentQueryBuilderWhere extends Partial<Record<keyof ParsedCon
})
```
*/
$gte?: number
$gte?: number | string
/**
* Check if item is less than condition
*
Expand All @@ -150,7 +150,7 @@ export interface ContentQueryBuilderWhere extends Partial<Record<keyof ParsedCon
})
```
*/
$lt?: number
$lt?: number | string
/**
* Check if item is less than or equal to condition
*
Expand All @@ -163,7 +163,7 @@ export interface ContentQueryBuilderWhere extends Partial<Record<keyof ParsedCon
})
```
*/
$lte?: number
$lte?: number | string
/**
* Provides regular expression capabilities for pattern matching strings.
*
Expand Down
10 changes: 9 additions & 1 deletion test/features/query/match.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,25 +164,33 @@ describe('Match', () => {
})
})

describe('Numerical operators', () => {
describe('Less-than/Greater-than operators', () => {
test('$gt', () => {
expect(match(item, { id: { $gt: 0 } })).toBe(true)
expect(match(item, { id: { $gt: 1 } })).toBe(false)
expect(match(item, { category: { $gt: 'c' } })).toBe(true)
expect(match(item, { category: { $gt: 'c1' } })).toBe(false)
})

test('$gte', () => {
expect(match(item, { id: { $gte: 1 } })).toBe(true)
expect(match(item, { id: { $gte: 2 } })).toBe(false)
expect(match(item, { category: { $gte: 'c1' } })).toBe(true)
expect(match(item, { category: { $gte: 'c11' } })).toBe(false)
})

test('$lt', () => {
expect(match(item, { id: { $lt: 2 } })).toBe(true)
expect(match(item, { id: { $lt: 1 } })).toBe(false)
expect(match(item, { category: { $lt: 'c11' } })).toBe(true)
expect(match(item, { category: { $lt: 'c1' } })).toBe(false)
})

test('$lte', () => {
expect(match(item, { id: { $lte: 1 } })).toBe(true)
expect(match(item, { id: { $lte: 0 } })).toBe(false)
expect(match(item, { category: { $lte: 'c1' } })).toBe(true)
expect(match(item, { category: { $lte: 'c' } })).toBe(false)
})
})

Expand Down

0 comments on commit 233533d

Please sign in to comment.