aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/accounts.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-23 10:40:39 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commit3e753302d8c911b59971c16a8018df0e1ab78465 (patch)
treeefce7ece3273589228c5c948ea6757b2bdf65429 /server/helpers/custom-validators/accounts.ts
parenta8b666e9f1ed002230869606308749614390c82f (diff)
downloadPeerTube-3e753302d8c911b59971c16a8018df0e1ab78465.tar.gz
PeerTube-3e753302d8c911b59971c16a8018df0e1ab78465.tar.zst
PeerTube-3e753302d8c911b59971c16a8018df0e1ab78465.zip
Refactor middleware helpers
Diffstat (limited to 'server/helpers/custom-validators/accounts.ts')
-rw-r--r--server/helpers/custom-validators/accounts.ts40
1 files changed, 0 insertions, 40 deletions
diff --git a/server/helpers/custom-validators/accounts.ts b/server/helpers/custom-validators/accounts.ts
index 31a2de5ca..be196d2a4 100644
--- a/server/helpers/custom-validators/accounts.ts
+++ b/server/helpers/custom-validators/accounts.ts
@@ -1,7 +1,4 @@
1import * as Bluebird from 'bluebird'
2import { Response } from 'express'
3import 'express-validator' 1import 'express-validator'
4import { AccountModel } from '../../models/account/account'
5import { isUserDescriptionValid, isUserUsernameValid } from './users' 2import { isUserDescriptionValid, isUserUsernameValid } from './users'
6import { exists } from './misc' 3import { exists } from './misc'
7 4
@@ -17,47 +14,10 @@ function isAccountDescriptionValid (value: string) {
17 return isUserDescriptionValid(value) 14 return isUserDescriptionValid(value)
18} 15}
19 16
20function doesAccountIdExist (id: number, res: Response, sendNotFound = true) {
21 const promise = AccountModel.load(id)
22
23 return doesAccountExist(promise, res, sendNotFound)
24}
25
26function doesLocalAccountNameExist (name: string, res: Response, sendNotFound = true) {
27 const promise = AccountModel.loadLocalByName(name)
28
29 return doesAccountExist(promise, res, sendNotFound)
30}
31
32function doesAccountNameWithHostExist (nameWithDomain: string, res: Response, sendNotFound = true) {
33 return doesAccountExist(AccountModel.loadByNameWithHost(nameWithDomain), res, sendNotFound)
34}
35
36async function doesAccountExist (p: Bluebird<AccountModel>, res: Response, sendNotFound: boolean) {
37 const account = await p
38
39 if (!account) {
40 if (sendNotFound === true) {
41 res.status(404)
42 .send({ error: 'Account not found' })
43 .end()
44 }
45
46 return false
47 }
48
49 res.locals.account = account
50
51 return true
52}
53
54// --------------------------------------------------------------------------- 17// ---------------------------------------------------------------------------
55 18
56export { 19export {
57 isAccountIdValid, 20 isAccountIdValid,
58 doesAccountIdExist,
59 doesLocalAccountNameExist,
60 isAccountDescriptionValid, 21 isAccountDescriptionValid,
61 doesAccountNameWithHostExist,
62 isAccountNameValid 22 isAccountNameValid
63} 23}