mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 02:09:37 +02:00
server/server -> server/core
This commit is contained in:
parent
114327d4ce
commit
5a3d0650c9
838 changed files with 111 additions and 111 deletions
115
server/core/controllers/api/users/my-notifications.ts
Normal file
115
server/core/controllers/api/users/my-notifications.ts
Normal file
|
@ -0,0 +1,115 @@
|
|||
import 'multer'
|
||||
import express from 'express'
|
||||
import { HttpStatusCode, UserNotificationSetting } from '@peertube/peertube-models'
|
||||
import { getFormattedObjects } from '@server/helpers/utils.js'
|
||||
import { UserNotificationModel } from '@server/models/user/user-notification.js'
|
||||
import {
|
||||
asyncMiddleware,
|
||||
asyncRetryTransactionMiddleware,
|
||||
authenticate,
|
||||
paginationValidator,
|
||||
setDefaultPagination,
|
||||
setDefaultSort,
|
||||
userNotificationsSortValidator
|
||||
} from '../../../middlewares/index.js'
|
||||
import {
|
||||
listUserNotificationsValidator,
|
||||
markAsReadUserNotificationsValidator,
|
||||
updateNotificationSettingsValidator
|
||||
} from '../../../middlewares/validators/user-notifications.js'
|
||||
import { UserNotificationSettingModel } from '../../../models/user/user-notification-setting.js'
|
||||
import { meRouter } from './me.js'
|
||||
|
||||
const myNotificationsRouter = express.Router()
|
||||
|
||||
meRouter.put('/me/notification-settings',
|
||||
authenticate,
|
||||
updateNotificationSettingsValidator,
|
||||
asyncRetryTransactionMiddleware(updateNotificationSettings)
|
||||
)
|
||||
|
||||
myNotificationsRouter.get('/me/notifications',
|
||||
authenticate,
|
||||
paginationValidator,
|
||||
userNotificationsSortValidator,
|
||||
setDefaultSort,
|
||||
setDefaultPagination,
|
||||
listUserNotificationsValidator,
|
||||
asyncMiddleware(listUserNotifications)
|
||||
)
|
||||
|
||||
myNotificationsRouter.post('/me/notifications/read',
|
||||
authenticate,
|
||||
markAsReadUserNotificationsValidator,
|
||||
asyncMiddleware(markAsReadUserNotifications)
|
||||
)
|
||||
|
||||
myNotificationsRouter.post('/me/notifications/read-all',
|
||||
authenticate,
|
||||
asyncMiddleware(markAsReadAllUserNotifications)
|
||||
)
|
||||
|
||||
export {
|
||||
myNotificationsRouter
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function updateNotificationSettings (req: express.Request, res: express.Response) {
|
||||
const user = res.locals.oauth.token.User
|
||||
const body = req.body as UserNotificationSetting
|
||||
|
||||
const query = {
|
||||
where: {
|
||||
userId: user.id
|
||||
}
|
||||
}
|
||||
|
||||
const values: UserNotificationSetting = {
|
||||
newVideoFromSubscription: body.newVideoFromSubscription,
|
||||
newCommentOnMyVideo: body.newCommentOnMyVideo,
|
||||
abuseAsModerator: body.abuseAsModerator,
|
||||
videoAutoBlacklistAsModerator: body.videoAutoBlacklistAsModerator,
|
||||
blacklistOnMyVideo: body.blacklistOnMyVideo,
|
||||
myVideoPublished: body.myVideoPublished,
|
||||
myVideoImportFinished: body.myVideoImportFinished,
|
||||
newFollow: body.newFollow,
|
||||
newUserRegistration: body.newUserRegistration,
|
||||
commentMention: body.commentMention,
|
||||
newInstanceFollower: body.newInstanceFollower,
|
||||
autoInstanceFollowing: body.autoInstanceFollowing,
|
||||
abuseNewMessage: body.abuseNewMessage,
|
||||
abuseStateChange: body.abuseStateChange,
|
||||
newPeerTubeVersion: body.newPeerTubeVersion,
|
||||
newPluginVersion: body.newPluginVersion,
|
||||
myVideoStudioEditionFinished: body.myVideoStudioEditionFinished
|
||||
}
|
||||
|
||||
await UserNotificationSettingModel.update(values, query)
|
||||
|
||||
return res.status(HttpStatusCode.NO_CONTENT_204).end()
|
||||
}
|
||||
|
||||
async function listUserNotifications (req: express.Request, res: express.Response) {
|
||||
const user = res.locals.oauth.token.User
|
||||
|
||||
const resultList = await UserNotificationModel.listForApi(user.id, req.query.start, req.query.count, req.query.sort, req.query.unread)
|
||||
|
||||
return res.json(getFormattedObjects(resultList.data, resultList.total))
|
||||
}
|
||||
|
||||
async function markAsReadUserNotifications (req: express.Request, res: express.Response) {
|
||||
const user = res.locals.oauth.token.User
|
||||
|
||||
await UserNotificationModel.markAsRead(user.id, req.body.ids)
|
||||
|
||||
return res.status(HttpStatusCode.NO_CONTENT_204).end()
|
||||
}
|
||||
|
||||
async function markAsReadAllUserNotifications (req: express.Request, res: express.Response) {
|
||||
const user = res.locals.oauth.token.User
|
||||
|
||||
await UserNotificationModel.markAllAsRead(user.id)
|
||||
|
||||
return res.status(HttpStatusCode.NO_CONTENT_204).end()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue