Skip to content

Commit

Permalink
fix: handle UUID type in filters
Browse files Browse the repository at this point in the history
Resolves #32
  • Loading branch information
dziraf committed Feb 24, 2022
1 parent e07e5e4 commit 69b3a72
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/utils/filter/default-filter.parser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { Like } from 'typeorm'
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) => ({ filterKey: fieldKey, filterValue: Like(`%${filter.value}%`) }),
parse: (filter, fieldKey) => {
if (uuidRegex.test(filter.value.toString())) {
return { filterKey: fieldKey, filterValue: filter.value }
}
return { filterKey: fieldKey, filterValue: Like(`%${filter.value}%`) }
},
}

0 comments on commit 69b3a72

Please sign in to comment.