1 import { Response } from 'express'
2 import { AccountModel } from '../../models/account/account'
3 import * as Bluebird from 'bluebird'
5 function doesAccountIdExist (id: number, res: Response, sendNotFound = true) {
6 const promise = AccountModel.load(id)
8 return doesAccountExist(promise, res, sendNotFound)
11 function doesLocalAccountNameExist (name: string, res: Response, sendNotFound = true) {
12 const promise = AccountModel.loadLocalByName(name)
14 return doesAccountExist(promise, res, sendNotFound)
17 function doesAccountNameWithHostExist (nameWithDomain: string, res: Response, sendNotFound = true) {
18 return doesAccountExist(AccountModel.loadByNameWithHost(nameWithDomain), res, sendNotFound)
21 async function doesAccountExist (p: Bluebird<AccountModel>, res: Response, sendNotFound: boolean) {
22 const account = await p
25 if (sendNotFound === true) {
27 .send({ error: 'Account not found' })
34 res.locals.account = account
39 // ---------------------------------------------------------------------------
43 doesLocalAccountNameExist,
44 doesAccountNameWithHostExist,