+ const nextPosition = await VideoPlaylistElementModel.getNextPositionOf(videoPlaylist.id)
+ const startPosition: number = req.body.startPosition
+ const insertAfterPosition: number = req.body.insertAfterPosition
+ const reorderLength: number = req.body.reorderLength
+
+ if (startPosition >= nextPosition || insertAfterPosition >= nextPosition) {
+ res.fail({ message: `Start position or insert after position exceed the playlist limits (max: ${nextPosition - 1})` })
+ return
+ }
+
+ if (reorderLength && reorderLength + startPosition > nextPosition) {
+ res.fail({ message: `Reorder length with this start position exceeds the playlist limits (max: ${nextPosition - startPosition})` })
+ return
+ }
+
+ return next()
+ }
+]
+
+const commonVideoPlaylistFiltersValidator = [
+ query('playlistType')
+ .optional()
+ .custom(isVideoPlaylistTypeValid).withMessage('Should have a valid playlist type'),
+
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking commonVideoPlaylistFiltersValidator parameters', { parameters: req.params })
+
+ if (areValidationErrors(req, res)) return
+
+ return next()
+ }
+]
+
+const doVideosInPlaylistExistValidator = [
+ query('videoIds')
+ .customSanitizer(toIntArray)
+ .custom(v => isArrayOf(v, isIdValid)).withMessage('Should have a valid video ids array'),
+
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking areVideosInPlaylistExistValidator parameters', { parameters: req.query })
+
+ if (areValidationErrors(req, res)) return
+