orgUser.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 if (this.isUpsert) {
  52. return { $setOnInsert: new Date() };
  53. } else {
  54. this.unset();
  55. }
  56. },
  57. },
  58. modifiedAt: {
  59. type: Date,
  60. denyUpdate: false,
  61. // eslint-disable-next-line consistent-return
  62. autoValue() {
  63. if (this.isInsert || this.isUpsert || this.isUpdate) {
  64. return new Date();
  65. } else {
  66. this.unset();
  67. }
  68. },
  69. },
  70. }),
  71. );
  72. if (Meteor.isServer) {
  73. // Index for Organization User.
  74. Meteor.startup(() => {
  75. OrgUser._collection.createIndex({ orgId: -1 });
  76. OrgUser._collection.createIndex({ orgId: -1, userId: -1 });
  77. });
  78. }
  79. export default OrgUser;