From 7177b46ca1b35aa9d7ed39a06c1dcf41a4fc6180 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 18 Jan 2022 11:23:41 +0100 Subject: Add ability to delete history element --- server/controllers/api/users/my-history.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'server/controllers') diff --git a/server/controllers/api/users/my-history.ts b/server/controllers/api/users/my-history.ts index 2fcb25acf..bc5b40f59 100644 --- a/server/controllers/api/users/my-history.ts +++ b/server/controllers/api/users/my-history.ts @@ -9,7 +9,8 @@ import { paginationValidator, setDefaultPagination, userHistoryListValidator, - userHistoryRemoveValidator + userHistoryRemoveAllValidator, + userHistoryRemoveElementValidator } from '../../../middlewares' import { UserVideoHistoryModel } from '../../../models/user/user-video-history' @@ -23,10 +24,16 @@ myVideosHistoryRouter.get('/me/history/videos', asyncMiddleware(listMyVideosHistory) ) +myVideosHistoryRouter.delete('/me/history/videos/:videoId', + authenticate, + userHistoryRemoveElementValidator, + asyncMiddleware(removeUserHistoryElement) +) + myVideosHistoryRouter.post('/me/history/videos/remove', authenticate, - userHistoryRemoveValidator, - asyncRetryTransactionMiddleware(removeUserHistory) + userHistoryRemoveAllValidator, + asyncRetryTransactionMiddleware(removeAllUserHistory) ) // --------------------------------------------------------------------------- @@ -45,7 +52,15 @@ async function listMyVideosHistory (req: express.Request, res: express.Response) return res.json(getFormattedObjects(resultList.data, resultList.total)) } -async function removeUserHistory (req: express.Request, res: express.Response) { +async function removeUserHistoryElement (req: express.Request, res: express.Response) { + const user = res.locals.oauth.token.User + + await UserVideoHistoryModel.removeUserHistoryElement(user, parseInt(req.params.videoId + '')) + + return res.sendStatus(HttpStatusCode.NO_CONTENT_204) +} + +async function removeAllUserHistory (req: express.Request, res: express.Response) { const user = res.locals.oauth.token.User const beforeDate = req.body.beforeDate || null -- cgit v1.2.3