aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/follows.ts
blob: 0bec683c167481d07447b1388f786ef187c481a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { exists, isArray } from './misc'
import { FollowState } from '@shared/models'

function isFollowStateValid (value: FollowState) {
  if (!exists(value)) return false

  return value === 'pending' || value === 'accepted' || value === 'rejected'
}

function isRemoteHandleValid (value: string) {
  if (!exists(value)) return false
  if (typeof value !== 'string') return false

  return value.includes('@')
}

function isEachUniqueHandleValid (handles: string[]) {
  return isArray(handles) &&
    handles.every(handle => {
      return isRemoteHandleValid(handle) && handles.indexOf(handle) === handles.lastIndexOf(handle)
    })
}

// ---------------------------------------------------------------------------

export {
  isFollowStateValid,
  isRemoteHandleValid,
  isEachUniqueHandleValid
}