aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/rate.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/videos/rate.ts')
-rw-r--r--server/controllers/api/videos/rate.ts18
1 files changed, 4 insertions, 14 deletions
diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.ts
index 23e9de9f3..9d63b5821 100644
--- a/server/controllers/api/videos/rate.ts
+++ b/server/controllers/api/videos/rate.ts
@@ -1,10 +1,9 @@
1import * as express from 'express' 1import * as express from 'express'
2import { UserVideoRateUpdate } from '../../../../shared' 2import { UserVideoRateUpdate } from '../../../../shared'
3import { retryTransactionWrapper } from '../../../helpers/database-utils'
4import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
5import { sequelizeTypescript, VIDEO_RATE_TYPES } from '../../../initializers' 4import { sequelizeTypescript, VIDEO_RATE_TYPES } from '../../../initializers'
6import { sendVideoRateChange } from '../../../lib/activitypub' 5import { sendVideoRateChange } from '../../../lib/activitypub'
7import { asyncMiddleware, authenticate, videoRateValidator } from '../../../middlewares' 6import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoRateValidator } from '../../../middlewares'
8import { AccountModel } from '../../../models/account/account' 7import { AccountModel } from '../../../models/account/account'
9import { AccountVideoRateModel } from '../../../models/account/account-video-rate' 8import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
10import { VideoModel } from '../../../models/video/video' 9import { VideoModel } from '../../../models/video/video'
@@ -14,7 +13,7 @@ const rateVideoRouter = express.Router()
14rateVideoRouter.put('/:id/rate', 13rateVideoRouter.put('/:id/rate',
15 authenticate, 14 authenticate,
16 asyncMiddleware(videoRateValidator), 15 asyncMiddleware(videoRateValidator),
17 asyncMiddleware(rateVideoRetryWrapper) 16 asyncRetryTransactionMiddleware(rateVideo)
18) 17)
19 18
20// --------------------------------------------------------------------------- 19// ---------------------------------------------------------------------------
@@ -25,17 +24,6 @@ export {
25 24
26// --------------------------------------------------------------------------- 25// ---------------------------------------------------------------------------
27 26
28async function rateVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
29 const options = {
30 arguments: [ req, res ],
31 errorMessage: 'Cannot update the user video rate.'
32 }
33
34 await retryTransactionWrapper(rateVideo, options)
35
36 return res.type('json').status(204).end()
37}
38
39async function rateVideo (req: express.Request, res: express.Response) { 27async function rateVideo (req: express.Request, res: express.Response) {
40 const body: UserVideoRateUpdate = req.body 28 const body: UserVideoRateUpdate = req.body
41 const rateType = body.rating 29 const rateType = body.rating
@@ -87,4 +75,6 @@ async function rateVideo (req: express.Request, res: express.Response) {
87 }) 75 })
88 76
89 logger.info('Account video rate for video %s of account %s updated.', videoInstance.name, accountInstance.name) 77 logger.info('Account video rate for video %s of account %s updated.', videoInstance.name, accountInstance.name)
78
79 return res.type('json').status(204).end()
90} 80}