2018-06-29 05:29:23 -04:00
|
|
|
import * as express from 'express'
|
|
|
|
import { body } from 'express-validator/check'
|
|
|
|
import { isAvatarFile } from '../../helpers/custom-validators/users'
|
|
|
|
import { areValidationErrors } from './utils'
|
2019-04-11 08:26:41 -04:00
|
|
|
import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
|
2018-06-29 05:29:23 -04:00
|
|
|
import { logger } from '../../helpers/logger'
|
2018-08-14 09:28:30 -04:00
|
|
|
import { cleanUpReqFiles } from '../../helpers/express-utils'
|
2018-06-29 05:29:23 -04:00
|
|
|
|
|
|
|
const updateAvatarValidator = [
|
|
|
|
body('avatarfile').custom((value, { req }) => isAvatarFile(req.files)).withMessage(
|
|
|
|
'This file is not supported or too large. Please, make sure it is of the following type : '
|
|
|
|
+ CONSTRAINTS_FIELDS.ACTORS.AVATAR.EXTNAME.join(', ')
|
|
|
|
),
|
|
|
|
|
|
|
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
logger.debug('Checking updateAvatarValidator parameters', { files: req.files })
|
|
|
|
|
2018-07-31 09:09:34 -04:00
|
|
|
if (areValidationErrors(req, res)) return cleanUpReqFiles(req)
|
2018-06-29 05:29:23 -04:00
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
export {
|
|
|
|
updateAvatarValidator
|
|
|
|
}
|