diff options
Diffstat (limited to 'server/controllers/api/videos/abuse.ts')
-rw-r--r-- | server/controllers/api/videos/abuse.ts | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index 08e11b00b..d0c81804b 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.ts | |||
@@ -21,6 +21,7 @@ import { AccountModel } from '../../../models/account/account' | |||
21 | import { VideoModel } from '../../../models/video/video' | 21 | import { VideoModel } from '../../../models/video/video' |
22 | import { VideoAbuseModel } from '../../../models/video/video-abuse' | 22 | import { VideoAbuseModel } from '../../../models/video/video-abuse' |
23 | import { auditLoggerFactory, VideoAbuseAuditView } from '../../../helpers/audit-logger' | 23 | import { auditLoggerFactory, VideoAbuseAuditView } from '../../../helpers/audit-logger' |
24 | import { UserModel } from '../../../models/account/user' | ||
24 | 25 | ||
25 | const auditLogger = auditLoggerFactory('abuse') | 26 | const auditLogger = auditLoggerFactory('abuse') |
26 | const abuseVideoRouter = express.Router() | 27 | const abuseVideoRouter = express.Router() |
@@ -95,17 +96,18 @@ async function deleteVideoAbuse (req: express.Request, res: express.Response) { | |||
95 | 96 | ||
96 | async function reportVideoAbuse (req: express.Request, res: express.Response) { | 97 | async function reportVideoAbuse (req: express.Request, res: express.Response) { |
97 | const videoInstance = res.locals.video as VideoModel | 98 | const videoInstance = res.locals.video as VideoModel |
98 | const reporterAccount = res.locals.oauth.token.User.Account as AccountModel | ||
99 | const body: VideoAbuseCreate = req.body | 99 | const body: VideoAbuseCreate = req.body |
100 | 100 | ||
101 | const abuseToCreate = { | ||
102 | reporterAccountId: reporterAccount.id, | ||
103 | reason: body.reason, | ||
104 | videoId: videoInstance.id, | ||
105 | state: VideoAbuseState.PENDING | ||
106 | } | ||
107 | |||
108 | const videoAbuse: VideoAbuseModel = await sequelizeTypescript.transaction(async t => { | 101 | const videoAbuse: VideoAbuseModel = await sequelizeTypescript.transaction(async t => { |
102 | const reporterAccount = await AccountModel.load((res.locals.oauth.token.User as UserModel).Account.id, t) | ||
103 | |||
104 | const abuseToCreate = { | ||
105 | reporterAccountId: reporterAccount.id, | ||
106 | reason: body.reason, | ||
107 | videoId: videoInstance.id, | ||
108 | state: VideoAbuseState.PENDING | ||
109 | } | ||
110 | |||
109 | const videoAbuseInstance = await VideoAbuseModel.create(abuseToCreate, { transaction: t }) | 111 | const videoAbuseInstance = await VideoAbuseModel.create(abuseToCreate, { transaction: t }) |
110 | videoAbuseInstance.Video = videoInstance | 112 | videoAbuseInstance.Video = videoInstance |
111 | videoAbuseInstance.Account = reporterAccount | 113 | videoAbuseInstance.Account = reporterAccount |
@@ -121,7 +123,6 @@ async function reportVideoAbuse (req: express.Request, res: express.Response) { | |||
121 | }) | 123 | }) |
122 | 124 | ||
123 | logger.info('Abuse report for video %s created.', videoInstance.name) | 125 | logger.info('Abuse report for video %s created.', videoInstance.name) |
124 | return res.json({ | 126 | |
125 | videoAbuse: videoAbuse.toFormattedJSON() | 127 | return res.json({ videoAbuse: videoAbuse.toFormattedJSON() }).end() |
126 | }).end() | ||
127 | } | 128 | } |