aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/middlewares/validators/account.ts
blob: 551f67d61fb68dc8d0a506b9cdddfe275dca7ef9 (plain) (tree)
1
2
3
4
5
6
7
8
9
                             
                                         
                                                                             
                                                                                                       

                               

                                
 
                                                                                      
                                             
                                                                      

                 


   
                                         

                      

                                                                                      
                                             
                                                                                




                 


                                                                              
                        
                                 
 
import express from 'express'
import { param } from 'express-validator'
import { isAccountNameValid } from '../../helpers/custom-validators/accounts'
import { areValidationErrors, doesAccountNameWithHostExist, doesLocalAccountNameExist } from './shared'

const localAccountValidator = [
  param('name')
    .custom(isAccountNameValid),

  async (req: express.Request, res: express.Response, next: express.NextFunction) => {
    if (areValidationErrors(req, res)) return
    if (!await doesLocalAccountNameExist(req.params.name, res)) return

    return next()
  }
]

const accountNameWithHostGetValidator = [
  param('accountName')
    .exists(),

  async (req: express.Request, res: express.Response, next: express.NextFunction) => {
    if (areValidationErrors(req, res)) return
    if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return

    return next()
  }
]

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

export {
  localAccountValidator,
  accountNameWithHostGetValidator
}