diff options
Diffstat (limited to 'server/models/utils.ts')
-rw-r--r-- | server/models/utils.ts | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/server/models/utils.ts b/server/models/utils.ts index 06ff05864..7137419a2 100644 --- a/server/models/utils.ts +++ b/server/models/utils.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { Model, Sequelize } from 'sequelize-typescript' | 1 | import { Model, Sequelize } from 'sequelize-typescript' |
2 | import validator from 'validator' | 2 | import validator from 'validator' |
3 | import { Col } from 'sequelize/types/lib/utils' | 3 | import { Col } from 'sequelize/types/lib/utils' |
4 | import { literal, OrderItem } from 'sequelize' | 4 | import { literal, OrderItem, Op } from 'sequelize' |
5 | 5 | ||
6 | type Primitive = string | Function | number | boolean | Symbol | undefined | null | 6 | type Primitive = string | Function | number | boolean | Symbol | undefined | null |
7 | type DeepOmitHelper<T, K extends keyof T> = { | 7 | type DeepOmitHelper<T, K extends keyof T> = { |
@@ -207,6 +207,16 @@ function buildDirectionAndField (value: string) { | |||
207 | return { direction, field } | 207 | return { direction, field } |
208 | } | 208 | } |
209 | 209 | ||
210 | function searchAttribute (sourceField, targetField) { | ||
211 | return sourceField | ||
212 | ? { | ||
213 | [targetField]: { | ||
214 | [Op.iLike]: `%${sourceField}%` | ||
215 | } | ||
216 | } | ||
217 | : {} | ||
218 | } | ||
219 | |||
210 | // --------------------------------------------------------------------------- | 220 | // --------------------------------------------------------------------------- |
211 | 221 | ||
212 | export { | 222 | export { |
@@ -228,7 +238,8 @@ export { | |||
228 | parseAggregateResult, | 238 | parseAggregateResult, |
229 | getFollowsSort, | 239 | getFollowsSort, |
230 | buildDirectionAndField, | 240 | buildDirectionAndField, |
231 | createSafeIn | 241 | createSafeIn, |
242 | searchAttribute | ||
232 | } | 243 | } |
233 | 244 | ||
234 | // --------------------------------------------------------------------------- | 245 | // --------------------------------------------------------------------------- |