activity.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { HasObjectId } from './has-object-id';
  2. import { IUser } from './user';
  3. // Model
  4. const MODEL_PAGE = 'Page';
  5. const MODEL_COMMENT = 'Comment';
  6. // Action
  7. const ACTION_UNSETTLED = 'UNSETTLED';
  8. const ACTION_REGISTRATION_SUCCESS = 'REGISTRATION_SUCCESS';
  9. const ACTION_LOGIN_SUCCESS = 'LOGIN_SUCCESS';
  10. const ACTION_LOGIN_FAILURE = 'LOGIN_FAILURE';
  11. const ACTION_LOGOUT = 'LOGOUT';
  12. const ACTION_PAGE_VIEW = 'PAGE_VIEW';
  13. const ACTION_PAGE_LIKE = 'PAGE_LIKE';
  14. const ACTION_PAGE_UNLIKE = 'PAGE_UNLIKE';
  15. const ACTION_PAGE_BOOKMARK = 'PAGE_BOOKMARK';
  16. const ACTION_PAGE_UNBOOKMARK = 'PAGE_UNBOOKMARK';
  17. const ACTION_PAGE_CREATE = 'PAGE_CREATE';
  18. const ACTION_PAGE_UPDATE = 'PAGE_UPDATE';
  19. const ACTION_PAGE_RENAME = 'PAGE_RENAME';
  20. const ACTION_PAGE_DUPLICATE = 'PAGE_DUPLICATE';
  21. const ACTION_PAGE_DELETE = 'PAGE_DELETE';
  22. const ACTION_PAGE_DELETE_COMPLETELY = 'PAGE_DELETE_COMPLETELY';
  23. const ACTION_PAGE_REVERT = 'PAGE_REVERT';
  24. const ACTION_COMMENT_CREATE = 'COMMENT_CREATE';
  25. const ACTION_COMMENT_UPDATE = 'COMMENT_UPDATE';
  26. const ACTION_COMMENT_REMOVE = 'COMMENT_REMOVE';
  27. export const SUPPORTED_TARGET_MODEL_TYPE = {
  28. MODEL_PAGE,
  29. } as const;
  30. export const SUPPORTED_EVENT_MODEL_TYPE = {
  31. MODEL_COMMENT,
  32. } as const;
  33. export const SUPPORTED_ACTION_TYPE = {
  34. ACTION_UNSETTLED,
  35. ACTION_REGISTRATION_SUCCESS,
  36. ACTION_LOGIN_SUCCESS,
  37. ACTION_LOGIN_FAILURE,
  38. ACTION_LOGOUT,
  39. ACTION_PAGE_VIEW,
  40. ACTION_PAGE_LIKE,
  41. ACTION_PAGE_UNLIKE,
  42. ACTION_PAGE_BOOKMARK,
  43. ACTION_PAGE_UNBOOKMARK,
  44. ACTION_PAGE_CREATE,
  45. ACTION_PAGE_UPDATE,
  46. ACTION_PAGE_RENAME,
  47. ACTION_PAGE_DUPLICATE,
  48. ACTION_PAGE_DELETE,
  49. ACTION_PAGE_DELETE_COMPLETELY,
  50. ACTION_PAGE_REVERT,
  51. ACTION_COMMENT_CREATE,
  52. ACTION_COMMENT_UPDATE,
  53. ACTION_COMMENT_REMOVE,
  54. } as const;
  55. export const SUPPORTED_ACTION_TO_NOTIFIED_TYPE = {
  56. ACTION_PAGE_LIKE,
  57. ACTION_PAGE_BOOKMARK,
  58. ACTION_PAGE_UPDATE,
  59. ACTION_PAGE_RENAME,
  60. ACTION_PAGE_DUPLICATE,
  61. ACTION_PAGE_DELETE,
  62. ACTION_PAGE_DELETE_COMPLETELY,
  63. ACTION_PAGE_REVERT,
  64. ACTION_COMMENT_CREATE,
  65. } as const;
  66. export const AllSupportedTargetModelType = Object.values(SUPPORTED_TARGET_MODEL_TYPE);
  67. export const AllSupportedEventModelType = Object.values(SUPPORTED_EVENT_MODEL_TYPE);
  68. export const AllSupportedActionType = Object.values(SUPPORTED_ACTION_TYPE);
  69. export const AllSupportedActionToNotifiedType = Object.values(SUPPORTED_ACTION_TO_NOTIFIED_TYPE);
  70. /*
  71. * For AuditLogManagement.tsx
  72. */
  73. export const PageActions = Object.values({
  74. ACTION_PAGE_LIKE,
  75. ACTION_PAGE_BOOKMARK,
  76. ACTION_PAGE_CREATE,
  77. ACTION_PAGE_UPDATE,
  78. ACTION_PAGE_RENAME,
  79. ACTION_PAGE_DUPLICATE,
  80. ACTION_PAGE_DELETE,
  81. ACTION_PAGE_DELETE_COMPLETELY,
  82. ACTION_PAGE_REVERT,
  83. } as const);
  84. export const CommentActions = Object.values({
  85. ACTION_COMMENT_CREATE,
  86. ACTION_COMMENT_UPDATE,
  87. } as const);
  88. export type SupportedTargetModelType = typeof SUPPORTED_TARGET_MODEL_TYPE[keyof typeof SUPPORTED_TARGET_MODEL_TYPE];
  89. export type SupportedEventModelType = typeof SUPPORTED_EVENT_MODEL_TYPE[keyof typeof SUPPORTED_EVENT_MODEL_TYPE];
  90. export type SupportedActionType = typeof SUPPORTED_ACTION_TYPE[keyof typeof SUPPORTED_ACTION_TYPE];
  91. export type ISnapshot = Partial<Pick<IUser, 'username'>>
  92. export type IActivity = {
  93. user?: string
  94. ip?: string
  95. endpoint?: string
  96. targetModel?: SupportedTargetModelType
  97. target?: string
  98. eventModel?: SupportedEventModelType
  99. event?: string
  100. action: SupportedActionType
  101. createdAt: Date
  102. snapshot?: ISnapshot
  103. }
  104. export type IActivityHasId = IActivity & HasObjectId;