positionHistory.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. import { Meteor } from 'meteor/meteor';
  2. import { check } from 'meteor/check';
  3. import PositionHistory from '/models/positionHistory';
  4. import Swimlanes from '/models/swimlanes';
  5. import Lists from '/models/lists';
  6. import Cards from '/models/cards';
  7. /**
  8. * Server-side methods for position history tracking
  9. */
  10. Meteor.methods({
  11. /**
  12. * Track original position for a swimlane
  13. */
  14. 'positionHistory.trackSwimlane'(swimlaneId) {
  15. check(swimlaneId, String);
  16. const swimlane = Swimlanes.findOne(swimlaneId);
  17. if (!swimlane) {
  18. throw new Meteor.Error('swimlane-not-found', 'Swimlane not found');
  19. }
  20. return swimlane.trackOriginalPosition();
  21. },
  22. /**
  23. * Track original position for a list
  24. */
  25. 'positionHistory.trackList'(listId) {
  26. check(listId, String);
  27. const list = Lists.findOne(listId);
  28. if (!list) {
  29. throw new Meteor.Error('list-not-found', 'List not found');
  30. }
  31. return list.trackOriginalPosition();
  32. },
  33. /**
  34. * Track original position for a card
  35. */
  36. 'positionHistory.trackCard'(cardId) {
  37. check(cardId, String);
  38. const card = Cards.findOne(cardId);
  39. if (!card) {
  40. throw new Meteor.Error('card-not-found', 'Card not found');
  41. }
  42. return card.trackOriginalPosition();
  43. },
  44. /**
  45. * Get original position for a swimlane
  46. */
  47. 'positionHistory.getSwimlaneOriginalPosition'(swimlaneId) {
  48. check(swimlaneId, String);
  49. const swimlane = Swimlanes.findOne(swimlaneId);
  50. if (!swimlane) {
  51. throw new Meteor.Error('swimlane-not-found', 'Swimlane not found');
  52. }
  53. return swimlane.getOriginalPosition();
  54. },
  55. /**
  56. * Get original position for a list
  57. */
  58. 'positionHistory.getListOriginalPosition'(listId) {
  59. check(listId, String);
  60. const list = Lists.findOne(listId);
  61. if (!list) {
  62. throw new Meteor.Error('list-not-found', 'List not found');
  63. }
  64. return list.getOriginalPosition();
  65. },
  66. /**
  67. * Get original position for a card
  68. */
  69. 'positionHistory.getCardOriginalPosition'(cardId) {
  70. check(cardId, String);
  71. const card = Cards.findOne(cardId);
  72. if (!card) {
  73. throw new Meteor.Error('card-not-found', 'Card not found');
  74. }
  75. return card.getOriginalPosition();
  76. },
  77. /**
  78. * Check if a swimlane has moved from its original position
  79. */
  80. 'positionHistory.hasSwimlaneMoved'(swimlaneId) {
  81. check(swimlaneId, String);
  82. const swimlane = Swimlanes.findOne(swimlaneId);
  83. if (!swimlane) {
  84. throw new Meteor.Error('swimlane-not-found', 'Swimlane not found');
  85. }
  86. return swimlane.hasMovedFromOriginalPosition();
  87. },
  88. /**
  89. * Check if a list has moved from its original position
  90. */
  91. 'positionHistory.hasListMoved'(listId) {
  92. check(listId, String);
  93. const list = Lists.findOne(listId);
  94. if (!list) {
  95. throw new Meteor.Error('list-not-found', 'List not found');
  96. }
  97. return list.hasMovedFromOriginalPosition();
  98. },
  99. /**
  100. * Check if a card has moved from its original position
  101. */
  102. 'positionHistory.hasCardMoved'(cardId) {
  103. check(cardId, String);
  104. const card = Cards.findOne(cardId);
  105. if (!card) {
  106. throw new Meteor.Error('card-not-found', 'Card not found');
  107. }
  108. return card.hasMovedFromOriginalPosition();
  109. },
  110. /**
  111. * Get original position description for a swimlane
  112. */
  113. 'positionHistory.getSwimlaneDescription'(swimlaneId) {
  114. check(swimlaneId, String);
  115. const swimlane = Swimlanes.findOne(swimlaneId);
  116. if (!swimlane) {
  117. throw new Meteor.Error('swimlane-not-found', 'Swimlane not found');
  118. }
  119. return swimlane.getOriginalPositionDescription();
  120. },
  121. /**
  122. * Get original position description for a list
  123. */
  124. 'positionHistory.getListDescription'(listId) {
  125. check(listId, String);
  126. const list = Lists.findOne(listId);
  127. if (!list) {
  128. throw new Meteor.Error('list-not-found', 'List not found');
  129. }
  130. return list.getOriginalPositionDescription();
  131. },
  132. /**
  133. * Get original position description for a card
  134. */
  135. 'positionHistory.getCardDescription'(cardId) {
  136. check(cardId, String);
  137. const card = Cards.findOne(cardId);
  138. if (!card) {
  139. throw new Meteor.Error('card-not-found', 'Card not found');
  140. }
  141. return card.getOriginalPositionDescription();
  142. },
  143. /**
  144. * Get all position history for a board
  145. */
  146. 'positionHistory.getBoardHistory'(boardId) {
  147. check(boardId, String);
  148. return PositionHistory.find({
  149. boardId: boardId,
  150. }, {
  151. sort: { createdAt: -1 }
  152. }).fetch();
  153. },
  154. /**
  155. * Get position history by entity type for a board
  156. */
  157. 'positionHistory.getBoardHistoryByType'(boardId, entityType) {
  158. check(boardId, String);
  159. check(entityType, String);
  160. if (!['swimlane', 'list', 'card'].includes(entityType)) {
  161. throw new Meteor.Error('invalid-entity-type', 'Entity type must be swimlane, list, or card');
  162. }
  163. return PositionHistory.find({
  164. boardId: boardId,
  165. entityType: entityType,
  166. }, {
  167. sort: { createdAt: -1 }
  168. }).fetch();
  169. },
  170. });