import { literal, Op, OrderItem, Sequelize } from 'sequelize'
-import { Col } from 'sequelize/types/lib/utils'
import validator from 'validator'
type SortType = { sortModel: string, sortValue: string }
function getSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
const { direction, field } = buildDirectionAndField(value)
- let finalField: string | Col
+ let finalField: string | ReturnType<typeof Sequelize.col>
if (field.toLowerCase() === 'match') { // Search
finalField = Sequelize.col('similarity')
]
}
- let finalField: string | Col
+ let finalField: string | ReturnType<typeof Sequelize.col>
// Alias
if (field.toLowerCase() === 'match') { // Search
finalField = field
}
- const firstSort = typeof finalField === 'string'
- ? finalField.split('.').concat([ direction ]) as any // FIXME: sequelize typings
+ const firstSort: OrderItem = typeof finalField === 'string'
+ ? finalField.split('.').concat([ direction ]) as OrderItem
: [ finalField, direction ]
return [ firstSort, lastSort ]
function getBlacklistSort (model: any, value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
const [ firstSort ] = getSort(value)
- if (model) return [ [ literal(`"${model}.${firstSort[0]}" ${firstSort[1]}`) ], lastSort ] as any[] // FIXME: typings
+ if (model) return [ [ literal(`"${model}.${firstSort[0]}" ${firstSort[1]}`) ], lastSort ] as OrderItem[]
return [ firstSort, lastSort ]
}
}
function isOutdated (model: { createdAt: Date, updatedAt: Date }, refreshInterval: number) {
+ if (!model.createdAt || !model.updatedAt) {
+ throw new Error('Miss createdAt & updatedAt attribuets to model')
+ }
+
const now = Date.now()
const createdAtTime = model.createdAt.getTime()
const updatedAtTime = model.updatedAt.getTime()
'SELECT "actor"."serverId" FROM "actorFollow" ' +
'INNER JOIN "actor" ON actor.id = "actorFollow"."targetActorId" ' +
'WHERE "actorFollow"."actorId" = ' + actorIdNumber +
- ')'
+ ')'
}
function buildWhereIdOrUUID (id: number | string) {
return {
[targetField]: {
- [Op.iLike]: `%${sourceField}%`
+ // FIXME: ts error
+ [Op.iLike as any]: `%${sourceField}%`
}
}
}