1 import { Response } from 'express'
2 import { AccountModel } from '../../models/account/account'
3 import * as Bluebird from 'bluebird'
4 import { MAccountDefault } from '../../types/models'
6 function doesAccountIdExist (id: number | string, res: Response, sendNotFound = true) {
7 const promise = AccountModel.load(parseInt(id + '', 10))
9 return doesAccountExist(promise, res, sendNotFound)
12 function doesLocalAccountNameExist (name: string, res: Response, sendNotFound = true) {
13 const promise = AccountModel.loadLocalByName(name)
15 return doesAccountExist(promise, res, sendNotFound)
18 function doesAccountNameWithHostExist (nameWithDomain: string, res: Response, sendNotFound = true) {
19 const promise = AccountModel.loadByNameWithHost(nameWithDomain)
21 return doesAccountExist(promise, res, sendNotFound)
24 async function doesAccountExist (p: Bluebird<MAccountDefault>, res: Response, sendNotFound: boolean) {
25 const account = await p
28 if (sendNotFound === true) {
30 .send({ error: 'Account not found' })
37 res.locals.account = account
42 // ---------------------------------------------------------------------------
46 doesLocalAccountNameExist,
47 doesAccountNameWithHostExist,