2018-10-12 08:26:04 -05:00
|
|
|
import { sequelizeTypescript } from '../initializers'
|
|
|
|
import { AccountBlocklistModel } from '../models/account/account-blocklist'
|
|
|
|
import { ServerBlocklistModel } from '../models/server/server-blocklist'
|
2019-08-15 04:53:26 -05:00
|
|
|
import { MAccountBlocklist, MServerBlocklist } from '@server/typings/models'
|
2018-10-12 08:26:04 -05:00
|
|
|
|
|
|
|
function addAccountInBlocklist (byAccountId: number, targetAccountId: number) {
|
|
|
|
return sequelizeTypescript.transaction(async t => {
|
2018-10-12 10:26:40 -05:00
|
|
|
return AccountBlocklistModel.upsert({
|
2018-10-12 08:26:04 -05:00
|
|
|
accountId: byAccountId,
|
|
|
|
targetAccountId: targetAccountId
|
|
|
|
}, { transaction: t })
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function addServerInBlocklist (byAccountId: number, targetServerId: number) {
|
|
|
|
return sequelizeTypescript.transaction(async t => {
|
2018-10-12 10:26:40 -05:00
|
|
|
return ServerBlocklistModel.upsert({
|
2018-10-12 08:26:04 -05:00
|
|
|
accountId: byAccountId,
|
|
|
|
targetServerId
|
|
|
|
}, { transaction: t })
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-08-15 04:53:26 -05:00
|
|
|
function removeAccountFromBlocklist (accountBlock: MAccountBlocklist) {
|
2018-10-12 08:26:04 -05:00
|
|
|
return sequelizeTypescript.transaction(async t => {
|
|
|
|
return accountBlock.destroy({ transaction: t })
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-08-15 04:53:26 -05:00
|
|
|
function removeServerFromBlocklist (serverBlock: MServerBlocklist) {
|
2018-10-12 08:26:04 -05:00
|
|
|
return sequelizeTypescript.transaction(async t => {
|
|
|
|
return serverBlock.destroy({ transaction: t })
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
addAccountInBlocklist,
|
|
|
|
addServerInBlocklist,
|
|
|
|
removeAccountFromBlocklist,
|
|
|
|
removeServerFromBlocklist
|
|
|
|
}
|