2018-12-17 08:52:38 -06:00
|
|
|
import * as express from 'express'
|
|
|
|
import {
|
|
|
|
asyncMiddleware,
|
|
|
|
asyncRetryTransactionMiddleware,
|
|
|
|
authenticate,
|
|
|
|
paginationValidator,
|
|
|
|
setDefaultPagination,
|
|
|
|
userHistoryRemoveValidator
|
|
|
|
} from '../../../middlewares'
|
|
|
|
import { getFormattedObjects } from '../../../helpers/utils'
|
|
|
|
import { UserVideoHistoryModel } from '../../../models/account/user-video-history'
|
2020-05-07 07:58:24 -05:00
|
|
|
import { sequelizeTypescript } from '../../../initializers/database'
|
2020-12-07 07:32:36 -06:00
|
|
|
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
2018-12-17 08:52:38 -06:00
|
|
|
|
|
|
|
const myVideosHistoryRouter = express.Router()
|
|
|
|
|
|
|
|
myVideosHistoryRouter.get('/me/history/videos',
|
|
|
|
authenticate,
|
|
|
|
paginationValidator,
|
|
|
|
setDefaultPagination,
|
|
|
|
asyncMiddleware(listMyVideosHistory)
|
|
|
|
)
|
|
|
|
|
|
|
|
myVideosHistoryRouter.post('/me/history/videos/remove',
|
|
|
|
authenticate,
|
|
|
|
userHistoryRemoveValidator,
|
|
|
|
asyncRetryTransactionMiddleware(removeUserHistory)
|
|
|
|
)
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
myVideosHistoryRouter
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
async function listMyVideosHistory (req: express.Request, res: express.Response) {
|
2019-03-19 04:35:15 -05:00
|
|
|
const user = res.locals.oauth.token.User
|
2018-12-17 08:52:38 -06:00
|
|
|
|
|
|
|
const resultList = await UserVideoHistoryModel.listForApi(user, req.query.start, req.query.count)
|
|
|
|
|
|
|
|
return res.json(getFormattedObjects(resultList.data, resultList.total))
|
|
|
|
}
|
|
|
|
|
|
|
|
async function removeUserHistory (req: express.Request, res: express.Response) {
|
2019-03-19 04:35:15 -05:00
|
|
|
const user = res.locals.oauth.token.User
|
2018-12-17 08:52:38 -06:00
|
|
|
const beforeDate = req.body.beforeDate || null
|
|
|
|
|
|
|
|
await sequelizeTypescript.transaction(t => {
|
2019-04-11 08:38:53 -05:00
|
|
|
return UserVideoHistoryModel.removeUserHistoryBefore(user, beforeDate, t)
|
2018-12-17 08:52:38 -06:00
|
|
|
})
|
|
|
|
|
2020-12-07 07:32:36 -06:00
|
|
|
return res.type('json')
|
|
|
|
.status(HttpStatusCode.NO_CONTENT_204)
|
|
|
|
.end()
|
2018-12-17 08:52:38 -06:00
|
|
|
}
|