X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Futils.ts;h=eb6653f3ddf24d906c4333a7856fd26d8923618c;hb=22a16e36f6526887ed8f5e5d3c9f9e5da0b4a8cd;hp=99e14658326adb5fb3fdb5d4dafcae8a625c9832;hpb=2cebd797014561ebc0bfee07ee8b5d83820adb66;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/utils.ts b/server/models/utils.ts index 99e146583..eb6653f3d 100644 --- a/server/models/utils.ts +++ b/server/models/utils.ts @@ -1,6 +1,8 @@ // Translate for example "-name" to [ [ 'name', 'DESC' ], [ 'id', 'ASC' ] ] import { Sequelize } from 'sequelize-typescript' +type SortType = { sortModel: any, sortValue: string } + function getSort (value: string, lastSort: string[] = [ 'id', 'ASC' ]) { let field: any let direction: 'ASC' | 'DESC' @@ -51,26 +53,15 @@ function createSimilarityAttribute (col: string, value: string) { ) } -function createSearchTrigramQuery (col: string, value: string) { - return { - [ Sequelize.Op.or ]: [ - // FIXME: use word_similarity instead of just similarity? - Sequelize.where(searchTrigramNormalizeCol(col), ' % ', searchTrigramNormalizeValue(value)), - - Sequelize.where(searchTrigramNormalizeCol(col), ' LIKE ', searchTrigramNormalizeValue(`%${value}%`)) - ] - } -} - // --------------------------------------------------------------------------- export { + SortType, getSort, getSortOnModel, createSimilarityAttribute, throwIfNotValid, - buildTrigramSearchIndex, - createSearchTrigramQuery + buildTrigramSearchIndex } // ---------------------------------------------------------------------------