aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/account')
-rw-r--r--server/models/account/account-blocklist.ts32
1 files changed, 26 insertions, 6 deletions
diff --git a/server/models/account/account-blocklist.ts b/server/models/account/account-blocklist.ts
index e2f66d733..fe2d5d010 100644
--- a/server/models/account/account-blocklist.ts
+++ b/server/models/account/account-blocklist.ts
@@ -1,6 +1,6 @@
1import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' 1import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
2import { AccountModel } from './account' 2import { AccountModel } from './account'
3import { getSort } from '../utils' 3import { getSort, searchAttribute } from '../utils'
4import { AccountBlock } from '../../../shared/models/blocklist' 4import { AccountBlock } from '../../../shared/models/blocklist'
5import { Op } from 'sequelize' 5import { Op } from 'sequelize'
6import * as Bluebird from 'bluebird' 6import * as Bluebird from 'bluebird'
@@ -111,16 +111,36 @@ export class AccountBlocklistModel extends Model<AccountBlocklistModel> {
111 return AccountBlocklistModel.findOne(query) 111 return AccountBlocklistModel.findOne(query)
112 } 112 }
113 113
114 static listForApi (accountId: number, start: number, count: number, sort: string) { 114 static listForApi (parameters: {
115 start: number
116 count: number
117 sort: string
118 search?: string
119 accountId: number
120 }) {
121 const { start, count, sort, search, accountId } = parameters
122
115 const query = { 123 const query = {
116 offset: start, 124 offset: start,
117 limit: count, 125 limit: count,
118 order: getSort(sort), 126 order: getSort(sort)
119 where: { 127 }
120 accountId 128
121 } 129 const where = {
130 accountId
122 } 131 }
123 132
133 if (search) {
134 Object.assign(where, {
135 [Op.or]: [
136 { ...searchAttribute(search, '$BlockedAccount.name$') },
137 { ...searchAttribute(search, '$BlockedAccount.Actor.url$') }
138 ]
139 })
140 }
141
142 Object.assign(query, { where })
143
124 return AccountBlocklistModel 144 return AccountBlocklistModel
125 .scope([ ScopeNames.WITH_ACCOUNTS ]) 145 .scope([ ScopeNames.WITH_ACCOUNTS ])
126 .findAndCountAll<MAccountBlocklistAccounts>(query) 146 .findAndCountAll<MAccountBlocklistAccounts>(query)