Skip to content

Commit

Permalink
fix: fix uuid casting for filters
Browse files Browse the repository at this point in the history
  • Loading branch information
dziraf committed Apr 3, 2022
1 parent d5c28b7 commit 96f4b3f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"license": "MIT",
"peerDependencies": {
"adminjs": "^5.0.0",
"typeorm": ">=0.2.28"
"typeorm": "^0.2.45"
},
"optionalDependencies": {},
"devDependencies": {
Expand All @@ -46,25 +46,25 @@
"@types/chai": "^4.2.4",
"@types/mocha": "^5.2.7",
"@types/node": "12.0.10",
"chai": "^4.2.0",
"class-validator": "^0.11.0",
"mocha": "^6.2.2",
"pg": "^7.12.1",
"ts-node": "^8.4.1",
"tsconfig-paths": "^3.9.0",
"@typescript-eslint/eslint-plugin": "^3.7.0",
"@typescript-eslint/parser": "^3.7.0",
"adminjs": "^5.0.0",
"chai": "^4.2.0",
"class-validator": "^0.11.0",
"eslint": "^7.5.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-react": "^7.20.3",
"eslint-plugin-react-hooks": "^4.0.8",
"husky": "^4.2.5",
"mocha": "^6.2.2",
"pg": "^7.12.1",
"semantic-release": "^17.0.7",
"semantic-release-slack-bot": "^1.6.2",
"typeorm": "^0.2.28",
"ts-node": "^8.4.1",
"tsconfig-paths": "^3.9.0",
"typeorm": "^0.2.45",
"typescript": "^4.0.3"
}
}
13 changes: 10 additions & 3 deletions src/utils/filter/default-filter.parser.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { Like } from 'typeorm'
import { Like, Raw } from 'typeorm'
import { Property } from '../../Property'
import { FilterParser } from './filter.types'

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

export const DefaultParser: FilterParser = {
isParserForType: (filter) => filter.property.type() === 'string',
parse: (filter, fieldKey) => {
if (uuidRegex.test(filter.value.toString())) {
return { filterKey: fieldKey, filterValue: filter.value }
if (uuidRegex.test(filter.value.toString()) || (filter.property as Property).column.type === 'uuid') {
return {
filterKey: fieldKey,
filterValue: Raw(
(alias) => `CAST(${alias} AS text) = :value`,
{ value: filter.value },
),
}
}
return { filterKey: fieldKey, filterValue: Like(`%${filter.value}%`) }
},
Expand Down

0 comments on commit 96f4b3f

Please sign in to comment.