import {
asyncMiddleware,
asyncRetryTransactionMiddleware,
- authenticate, optionalAuthenticate,
+ authenticate,
+ optionalAuthenticate,
paginationValidator,
setDefaultPagination,
setDefaultSort
removeVideoCommentValidator,
videoCommentThreadsSortValidator
} from '../../../middlewares/validators'
-import { VideoModel } from '../../../models/video/video'
import { VideoCommentModel } from '../../../models/video/video-comment'
import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger'
import { AccountModel } from '../../../models/account/account'
-import { UserModel } from '../../../models/account/user'
+import { Notifier } from '../../../lib/notifier'
const auditLogger = auditLoggerFactory('comments')
const videoCommentRouter = express.Router()
// ---------------------------------------------------------------------------
-async function listVideoThreads (req: express.Request, res: express.Response, next: express.NextFunction) {
- const video = res.locals.video as VideoModel
- const user: UserModel = res.locals.oauth ? res.locals.oauth.token.User : undefined
+async function listVideoThreads (req: express.Request, res: express.Response) {
+ const video = res.locals.video
+ const user = res.locals.oauth ? res.locals.oauth.token.User : undefined
let resultList: ResultList<VideoCommentModel>
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
-async function listVideoThreadComments (req: express.Request, res: express.Response, next: express.NextFunction) {
- const video = res.locals.video as VideoModel
- const user: UserModel = res.locals.oauth ? res.locals.oauth.token.User : undefined
+async function listVideoThreadComments (req: express.Request, res: express.Response) {
+ const video = res.locals.video
+ const user = res.locals.oauth ? res.locals.oauth.token.User : undefined
let resultList: ResultList<VideoCommentModel>
const videoCommentInfo: VideoCommentCreate = req.body
const comment = await sequelizeTypescript.transaction(async t => {
- const account = await AccountModel.load((res.locals.oauth.token.User as UserModel).Account.id, t)
+ const account = await AccountModel.load(res.locals.oauth.token.User.Account.id, t)
return createVideoComment({
text: videoCommentInfo.text,
}, t)
})
+ Notifier.Instance.notifyOnNewComment(comment)
auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON()))
return res.json({
const videoCommentInfo: VideoCommentCreate = req.body
const comment = await sequelizeTypescript.transaction(async t => {
- const account = await AccountModel.load((res.locals.oauth.token.User as UserModel).Account.id, t)
+ const account = await AccountModel.load(res.locals.oauth.token.User.Account.id, t)
return createVideoComment({
text: videoCommentInfo.text,
}, t)
})
+ Notifier.Instance.notifyOnNewComment(comment)
auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON()))
return res.json({ comment: comment.toFormattedJSON() }).end()
}
async function removeVideoComment (req: express.Request, res: express.Response) {
- const videoCommentInstance: VideoCommentModel = res.locals.videoComment
+ const videoCommentInstance = res.locals.videoComment
await sequelizeTypescript.transaction(async t => {
await videoCommentInstance.destroy({ transaction: t })