1 import express from 'express'
2 import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
3 import { getFormattedObjects } from '../../../helpers/utils'
4 import { sequelizeTypescript } from '../../../initializers/database'
7 asyncRetryTransactionMiddleware,
11 userHistoryListValidator,
12 userHistoryRemoveValidator
13 } from '../../../middlewares'
14 import { UserVideoHistoryModel } from '../../../models/user/user-video-history'
16 const myVideosHistoryRouter = express.Router()
18 myVideosHistoryRouter.get('/me/history/videos',
22 userHistoryListValidator,
23 asyncMiddleware(listMyVideosHistory)
26 myVideosHistoryRouter.post('/me/history/videos/remove',
28 userHistoryRemoveValidator,
29 asyncRetryTransactionMiddleware(removeUserHistory)
32 // ---------------------------------------------------------------------------
38 // ---------------------------------------------------------------------------
40 async function listMyVideosHistory (req: express.Request, res: express.Response) {
41 const user = res.locals.oauth.token.User
43 const resultList = await UserVideoHistoryModel.listForApi(user, req.query.start, req.query.count, req.query.search)
45 return res.json(getFormattedObjects(resultList.data, resultList.total))
48 async function removeUserHistory (req: express.Request, res: express.Response) {
49 const user = res.locals.oauth.token.User
50 const beforeDate = req.body.beforeDate || null
52 await sequelizeTypescript.transaction(t => {
53 return UserVideoHistoryModel.removeUserHistoryBefore(user, beforeDate, t)
56 return res.type('json')
57 .status(HttpStatusCode.NO_CONTENT_204)