-import * as Bluebird from 'bluebird'
-import { FindOptions, IncludeOptions, Op, Transaction, WhereOptions } from 'sequelize'
+import { FindOptions, Includeable, IncludeOptions, Op, Transaction, WhereOptions } from 'sequelize'
import {
AllowNull,
BeforeDestroy,
required: false
}
- const query: FindOptions = {
- attributes: [ 'id', 'name', 'actorId' ],
- include: [
- {
- attributes: [ 'id', 'preferredUsername', 'url', 'serverId', 'avatarId' ],
- model: ActorModel.unscoped(),
- required: options.actorRequired ?? true,
- where: whereActor,
- include: [
- serverInclude,
+ const queryInclude: Includeable[] = [
+ {
+ attributes: [ 'id', 'preferredUsername', 'url', 'serverId', 'avatarId' ],
+ model: ActorModel.unscoped(),
+ required: options.actorRequired ?? true,
+ where: whereActor,
+ include: [
+ serverInclude,
- {
- model: AvatarModel.unscoped(),
- required: false
- }
- ]
- }
- ]
+ {
+ model: AvatarModel.unscoped(),
+ required: false
+ }
+ ]
+ }
+ ]
+
+ const query: FindOptions = {
+ attributes: [ 'id', 'name', 'actorId' ]
}
if (options.withAccountBlockerIds) {
- query.include.push({
+ queryInclude.push({
attributes: [ 'id' ],
model: AccountBlocklistModel.unscoped(),
as: 'BlockedAccounts',
]
}
+ query.include = queryInclude
+
return query
}
}))
}
]
})
-export class AccountModel extends Model<AccountModel> {
+export class AccountModel extends Model {
@AllowNull(false)
@Column
return undefined
}
- static load (id: number, transaction?: Transaction): Bluebird<MAccountDefault> {
+ static load (id: number, transaction?: Transaction): Promise<MAccountDefault> {
return AccountModel.findByPk(id, { transaction })
}
- static loadByNameWithHost (nameWithHost: string): Bluebird<MAccountDefault> {
+ static loadByNameWithHost (nameWithHost: string): Promise<MAccountDefault> {
const [ accountName, host ] = nameWithHost.split('@')
if (!host || host === WEBSERVER.HOST) return AccountModel.loadLocalByName(accountName)
return AccountModel.loadByNameAndHost(accountName, host)
}
- static loadLocalByName (name: string): Bluebird<MAccountDefault> {
+ static loadLocalByName (name: string): Promise<MAccountDefault> {
const fun = () => {
const query = {
where: {
})
}
- static loadByNameAndHost (name: string, host: string): Bluebird<MAccountDefault> {
+ static loadByNameAndHost (name: string, host: string): Promise<MAccountDefault> {
const query = {
include: [
{
return AccountModel.findOne(query)
}
- static loadByUrl (url: string, transaction?: Transaction): Bluebird<MAccountDefault> {
+ static loadByUrl (url: string, transaction?: Transaction): Promise<MAccountDefault> {
const query = {
include: [
{
})
}
- static loadAccountIdFromVideo (videoId: number): Bluebird<MAccount> {
+ static loadAccountIdFromVideo (videoId: number): Promise<MAccount> {
const query = {
include: [
{
return AccountModel.findOne(query)
}
- static listLocalsForSitemap (sort: string): Bluebird<MAccountActor[]> {
+ static listLocalsForSitemap (sort: string): Promise<MAccountActor[]> {
const query = {
attributes: [ ],
offset: 0,