2
0

usersessiondata.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. SessionData = new Mongo.Collection('sessiondata');
  2. /**
  3. * A UserSessionData in Wekan. Organization in Trello.
  4. */
  5. SessionData.attachSchema(
  6. new SimpleSchema({
  7. _id: {
  8. /**
  9. * the organization id
  10. */
  11. type: Number,
  12. optional: true,
  13. // eslint-disable-next-line consistent-return
  14. autoValue() {
  15. if (this.isInsert && !this.isSet) {
  16. return incrementCounter('counters', 'orgId', 1);
  17. }
  18. },
  19. },
  20. userId: {
  21. /**
  22. * userId of the user
  23. */
  24. type: String,
  25. optional: false,
  26. },
  27. sessionId: {
  28. /**
  29. * unique session ID
  30. */
  31. type: String,
  32. optional: false,
  33. },
  34. totalHits: {
  35. /**
  36. * total number of hits in the last report query
  37. */
  38. type: Number,
  39. optional: true,
  40. },
  41. lastHit: {
  42. /**
  43. * the last hit returned from a report query
  44. */
  45. type: Number,
  46. optional: true,
  47. },
  48. cards: {
  49. type: [String],
  50. optional: true,
  51. },
  52. errorMessages: {
  53. type: [String],
  54. optional: true,
  55. },
  56. errors: {
  57. type: [Object],
  58. optional: true,
  59. defaultValue: [],
  60. },
  61. 'errors.$': {
  62. type: new SimpleSchema({
  63. tag: {
  64. /**
  65. * i18n tag
  66. */
  67. type: String,
  68. optional: false,
  69. },
  70. value: {
  71. /**
  72. * value for the tag
  73. */
  74. type: String,
  75. optional: true,
  76. defaultValue: null,
  77. },
  78. color: {
  79. type: Boolean,
  80. optional: true,
  81. defaultValue: false,
  82. },
  83. }),
  84. },
  85. createdAt: {
  86. /**
  87. * creation date of the team
  88. */
  89. type: Date,
  90. // eslint-disable-next-line consistent-return
  91. autoValue() {
  92. if (this.isInsert) {
  93. return new Date();
  94. } else if (this.isUpsert) {
  95. return { $setOnInsert: new Date() };
  96. } else {
  97. this.unset();
  98. }
  99. },
  100. },
  101. modifiedAt: {
  102. type: Date,
  103. denyUpdate: false,
  104. // eslint-disable-next-line consistent-return
  105. autoValue() {
  106. if (this.isInsert || this.isUpsert || this.isUpdate) {
  107. return new Date();
  108. } else {
  109. this.unset();
  110. }
  111. },
  112. },
  113. }),
  114. );
  115. if (!Meteor.isServer) {
  116. SessionData.getSessionId = () => {
  117. let sessionId = Session.get('sessionId');
  118. if (!sessionId) {
  119. sessionId = `${String(Meteor.userId())}-${String(Math.random())}`;
  120. Session.set('sessionId', sessionId);
  121. }
  122. return sessionId;
  123. };
  124. }
  125. export default SessionData;