1 import express from 'express'
2 import { HttpStatusCode, UserWatchingVideo } from '@shared/models'
5 asyncRetryTransactionMiddleware,
9 } from '../../../middlewares'
10 import { UserVideoHistoryModel } from '../../../models/user/user-video-history'
12 const watchingRouter = express.Router()
14 watchingRouter.put('/:videoId/watching',
15 openapiOperationDoc({ operationId: 'setProgress' }),
17 asyncMiddleware(videoWatchingValidator),
18 asyncRetryTransactionMiddleware(userWatchVideo)
21 // ---------------------------------------------------------------------------
27 // ---------------------------------------------------------------------------
29 async function userWatchVideo (req: express.Request, res: express.Response) {
30 const user = res.locals.oauth.token.User
32 const body: UserWatchingVideo = req.body
33 const { id: videoId } = res.locals.videoId
35 await UserVideoHistoryModel.upsert({
38 currentTime: body.currentTime
41 return res.type('json')
42 .status(HttpStatusCode.NO_CONTENT_204)