blocklist.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { sequelizeTypescript } from '../initializers'
  2. import { AccountBlocklistModel } from '../models/account/account-blocklist'
  3. import { ServerBlocklistModel } from '../models/server/server-blocklist'
  4. function addAccountInBlocklist (byAccountId: number, targetAccountId: number) {
  5. return sequelizeTypescript.transaction(async t => {
  6. return AccountBlocklistModel.upsert({
  7. accountId: byAccountId,
  8. targetAccountId: targetAccountId
  9. }, { transaction: t })
  10. })
  11. }
  12. function addServerInBlocklist (byAccountId: number, targetServerId: number) {
  13. return sequelizeTypescript.transaction(async t => {
  14. return ServerBlocklistModel.upsert({
  15. accountId: byAccountId,
  16. targetServerId
  17. }, { transaction: t })
  18. })
  19. }
  20. function removeAccountFromBlocklist (accountBlock: AccountBlocklistModel) {
  21. return sequelizeTypescript.transaction(async t => {
  22. return accountBlock.destroy({ transaction: t })
  23. })
  24. }
  25. function removeServerFromBlocklist (serverBlock: ServerBlocklistModel) {
  26. return sequelizeTypescript.transaction(async t => {
  27. return serverBlock.destroy({ transaction: t })
  28. })
  29. }
  30. export {
  31. addAccountInBlocklist,
  32. addServerInBlocklist,
  33. removeAccountFromBlocklist,
  34. removeServerFromBlocklist
  35. }