cardCommentReactions.js 1.5 KB

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