1 import { Response } from 'express'
2 import * as validator from 'validator'
3 import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers'
4 import { exists } from './misc'
5 import { VideoAbuseModel } from '../../models/video/video-abuse'
7 const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES
9 function isVideoAbuseReasonValid (value: string) {
10 return exists(value) && validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.REASON)
13 function isVideoAbuseModerationCommentValid (value: string) {
14 return exists(value) && validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.MODERATION_COMMENT)
17 function isVideoAbuseStateValid (value: string) {
18 return exists(value) && VIDEO_ABUSE_STATES[ value ] !== undefined
21 async function isVideoAbuseExist (abuseId: number, videoId: number, res: Response) {
22 const videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, videoId)
24 if (videoAbuse === null) {
26 .json({ error: 'Video abuse not found' })
32 res.locals.videoAbuse = videoAbuse
36 // ---------------------------------------------------------------------------
40 isVideoAbuseStateValid,
41 isVideoAbuseReasonValid,
42 isVideoAbuseModerationCommentValid