aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/utils.ts')
-rw-r--r--server/models/utils.ts15
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 @@
1import { Model, Sequelize } from 'sequelize-typescript' 1import { Model, Sequelize } from 'sequelize-typescript'
2import validator from 'validator' 2import validator from 'validator'
3import { Col } from 'sequelize/types/lib/utils' 3import { Col } from 'sequelize/types/lib/utils'
4import { literal, OrderItem } from 'sequelize' 4import { literal, OrderItem, Op } from 'sequelize'
5 5
6type Primitive = string | Function | number | boolean | Symbol | undefined | null 6type Primitive = string | Function | number | boolean | Symbol | undefined | null
7type DeepOmitHelper<T, K extends keyof T> = { 7type 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
210function searchAttribute (sourceField, targetField) {
211 return sourceField
212 ? {
213 [targetField]: {
214 [Op.iLike]: `%${sourceField}%`
215 }
216 }
217 : {}
218}
219
210// --------------------------------------------------------------------------- 220// ---------------------------------------------------------------------------
211 221
212export { 222export {
@@ -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// ---------------------------------------------------------------------------