X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fblocklist.ts;h=28c69b46e767744a73d267fa97f9fcabb9aaba8d;hb=03efb1419d33627939ee9593633fc703b957199d;hp=394c2453705c139054a839372807ec482da53762;hpb=7ad9b9846c44d198a736183fb186c2039f5236b5;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/blocklist.ts b/server/lib/blocklist.ts index 394c24537..28c69b46e 100644 --- a/server/lib/blocklist.ts +++ b/server/lib/blocklist.ts @@ -1,10 +1,11 @@ import { sequelizeTypescript } from '../initializers' import { AccountBlocklistModel } from '../models/account/account-blocklist' import { ServerBlocklistModel } from '../models/server/server-blocklist' +import { MAccountBlocklist, MServerBlocklist } from '@server/typings/models' function addAccountInBlocklist (byAccountId: number, targetAccountId: number) { return sequelizeTypescript.transaction(async t => { - return AccountBlocklistModel.create({ + return AccountBlocklistModel.upsert({ accountId: byAccountId, targetAccountId: targetAccountId }, { transaction: t }) @@ -13,20 +14,20 @@ function addAccountInBlocklist (byAccountId: number, targetAccountId: number) { function addServerInBlocklist (byAccountId: number, targetServerId: number) { return sequelizeTypescript.transaction(async t => { - return ServerBlocklistModel.create({ + return ServerBlocklistModel.upsert({ accountId: byAccountId, targetServerId }, { transaction: t }) }) } -function removeAccountFromBlocklist (accountBlock: AccountBlocklistModel) { +function removeAccountFromBlocklist (accountBlock: MAccountBlocklist) { return sequelizeTypescript.transaction(async t => { return accountBlock.destroy({ transaction: t }) }) } -function removeServerFromBlocklist (serverBlock: ServerBlocklistModel) { +function removeServerFromBlocklist (serverBlock: MServerBlocklist) { return sequelizeTypescript.transaction(async t => { return serverBlock.destroy({ transaction: t }) })