aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/abuse.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-12 17:53:50 +0100
committerChocobozzz <me@florianbigard.com>2017-12-13 16:50:33 +0100
commit3fd3ab2d34d512b160a5e6084d7609be7b4f4452 (patch)
treee5ca358287fca6ecacce83defcf23af1e8e9f419 /server/controllers/api/videos/abuse.ts
parentc893d4514e6ecbf282c7985fe5f82b8acd8a1137 (diff)
downloadPeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.gz
PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.zst
PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.zip
Move models to typescript-sequelize
Diffstat (limited to 'server/controllers/api/videos/abuse.ts')
-rw-r--r--server/controllers/api/videos/abuse.ts17
1 files changed, 9 insertions, 8 deletions
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts
index 29e1175c5..08cc4d0b4 100644
--- a/server/controllers/api/videos/abuse.ts
+++ b/server/controllers/api/videos/abuse.ts
@@ -1,11 +1,10 @@
1import * as express from 'express' 1import * as express from 'express'
2
3import { database as db } from '../../../initializers/database'
4import { 2import {
5 logger, 3 logger,
6 getFormattedObjects, 4 getFormattedObjects,
7 retryTransactionWrapper 5 retryTransactionWrapper
8} from '../../../helpers' 6} from '../../../helpers'
7import { sequelizeTypescript } from '../../../initializers'
9import { 8import {
10 authenticate, 9 authenticate,
11 ensureUserHasRight, 10 ensureUserHasRight,
@@ -16,9 +15,11 @@ import {
16 setPagination, 15 setPagination,
17 asyncMiddleware 16 asyncMiddleware
18} from '../../../middlewares' 17} from '../../../middlewares'
19import { VideoInstance } from '../../../models'
20import { VideoAbuseCreate, UserRight } from '../../../../shared' 18import { VideoAbuseCreate, UserRight } from '../../../../shared'
21import { sendVideoAbuse } from '../../../lib/index' 19import { sendVideoAbuse } from '../../../lib/index'
20import { AccountModel } from '../../../models/account/account'
21import { VideoModel } from '../../../models/video/video'
22import { VideoAbuseModel } from '../../../models/video/video-abuse'
22 23
23const abuseVideoRouter = express.Router() 24const abuseVideoRouter = express.Router()
24 25
@@ -46,7 +47,7 @@ export {
46// --------------------------------------------------------------------------- 47// ---------------------------------------------------------------------------
47 48
48async function listVideoAbuses (req: express.Request, res: express.Response, next: express.NextFunction) { 49async function listVideoAbuses (req: express.Request, res: express.Response, next: express.NextFunction) {
49 const resultList = await db.VideoAbuse.listForApi(req.query.start, req.query.count, req.query.sort) 50 const resultList = await VideoAbuseModel.listForApi(req.query.start, req.query.count, req.query.sort)
50 51
51 return res.json(getFormattedObjects(resultList.data, resultList.total)) 52 return res.json(getFormattedObjects(resultList.data, resultList.total))
52} 53}
@@ -63,8 +64,8 @@ async function reportVideoAbuseRetryWrapper (req: express.Request, res: express.
63} 64}
64 65
65async function reportVideoAbuse (req: express.Request, res: express.Response) { 66async function reportVideoAbuse (req: express.Request, res: express.Response) {
66 const videoInstance = res.locals.video as VideoInstance 67 const videoInstance = res.locals.video as VideoModel
67 const reporterAccount = res.locals.oauth.token.User.Account 68 const reporterAccount = res.locals.oauth.token.User.Account as AccountModel
68 const body: VideoAbuseCreate = req.body 69 const body: VideoAbuseCreate = req.body
69 70
70 const abuseToCreate = { 71 const abuseToCreate = {
@@ -73,8 +74,8 @@ async function reportVideoAbuse (req: express.Request, res: express.Response) {
73 videoId: videoInstance.id 74 videoId: videoInstance.id
74 } 75 }
75 76
76 await db.sequelize.transaction(async t => { 77 await sequelizeTypescript.transaction(async t => {
77 const videoAbuseInstance = await db.VideoAbuse.create(abuseToCreate, { transaction: t }) 78 const videoAbuseInstance = await VideoAbuseModel.create(abuseToCreate, { transaction: t })
78 videoAbuseInstance.Video = videoInstance 79 videoAbuseInstance.Video = videoInstance
79 80
80 // We send the video abuse to the origin server 81 // We send the video abuse to the origin server