cardCommentReactions.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. const commentReactionSchema = new SimpleSchema({
  2. reactionCodepoint: {
  3. type: String,
  4. optional: false,
  5. max: 9, // max length of reaction code
  6. custom() {
  7. if (!this.value.match(/^&#\d{4,6};$/)) { // regex for only valid reactions
  8. return "incorrectReactionCode";
  9. }
  10. },
  11. },
  12. userIds: { type: [String], defaultValue: [] }
  13. });
  14. CardCommentReactions = new Mongo.Collection('card_comment_reactions');
  15. /**
  16. * All reactions of a card comment
  17. */
  18. CardCommentReactions.attachSchema(
  19. new SimpleSchema({
  20. boardId: {
  21. /**
  22. * the board ID
  23. */
  24. type: String,
  25. optional: false
  26. },
  27. cardId: {
  28. /**
  29. * the card ID
  30. */
  31. type: String,
  32. optional: false
  33. },
  34. cardCommentId: {
  35. /**
  36. * the card comment ID
  37. */
  38. type: String,
  39. optional: false
  40. },
  41. reactions: {
  42. type: [commentReactionSchema],
  43. defaultValue: []
  44. }
  45. }),
  46. );
  47. CardCommentReactions.allow({
  48. insert(userId, doc) {
  49. return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
  50. },
  51. update(userId, doc) {
  52. return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
  53. },
  54. remove(userId, doc) {
  55. return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
  56. },
  57. fetch: ['boardId'],
  58. });
  59. if (Meteor.isServer) {
  60. Meteor.startup(() => {
  61. CardCommentReactions._collection.createIndex({ cardCommentId: 1 }, { unique: true });
  62. });
  63. }