diff --git a/package.json b/package.json index f708373a..46a48ca7 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "license": "MIT", "peerDependencies": { "adminjs": "^5.0.0", - "typeorm": ">=0.2.28" + "typeorm": "^0.2.45" }, "optionalDependencies": {}, "devDependencies": { @@ -46,15 +46,11 @@ "@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", @@ -62,9 +58,13 @@ "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" } } diff --git a/src/utils/filter/default-filter.parser.ts b/src/utils/filter/default-filter.parser.ts index e0c1b568..68eb6e4b 100644 --- a/src/utils/filter/default-filter.parser.ts +++ b/src/utils/filter/default-filter.parser.ts @@ -1,4 +1,5 @@ -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 @@ -6,8 +7,14 @@ const uuidRegex = /^[0-9A-F]{8}-[0-9A-F]{4}-[5|4|3|2|1][0-9A-F]{3}-[89AB][0-9A-F 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}%`) } },