X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Factor%2Factor-follow.ts;h=9615229dd7ea3a332262e3f2a31951e42d29ab7f;hb=52d6c2e0bf0893e39d0a89fccebad684e9d61ce5;hp=af1d85e9f8befbb44573edd2a8076452c898d83f;hpb=69c1f3c25622500e0956127a2493bba54fce97f8;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/actor/actor-follow.ts b/server/models/actor/actor-follow.ts index af1d85e9f..9615229dd 100644 --- a/server/models/actor/actor-follow.ts +++ b/server/models/actor/actor-follow.ts @@ -1,5 +1,5 @@ -import { difference, values } from 'lodash' -import { Includeable, IncludeOptions, Op, QueryTypes, Transaction } from 'sequelize' +import { difference } from 'lodash' +import { Attributes, FindOptions, Includeable, IncludeOptions, Op, QueryTypes, Transaction, WhereAttributeHash } from 'sequelize' import { AfterCreate, AfterDestroy, @@ -69,7 +69,7 @@ import { InstanceListFollowingQueryBuilder, ListFollowingOptions } from './sql/i export class ActorFollowModel extends Model>> { @AllowNull(false) - @Column(DataType.ENUM(...values(FOLLOW_STATES))) + @Column(DataType.ENUM(...Object.values(FOLLOW_STATES))) state: FollowState @AllowNull(false) @@ -209,7 +209,9 @@ export class ActorFollowModel extends Model { + static loadByActorAndTargetNameAndHostForAPI (options: { + actorId: number + targetName: string + targetHost: string + state?: FollowState + transaction?: Transaction + }): Promise { + const { actorId, targetHost, targetName, state, transaction } = options + const actorFollowingPartInclude: IncludeOptions = { model: ActorModel, required: true, @@ -271,10 +276,11 @@ export class ActorFollowModel extends Model> = { actorId } + if (state) where.state = state + + const query: FindOptions> = { + where, include: [ actorFollowingPartInclude, { @@ -283,7 +289,7 @@ export class ActorFollowModel extends Model