Skip to content

Instantly share code, notes, and snippets.

@marcusstenbeck
Last active January 17, 2018 20:01
Show Gist options
  • Save marcusstenbeck/1b425cd33f682ac9e93a9102ddfd590d to your computer and use it in GitHub Desktop.
Save marcusstenbeck/1b425cd33f682ac9e93a9102ddfd590d to your computer and use it in GitHub Desktop.
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