diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-12 17:53:50 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-13 16:50:33 +0100 |
commit | 3fd3ab2d34d512b160a5e6084d7609be7b4f4452 (patch) | |
tree | e5ca358287fca6ecacce83defcf23af1e8e9f419 /server/controllers/api/videos/abuse.ts | |
parent | c893d4514e6ecbf282c7985fe5f82b8acd8a1137 (diff) | |
download | PeerTube-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.ts | 17 |
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | |||
3 | import { database as db } from '../../../initializers/database' | ||
4 | import { | 2 | import { |
5 | logger, | 3 | logger, |
6 | getFormattedObjects, | 4 | getFormattedObjects, |
7 | retryTransactionWrapper | 5 | retryTransactionWrapper |
8 | } from '../../../helpers' | 6 | } from '../../../helpers' |
7 | import { sequelizeTypescript } from '../../../initializers' | ||
9 | import { | 8 | import { |
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' |
19 | import { VideoInstance } from '../../../models' | ||
20 | import { VideoAbuseCreate, UserRight } from '../../../../shared' | 18 | import { VideoAbuseCreate, UserRight } from '../../../../shared' |
21 | import { sendVideoAbuse } from '../../../lib/index' | 19 | import { sendVideoAbuse } from '../../../lib/index' |
20 | import { AccountModel } from '../../../models/account/account' | ||
21 | import { VideoModel } from '../../../models/video/video' | ||
22 | import { VideoAbuseModel } from '../../../models/video/video-abuse' | ||
22 | 23 | ||
23 | const abuseVideoRouter = express.Router() | 24 | const abuseVideoRouter = express.Router() |
24 | 25 | ||
@@ -46,7 +47,7 @@ export { | |||
46 | // --------------------------------------------------------------------------- | 47 | // --------------------------------------------------------------------------- |
47 | 48 | ||
48 | async function listVideoAbuses (req: express.Request, res: express.Response, next: express.NextFunction) { | 49 | async 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 | ||
65 | async function reportVideoAbuse (req: express.Request, res: express.Response) { | 66 | async 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 |