From 65fcc3119c334b75dd13bcfdebf186afdc580a8f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 15 May 2017 22:22:03 +0200 Subject: First typescript iteration --- server/controllers/api/videos/blacklist.ts | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 server/controllers/api/videos/blacklist.ts (limited to 'server/controllers/api/videos/blacklist.ts') diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts new file mode 100644 index 000000000..db6d95e73 --- /dev/null +++ b/server/controllers/api/videos/blacklist.ts @@ -0,0 +1,43 @@ +import express = require('express') + +const db = require('../../../initializers/database') +import { logger } from '../../../helpers' +import { + authenticate, + ensureIsAdmin, + videosBlacklistValidator +} from '../../../middlewares' + +const blacklistRouter = express.Router() + +blacklistRouter.post('/:id/blacklist', + authenticate, + ensureIsAdmin, + videosBlacklistValidator, + addVideoToBlacklist +) + +// --------------------------------------------------------------------------- + +export { + blacklistRouter +} + +// --------------------------------------------------------------------------- + +function addVideoToBlacklist (req, res, next) { + const videoInstance = res.locals.video + + const toCreate = { + videoId: videoInstance.id + } + + db.BlacklistedVideo.create(toCreate).asCallback(function (err) { + if (err) { + logger.error('Errors when blacklisting video ', { error: err }) + return next(err) + } + + return res.type('json').status(204).end() + }) +} -- cgit v1.2.3