cardCommentReactions.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. const commentReactionSchema = new SimpleSchema({
  2. reactionCodepoint: { type: String, optional: false },
  3. userIds: { type: [String], defaultValue: [] }
  4. });
  5. CardCommentReactions = new Mongo.Collection('card_comment_reactions');
  6. /**
  7. * All reactions of a card comment
  8. */
  9. CardCommentReactions.attachSchema(
  10. new SimpleSchema({
  11. boardId: {
  12. /**
  13. * the board ID
  14. */
  15. type: String,
  16. optional: false
  17. },
  18. cardId: {
  19. /**
  20. * the card ID
  21. */
  22. type: String,
  23. optional: false
  24. },
  25. cardCommentId: {
  26. /**
  27. * the card comment ID
  28. */
  29. type: String,
  30. optional: false
  31. },
  32. reactions: {
  33. type: [commentReactionSchema],
  34. defaultValue: []
  35. }
  36. }),
  37. );
  38. CardCommentReactions.allow({
  39. insert(userId, doc) {
  40. return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
  41. },
  42. update(userId, doc) {
  43. return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
  44. },
  45. remove(userId, doc) {
  46. return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
  47. },
  48. fetch: ['boardId'],
  49. });
  50. if (Meteor.isServer) {
  51. Meteor.startup(() => {
  52. CardCommentReactions._collection.createIndex({ cardCommentId: 1 }, { unique: true });
  53. });
  54. }