2021-08-27 08:32:44 -04:00
|
|
|
import express from 'express'
|
2021-07-16 08:27:30 -04:00
|
|
|
import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
|
|
|
|
import { getFormattedObjects } from '../../../helpers/utils'
|
|
|
|
import { sequelizeTypescript } from '../../../initializers/database'
|
2018-12-17 09:52:38 -05:00
|
|
|
import {
|
|
|
|
asyncMiddleware,
|
|
|
|
asyncRetryTransactionMiddleware,
|
|
|
|
authenticate,
|
|
|
|
paginationValidator,
|
|
|
|
setDefaultPagination,
|
2021-01-13 03:16:15 -05:00
|
|
|
userHistoryListValidator,
|
2018-12-17 09:52:38 -05:00
|
|
|
userHistoryRemoveValidator
|
|
|
|
} from '../../../middlewares'
|
2021-05-11 05:15:29 -04:00
|
|
|
import { UserVideoHistoryModel } from '../../../models/user/user-video-history'
|
2018-12-17 09:52:38 -05:00
|
|
|
|
|
|
|
const myVideosHistoryRouter = express.Router()
|
|
|
|
|
|
|
|
myVideosHistoryRouter.get('/me/history/videos',
|
|
|
|
authenticate,
|
|
|
|
paginationValidator,
|
|
|
|
setDefaultPagination,
|
2021-01-13 03:16:15 -05:00
|
|
|
userHistoryListValidator,
|
2018-12-17 09:52:38 -05:00
|
|
|
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 05:35:15 -04:00
|
|
|
const user = res.locals.oauth.token.User
|
2018-12-17 09:52:38 -05:00
|
|
|
|
2021-01-13 03:16:15 -05:00
|
|
|
const resultList = await UserVideoHistoryModel.listForApi(user, req.query.start, req.query.count, req.query.search)
|
2018-12-17 09:52:38 -05:00
|
|
|
|
|
|
|
return res.json(getFormattedObjects(resultList.data, resultList.total))
|
|
|
|
}
|
|
|
|
|
|
|
|
async function removeUserHistory (req: express.Request, res: express.Response) {
|
2019-03-19 05:35:15 -04:00
|
|
|
const user = res.locals.oauth.token.User
|
2018-12-17 09:52:38 -05:00
|
|
|
const beforeDate = req.body.beforeDate || null
|
|
|
|
|
|
|
|
await sequelizeTypescript.transaction(t => {
|
2019-04-11 09:38:53 -04:00
|
|
|
return UserVideoHistoryModel.removeUserHistoryBefore(user, beforeDate, t)
|
2018-12-17 09:52:38 -05:00
|
|
|
})
|
|
|
|
|
2020-12-07 08:32:36 -05:00
|
|
|
return res.type('json')
|
|
|
|
.status(HttpStatusCode.NO_CONTENT_204)
|
|
|
|
.end()
|
2018-12-17 09:52:38 -05:00
|
|
|
}
|