import * as Sequelize from 'sequelize'
import {
+ AfterDelete,
+ AfterUpdate,
AllowNull,
BeforeCreate,
BeforeUpdate,
import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type'
import { values } from 'lodash'
import { NSFW_POLICY_TYPES } from '../../initializers'
+import { clearCacheByUserId } from '../../lib/oauth-model'
enum ScopeNames {
WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL'
}
}
+ @AfterUpdate
+ @AfterDelete
+ static removeTokenCache (instance: UserModel) {
+ return clearCacheByUserId(instance.id)
+ }
+
static countTotal () {
return this.count()
}
- static listForApi (start: number, count: number, sort: string) {
+ static listForApi (start: number, count: number, sort: string, search?: string) {
+ let where = undefined
+ if (search) {
+ where = {
+ [Sequelize.Op.or]: [
+ {
+ email: {
+ [Sequelize.Op.iLike]: '%' + search + '%'
+ }
+ },
+ {
+ username: {
+ [ Sequelize.Op.iLike ]: '%' + search + '%'
+ }
+ }
+ ]
+ }
+ }
+
const query = {
attributes: {
include: [
},
offset: start,
limit: count,
- order: getSort(sort)
+ order: getSort(sort),
+ where
}
return UserModel.findAndCountAll(query)