Add jobs tag to logger
This commit is contained in:
parent
db4b15f21f
commit
18b24b2dc5
|
@ -9,10 +9,10 @@ import {
|
|||
authenticate,
|
||||
ensureUserHasRight,
|
||||
jobsSortValidator,
|
||||
paginationValidatorBuilder,
|
||||
setDefaultPagination,
|
||||
setDefaultSort
|
||||
} from '../../middlewares'
|
||||
import { paginationValidator } from '../../middlewares/validators'
|
||||
import { listJobsValidator } from '../../middlewares/validators/jobs'
|
||||
|
||||
const jobsRouter = express.Router()
|
||||
|
@ -20,7 +20,7 @@ const jobsRouter = express.Router()
|
|||
jobsRouter.get('/:state?',
|
||||
authenticate,
|
||||
ensureUserHasRight(UserRight.MANAGE_JOBS),
|
||||
paginationValidator,
|
||||
paginationValidatorBuilder([ 'jobs' ]),
|
||||
jobsSortValidator,
|
||||
setDefaultSort,
|
||||
setDefaultPagination,
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import * as express from 'express'
|
||||
import { param, query } from 'express-validator'
|
||||
import { isValidJobState, isValidJobType } from '../../helpers/custom-validators/jobs'
|
||||
import { logger } from '../../helpers/logger'
|
||||
import { logger, loggerTagsFactory } from '../../helpers/logger'
|
||||
import { areValidationErrors } from './utils'
|
||||
|
||||
const lTags = loggerTagsFactory('validators', 'jobs')
|
||||
|
||||
const listJobsValidator = [
|
||||
param('state')
|
||||
.optional()
|
||||
|
@ -14,7 +16,7 @@ const listJobsValidator = [
|
|||
.custom(isValidJobType).withMessage('Should have a valid job state'),
|
||||
|
||||
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||
logger.debug('Checking listJobsValidator parameters.', { parameters: req.params })
|
||||
logger.debug('Checking listJobsValidator parameters.', { parameters: req.params, ...lTags() })
|
||||
|
||||
if (areValidationErrors(req, res)) return
|
||||
|
||||
|
|
|
@ -4,25 +4,30 @@ import { logger } from '../../helpers/logger'
|
|||
import { areValidationErrors } from './utils'
|
||||
import { PAGINATION } from '@server/initializers/constants'
|
||||
|
||||
const paginationValidator = [
|
||||
query('start')
|
||||
.optional()
|
||||
.isInt({ min: 0 }).withMessage('Should have a number start'),
|
||||
query('count')
|
||||
.optional()
|
||||
.isInt({ min: 0, max: PAGINATION.GLOBAL.COUNT.MAX }).withMessage(`Should have a number count (max: ${PAGINATION.GLOBAL.COUNT.MAX})`),
|
||||
const paginationValidator = paginationValidatorBuilder()
|
||||
|
||||
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||
logger.debug('Checking pagination parameters', { parameters: req.query })
|
||||
function paginationValidatorBuilder (tags: string[] = []) {
|
||||
return [
|
||||
query('start')
|
||||
.optional()
|
||||
.isInt({ min: 0 }).withMessage('Should have a number start'),
|
||||
query('count')
|
||||
.optional()
|
||||
.isInt({ min: 0, max: PAGINATION.GLOBAL.COUNT.MAX }).withMessage(`Should have a number count (max: ${PAGINATION.GLOBAL.COUNT.MAX})`),
|
||||
|
||||
if (areValidationErrors(req, res)) return
|
||||
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||
logger.debug('Checking pagination parameters', { parameters: req.query, tags })
|
||||
|
||||
return next()
|
||||
}
|
||||
]
|
||||
if (areValidationErrors(req, res)) return
|
||||
|
||||
return next()
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
paginationValidator
|
||||
paginationValidator,
|
||||
paginationValidatorBuilder
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ const SORTABLE_VIDEO_REDUNDANCIES_COLUMNS = createSortableColumns(SORTABLE_COLUM
|
|||
|
||||
const usersSortValidator = checkSort(SORTABLE_USERS_COLUMNS)
|
||||
const accountsSortValidator = checkSort(SORTABLE_ACCOUNTS_COLUMNS)
|
||||
const jobsSortValidator = checkSort(SORTABLE_JOBS_COLUMNS)
|
||||
const jobsSortValidator = checkSort(SORTABLE_JOBS_COLUMNS, [ 'jobs' ])
|
||||
const abusesSortValidator = checkSort(SORTABLE_ABUSES_COLUMNS)
|
||||
const videosSortValidator = checkSort(SORTABLE_VIDEOS_COLUMNS)
|
||||
const videoImportsSortValidator = checkSort(SORTABLE_VIDEO_IMPORTS_COLUMNS)
|
||||
|
|
|
@ -17,12 +17,12 @@ function areValidationErrors (req: express.Request, res: express.Response) {
|
|||
return false
|
||||
}
|
||||
|
||||
function checkSort (sortableColumns: string[]) {
|
||||
function checkSort (sortableColumns: string[], tags: string[] = []) {
|
||||
return [
|
||||
query('sort').optional().isIn(sortableColumns).withMessage('Should have correct sortable column'),
|
||||
|
||||
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||
logger.debug('Checking sort parameters', { parameters: req.query })
|
||||
logger.debug('Checking sort parameters', { parameters: req.query, tags })
|
||||
|
||||
if (areValidationErrors(req, res)) return
|
||||
|
||||
|
|
Loading…
Reference in New Issue