Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. var request = {
  2. correlationId: '888',
  3. commands: [{
  4. command: 'makeComment',
  5. contextId: '123',
  6. text: 'foible',
  7. commentId: '456'
  8. }]
  9. }
  10.  
  11. function makeCommentHandler(events, command) {
  12. if (events.filter( e => e.commentId === command.commentId) > 0) {
  13. throw new Error('hey you already assigned this id to a comment (rare)')
  14. }
  15.  
  16. events.push({
  17. event: 'commentMade',
  18. text: command.text,
  19. commentId: command.commentId,
  20. contextId: command.contextId
  21. })
  22. return events
  23. }
  24.  
  25. function samReadModelUpdater(event) {
  26. if (event.event === 'commentMade') {
  27. var context = getContext(event.contextId)
  28. context.comments[event.commentId] = { text: event.text, commentId: event.commentId, timestamp: 'iso' }
  29. save(context)
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement