Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var request = {
- correlationId: '888',
- commands: [{
- command: 'makeComment',
- contextId: '123',
- text: 'foible',
- commentId: '456'
- }]
- }
- function makeCommentHandler(events, command) {
- if (events.filter( e => e.commentId === command.commentId) > 0) {
- throw new Error('hey you already assigned this id to a comment (rare)')
- }
- events.push({
- event: 'commentMade',
- text: command.text,
- commentId: command.commentId,
- contextId: command.contextId
- })
- return events
- }
- function samReadModelUpdater(event) {
- if (event.event === 'commentMade') {
- var context = getContext(event.contextId)
- context.comments[event.commentId] = { text: event.text, commentId: event.commentId, timestamp: 'iso' }
- save(context)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement