orgUser.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. OrgUser = new Mongo.Collection('orgUser');
  2. /**
  3. * A Organization User in wekan
  4. */
  5. OrgUser.attachSchema(
  6. new SimpleSchema({
  7. id: {
  8. /**
  9. * the organization user's 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', 'orgUserId', 1);
  17. }
  18. },
  19. },
  20. orgId: {
  21. /**
  22. * the organization id
  23. */
  24. type: Number,
  25. optional: true,
  26. },
  27. userId: {
  28. /**
  29. * the user id
  30. */
  31. type: Number,
  32. optional: true,
  33. },
  34. role: {
  35. /**
  36. * the role of user
  37. */
  38. type: String,
  39. optional: true,
  40. max: 20,
  41. },
  42. createdAt: {
  43. /**
  44. * creation date of the organization user
  45. */
  46. type: Date,
  47. // eslint-disable-next-line consistent-return
  48. autoValue() {
  49. if (this.isInsert) {
  50. return new Date();
  51. } else {
  52. this.unset();
  53. }
  54. },
  55. },
  56. modifiedAt: {
  57. type: Date,
  58. denyUpdate: false,
  59. // eslint-disable-next-line consistent-return
  60. autoValue() {
  61. if (this.isInsert || this.isUpsert || this.isUpdate) {
  62. return new Date();
  63. } else {
  64. this.unset();
  65. }
  66. },
  67. },
  68. }),
  69. );
  70. if (Meteor.isServer) {
  71. // Index for Organization User.
  72. Meteor.startup(() => {
  73. OrgUser._collection._ensureIndex({ orgId: -1 });
  74. OrgUser._collection._ensureIndex({ orgId: -1, userId: -1 });
  75. });
  76. }
  77. export default OrgUser;