X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Futils.ts;h=bdf2291f0ceb5b34ed3c089de5e71044ec7304b8;hb=c2a89b70ce75c4955cbdb1ced6fd20a5010a8c9b;hp=674ddcbe47260277ad03c1ba1edbafab29da83c5;hpb=5f3e2425f1c64d93860a0c3341de9b361b3c1f1f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/utils.ts b/server/models/utils.ts index 674ddcbe4..bdf2291f0 100644 --- a/server/models/utils.ts +++ b/server/models/utils.ts @@ -1,7 +1,24 @@ import { Model, Sequelize } from 'sequelize-typescript' import validator from 'validator' import { Col } from 'sequelize/types/lib/utils' -import { literal, OrderItem } from 'sequelize' +import { literal, OrderItem, Op } from 'sequelize' + +type Primitive = string | Function | number | boolean | Symbol | undefined | null +type DeepOmitHelper = { + [P in K]: // extra level of indirection needed to trigger homomorhic behavior + T[P] extends infer TP // distribute over unions + ? TP extends Primitive + ? TP // leave primitives and functions alone + : TP extends any[] + ? DeepOmitArray // Array special handling + : DeepOmit + : never +} +type DeepOmit = T extends Primitive ? T : DeepOmitHelper> + +type DeepOmitArray = { + [P in keyof T]: DeepOmit +} type SortType = { sortModel: string, sortValue: string } @@ -190,9 +207,22 @@ function buildDirectionAndField (value: string) { return { direction, field } } +function searchAttribute (sourceField, targetField) { + if (sourceField) { + return { + [targetField]: { + [Op.iLike]: `%${sourceField}%` + } + } + } else { + return {} + } +} + // --------------------------------------------------------------------------- export { + DeepOmit, buildBlockedAccountSQL, buildLocalActorIdsIn, SortType, @@ -210,7 +240,8 @@ export { parseAggregateResult, getFollowsSort, buildDirectionAndField, - createSafeIn + createSafeIn, + searchAttribute } // ---------------------------------------------------------------------------