invitationCodes.js 1.5 KB

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