Last active
January 17, 2018 20:01
-
-
Save marcusstenbeck/1b425cd33f682ac9e93a9102ddfd590d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const max50 = str => str.length <= 50; | |
module.exports = function addShow( | |
eventStore, | |
{ | |
title, | |
time, | |
host, | |
location | |
} | |
) { | |
if (!title || !max50(title)) { | |
throw new Error(`title can't be longer than 50 characters`); | |
} | |
if (!(time instanceof Date)) { | |
throw new Error(`time must be a date object`); | |
} | |
if (!host || !max50(host)) { | |
throw new Error(`host can't be longer than 50 characters`); | |
} | |
if (!location || !max50(location)) { | |
throw new Error(`location can't be longer than 50 characters`); | |
} | |
eventStore.commit({ | |
type: 'ShowAdded', | |
payload: { | |
title, | |
time, | |
host, | |
location | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment