X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Faccounts.ts;h=f676669ea6c557d232af78997371a147490a39d8;hb=dc48fdbe68e9dd3a3a6028181e61d8595d98e654;hp=31a2de5ca6ce5e2b5377ab4a3193bfd0108fbd99;hpb=57cfff78858b2360d9e038e2a504b761cb51da47;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/custom-validators/accounts.ts b/server/helpers/custom-validators/accounts.ts index 31a2de5ca..f676669ea 100644 --- a/server/helpers/custom-validators/accounts.ts +++ b/server/helpers/custom-validators/accounts.ts @@ -1,7 +1,3 @@ -import * as Bluebird from 'bluebird' -import { Response } from 'express' -import 'express-validator' -import { AccountModel } from '../../models/account/account' import { isUserDescriptionValid, isUserUsernameValid } from './users' import { exists } from './misc' @@ -17,47 +13,10 @@ function isAccountDescriptionValid (value: string) { return isUserDescriptionValid(value) } -function doesAccountIdExist (id: number, res: Response, sendNotFound = true) { - const promise = AccountModel.load(id) - - return doesAccountExist(promise, res, sendNotFound) -} - -function doesLocalAccountNameExist (name: string, res: Response, sendNotFound = true) { - const promise = AccountModel.loadLocalByName(name) - - return doesAccountExist(promise, res, sendNotFound) -} - -function doesAccountNameWithHostExist (nameWithDomain: string, res: Response, sendNotFound = true) { - return doesAccountExist(AccountModel.loadByNameWithHost(nameWithDomain), res, sendNotFound) -} - -async function doesAccountExist (p: Bluebird, res: Response, sendNotFound: boolean) { - const account = await p - - if (!account) { - if (sendNotFound === true) { - res.status(404) - .send({ error: 'Account not found' }) - .end() - } - - return false - } - - res.locals.account = account - - return true -} - // --------------------------------------------------------------------------- export { isAccountIdValid, - doesAccountIdExist, - doesLocalAccountNameExist, isAccountDescriptionValid, - doesAccountNameWithHostExist, isAccountNameValid }