2
0

invitationCodes.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 {
  21. this.unset();
  22. }
  23. },
  24. },
  25. modifiedAt: {
  26. type: Date,
  27. denyUpdate: false,
  28. // eslint-disable-next-line consistent-return
  29. autoValue() {
  30. if (this.isInsert || this.isUpsert || this.isUpdate) {
  31. return new Date();
  32. } else {
  33. this.unset();
  34. }
  35. },
  36. },
  37. // always be the admin if only one admin
  38. authorId: {
  39. type: String,
  40. },
  41. boardsToBeInvited: {
  42. type: [String],
  43. optional: true,
  44. },
  45. valid: {
  46. type: Boolean,
  47. defaultValue: true,
  48. },
  49. }),
  50. );
  51. InvitationCodes.helpers({
  52. author() {
  53. return Users.findOne(this.authorId);
  54. },
  55. });
  56. // InvitationCodes.before.insert((userId, doc) => {
  57. // doc.createdAt = new Date();
  58. // doc.authorId = userId;
  59. // });
  60. if (Meteor.isServer) {
  61. Meteor.startup(() => {
  62. InvitationCodes._collection._ensureIndex({ modifiedAt: -1 });
  63. });
  64. Boards.deny({
  65. fetch: ['members'],
  66. });
  67. }
  68. export default InvitationCodes;