invitationCodes.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { ReactiveCache } from '/imports/reactiveCache';
  2. InvitationCodes = new Mongo.Collection('invitation_codes');
  3. InvitationCodes.attachSchema(
  4. new SimpleSchema({
  5. code: {
  6. type: String,
  7. },
  8. email: {
  9. type: String,
  10. unique: true,
  11. regEx: SimpleSchema.RegEx.Email,
  12. },
  13. createdAt: {
  14. type: Date,
  15. denyUpdate: false,
  16. optional: true,
  17. // eslint-disable-next-line consistent-return
  18. autoValue() {
  19. if (this.isInsert) {
  20. return new Date();
  21. } else if (this.isUpsert) {
  22. return { $setOnInsert: new Date() };
  23. } else {
  24. this.unset();
  25. }
  26. },
  27. },
  28. modifiedAt: {
  29. type: Date,
  30. denyUpdate: false,
  31. // eslint-disable-next-line consistent-return
  32. autoValue() {
  33. if (this.isInsert || this.isUpsert || this.isUpdate) {
  34. return new Date();
  35. } else {
  36. this.unset();
  37. }
  38. },
  39. },
  40. // always be the admin if only one admin
  41. authorId: {
  42. type: String,
  43. },
  44. boardsToBeInvited: {
  45. type: [String],
  46. optional: true,
  47. },
  48. valid: {
  49. type: Boolean,
  50. defaultValue: true,
  51. },
  52. }),
  53. );
  54. InvitationCodes.helpers({
  55. author() {
  56. return ReactiveCache.getUser(this.authorId);
  57. },
  58. });
  59. // InvitationCodes.before.insert((userId, doc) => {
  60. // doc.createdAt = new Date();
  61. // doc.authorId = userId;
  62. // });
  63. if (Meteor.isServer) {
  64. Meteor.startup(() => {
  65. InvitationCodes._collection.createIndex({ modifiedAt: -1 });
  66. });
  67. Boards.deny({
  68. fetch: ['members'],
  69. });
  70. }
  71. export default InvitationCodes;