Skip to content

Commit 96f4b3f

Browse files
committed
fix: fix uuid casting for filters
1 parent d5c28b7 commit 96f4b3f

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"license": "MIT",
3737
"peerDependencies": {
3838
"adminjs": "^5.0.0",
39-
"typeorm": ">=0.2.28"
39+
"typeorm": "^0.2.45"
4040
},
4141
"optionalDependencies": {},
4242
"devDependencies": {
@@ -46,25 +46,25 @@
4646
"@types/chai": "^4.2.4",
4747
"@types/mocha": "^5.2.7",
4848
"@types/node": "12.0.10",
49-
"chai": "^4.2.0",
50-
"class-validator": "^0.11.0",
51-
"mocha": "^6.2.2",
52-
"pg": "^7.12.1",
53-
"ts-node": "^8.4.1",
54-
"tsconfig-paths": "^3.9.0",
5549
"@typescript-eslint/eslint-plugin": "^3.7.0",
5650
"@typescript-eslint/parser": "^3.7.0",
5751
"adminjs": "^5.0.0",
52+
"chai": "^4.2.0",
53+
"class-validator": "^0.11.0",
5854
"eslint": "^7.5.0",
5955
"eslint-config-airbnb": "^18.2.0",
6056
"eslint-plugin-import": "^2.22.0",
6157
"eslint-plugin-jsx-a11y": "^6.3.1",
6258
"eslint-plugin-react": "^7.20.3",
6359
"eslint-plugin-react-hooks": "^4.0.8",
6460
"husky": "^4.2.5",
61+
"mocha": "^6.2.2",
62+
"pg": "^7.12.1",
6563
"semantic-release": "^17.0.7",
6664
"semantic-release-slack-bot": "^1.6.2",
67-
"typeorm": "^0.2.28",
65+
"ts-node": "^8.4.1",
66+
"tsconfig-paths": "^3.9.0",
67+
"typeorm": "^0.2.45",
6868
"typescript": "^4.0.3"
6969
}
7070
}

src/utils/filter/default-filter.parser.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
import { Like } from 'typeorm'
1+
import { Like, Raw } from 'typeorm'
2+
import { Property } from '../../Property'
23
import { FilterParser } from './filter.types'
34

45
const uuidRegex = /^[0-9A-F]{8}-[0-9A-F]{4}-[5|4|3|2|1][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i
56

67
export const DefaultParser: FilterParser = {
78
isParserForType: (filter) => filter.property.type() === 'string',
89
parse: (filter, fieldKey) => {
9-
if (uuidRegex.test(filter.value.toString())) {
10-
return { filterKey: fieldKey, filterValue: filter.value }
10+
if (uuidRegex.test(filter.value.toString()) || (filter.property as Property).column.type === 'uuid') {
11+
return {
12+
filterKey: fieldKey,
13+
filterValue: Raw(
14+
(alias) => `CAST(${alias} AS text) = :value`,
15+
{ value: filter.value },
16+
),
17+
}
1118
}
1219
return { filterKey: fieldKey, filterValue: Like(`%${filter.value}%`) }
1320
},

0 commit comments

Comments
 (0)