org.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. Org = new Mongo.Collection('org');
  2. /**
  3. * A Organization in wekan
  4. */
  5. Org.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. version: {
  21. /**
  22. * the version of the organization
  23. */
  24. type: Number,
  25. optional: true,
  26. },
  27. name: {
  28. /**
  29. * name of the organization
  30. */
  31. type: String,
  32. optional: true,
  33. max: 190,
  34. },
  35. address1: {
  36. /**
  37. * address1 of the organization
  38. */
  39. type: String,
  40. optional: true,
  41. max: 255,
  42. },
  43. address2: {
  44. /**
  45. * address2 of the organization
  46. */
  47. type: String,
  48. optional: true,
  49. max: 255,
  50. },
  51. city: {
  52. /**
  53. * city of the organization
  54. */
  55. type: String,
  56. optional: true,
  57. max: 255,
  58. },
  59. state: {
  60. /**
  61. * state of the organization
  62. */
  63. type: String,
  64. optional: true,
  65. max: 255,
  66. },
  67. zipCode: {
  68. /**
  69. * zipCode of the organization
  70. */
  71. type: String,
  72. optional: true,
  73. max: 50,
  74. },
  75. country: {
  76. /**
  77. * country of the organization
  78. */
  79. type: String,
  80. optional: true,
  81. max: 255,
  82. },
  83. billingEmail: {
  84. /**
  85. * billingEmail of the organization
  86. */
  87. type: String,
  88. optional: true,
  89. max: 255,
  90. },
  91. createdAt: {
  92. /**
  93. * creation date of the organization
  94. */
  95. type: Date,
  96. // eslint-disable-next-line consistent-return
  97. autoValue() {
  98. if (this.isInsert) {
  99. return new Date();
  100. } else if (this.isUpsert) {
  101. return { $setOnInsert: new Date() };
  102. } else {
  103. this.unset();
  104. }
  105. },
  106. },
  107. modifiedAt: {
  108. type: Date,
  109. denyUpdate: false,
  110. // eslint-disable-next-line consistent-return
  111. autoValue() {
  112. if (this.isInsert || this.isUpsert || this.isUpdate) {
  113. return new Date();
  114. } else {
  115. this.unset();
  116. }
  117. },
  118. },
  119. }),
  120. );
  121. if (Meteor.isServer) {
  122. // Index for Organization name.
  123. Meteor.startup(() => {
  124. Org._collection._ensureIndex({ name: -1 });
  125. });
  126. }
  127. export default Org;