2
1

user-notifications.ts 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import * as express from 'express'
  2. import 'express-validator'
  3. import { body, query } from 'express-validator/check'
  4. import { logger } from '../../helpers/logger'
  5. import { areValidationErrors } from './utils'
  6. import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications'
  7. import { isNotEmptyIntArray } from '../../helpers/custom-validators/misc'
  8. const listUserNotificationsValidator = [
  9. query('unread')
  10. .optional()
  11. .toBoolean()
  12. .isBoolean().withMessage('Should have a valid unread boolean'),
  13. (req: express.Request, res: express.Response, next: express.NextFunction) => {
  14. logger.debug('Checking listUserNotificationsValidator parameters', { parameters: req.query })
  15. if (areValidationErrors(req, res)) return
  16. return next()
  17. }
  18. ]
  19. const updateNotificationSettingsValidator = [
  20. body('newVideoFromSubscription')
  21. .custom(isUserNotificationSettingValid).withMessage('Should have a valid new video from subscription notification setting'),
  22. body('newCommentOnMyVideo')
  23. .custom(isUserNotificationSettingValid).withMessage('Should have a valid new comment on my video notification setting'),
  24. body('videoAbuseAsModerator')
  25. .custom(isUserNotificationSettingValid).withMessage('Should have a valid new video abuse as moderator notification setting'),
  26. body('videoAutoBlacklistAsModerator')
  27. .custom(isUserNotificationSettingValid).withMessage('Should have a valid video auto blacklist notification setting'),
  28. body('blacklistOnMyVideo')
  29. .custom(isUserNotificationSettingValid).withMessage('Should have a valid new blacklist on my video notification setting'),
  30. body('myVideoImportFinished')
  31. .custom(isUserNotificationSettingValid).withMessage('Should have a valid video import finished video notification setting'),
  32. body('myVideoPublished')
  33. .custom(isUserNotificationSettingValid).withMessage('Should have a valid video published notification setting'),
  34. body('commentMention')
  35. .custom(isUserNotificationSettingValid).withMessage('Should have a valid comment mention notification setting'),
  36. body('newFollow')
  37. .custom(isUserNotificationSettingValid).withMessage('Should have a valid new follow notification setting'),
  38. body('newUserRegistration')
  39. .custom(isUserNotificationSettingValid).withMessage('Should have a valid new user registration notification setting'),
  40. body('newInstanceFollower')
  41. .custom(isUserNotificationSettingValid).withMessage('Should have a valid new instance follower notification setting'),
  42. (req: express.Request, res: express.Response, next: express.NextFunction) => {
  43. logger.debug('Checking updateNotificationSettingsValidator parameters', { parameters: req.body })
  44. if (areValidationErrors(req, res)) return
  45. return next()
  46. }
  47. ]
  48. const markAsReadUserNotificationsValidator = [
  49. body('ids')
  50. .optional()
  51. .custom(isNotEmptyIntArray).withMessage('Should have a valid notification ids to mark as read'),
  52. (req: express.Request, res: express.Response, next: express.NextFunction) => {
  53. logger.debug('Checking markAsReadUserNotificationsValidator parameters', { parameters: req.body })
  54. if (areValidationErrors(req, res)) return
  55. return next()
  56. }
  57. ]
  58. // ---------------------------------------------------------------------------
  59. export {
  60. listUserNotificationsValidator,
  61. updateNotificationSettingsValidator,
  62. markAsReadUserNotificationsValidator
  63. }