-import * as Sequelize from 'sequelize'
import {
AllowNull,
BeforeDestroy,
BelongsTo,
Column,
- CreatedAt,
+ CreatedAt, DataType,
Default,
DefaultScope,
ForeignKey,
import { UserModel } from './user'
import { AvatarModel } from '../avatar/avatar'
import { VideoPlaylistModel } from '../video/video-playlist'
-import { WEBSERVER } from '../../initializers/constants'
+import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants'
+import { Op, Transaction, WhereOptions } from 'sequelize'
export enum ScopeNames {
SUMMARY = 'SUMMARY'
}
-@DefaultScope({
+@DefaultScope(() => ({
include: [
{
- model: () => ActorModel, // Default scope includes avatar and server
+ model: ActorModel, // Default scope includes avatar and server
required: true
}
]
-})
-@Scopes({
- [ ScopeNames.SUMMARY ]: (whereActor?: Sequelize.WhereOptions<ActorModel>) => {
+}))
+@Scopes(() => ({
+ [ ScopeNames.SUMMARY ]: (whereActor?: WhereOptions) => {
return {
attributes: [ 'id', 'name' ],
include: [
]
}
}
-})
+}))
@Table({
tableName: 'account',
indexes: [
@AllowNull(true)
@Default(null)
- @Is('AccountDescription', value => throwIfNotValid(value, isAccountDescriptionValid, 'description'))
- @Column
+ @Is('AccountDescription', value => throwIfNotValid(value, isAccountDescriptionValid, 'description', true))
+ @Column(DataType.STRING(CONSTRAINTS_FIELDS.USERS.DESCRIPTION.max))
description: string
@CreatedAt
return undefined
}
- static load (id: number, transaction?: Sequelize.Transaction) {
+ static load (id: number, transaction?: Transaction) {
return AccountModel.findByPk(id, { transaction })
}
static loadLocalByName (name: string) {
const query = {
where: {
- [ Sequelize.Op.or ]: [
+ [ Op.or ]: [
{
userId: {
- [ Sequelize.Op.ne ]: null
+ [ Op.ne ]: null
}
},
{
applicationId: {
- [ Sequelize.Op.ne ]: null
+ [ Op.ne ]: null
}
}
]
return AccountModel.findOne(query)
}
- static loadByUrl (url: string, transaction?: Sequelize.Transaction) {
+ static loadByUrl (url: string, transaction?: Transaction) {
const query = {
include: [
{