]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/helpers/custom-validators/accounts.ts
Remove unused actor uuid field
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / accounts.ts
CommitLineData
4e50b6a1 1import * as Bluebird from 'bluebird'
a2431b7d 2import { Response } from 'express'
38fa2065 3import 'express-validator'
3fd3ab2d 4import { AccountModel } from '../../models/account/account'
2422c46b 5import { isUserDescriptionValid, isUserUsernameValid } from './users'
d14a9532 6import { exists } from './misc'
38fa2065 7
350e31d6 8function isAccountNameValid (value: string) {
38fa2065
C
9 return isUserUsernameValid(value)
10}
11
d14a9532
C
12function isAccountIdValid (value: string) {
13 return exists(value)
14}
15
2422c46b
C
16function isAccountDescriptionValid (value: string) {
17 return isUserDescriptionValid(value)
18}
19
57cfff78
C
20function doesAccountIdExist (id: number, res: Response, sendNotFound = true) {
21 const promise = AccountModel.load(id)
38fa2065 22
0f6acda1 23 return doesAccountExist(promise, res, sendNotFound)
4e50b6a1
C
24}
25
0f6acda1 26function doesLocalAccountNameExist (name: string, res: Response, sendNotFound = true) {
3fd3ab2d 27 const promise = AccountModel.loadLocalByName(name)
4e50b6a1 28
0f6acda1 29 return doesAccountExist(promise, res, sendNotFound)
4e50b6a1
C
30}
31
0f6acda1
C
32function doesAccountNameWithHostExist (nameWithDomain: string, res: Response, sendNotFound = true) {
33 return doesAccountExist(AccountModel.loadByNameWithHost(nameWithDomain), res, sendNotFound)
e8cb4409
C
34}
35
0f6acda1 36async function doesAccountExist (p: Bluebird<AccountModel>, res: Response, sendNotFound: boolean) {
a2431b7d
C
37 const account = await p
38
39 if (!account) {
d14a9532
C
40 if (sendNotFound === true) {
41 res.status(404)
42 .send({ error: 'Account not found' })
43 .end()
44 }
a2431b7d
C
45
46 return false
47 }
48
49 res.locals.account = account
50
51 return true
38fa2065
C
52}
53
54// ---------------------------------------------------------------------------
55
56export {
d14a9532 57 isAccountIdValid,
0f6acda1
C
58 doesAccountIdExist,
59 doesLocalAccountNameExist,
2422c46b 60 isAccountDescriptionValid,
0f6acda1 61 doesAccountNameWithHostExist,
350e31d6 62 isAccountNameValid
38fa2065 63}