Skip to content

Instantly share code, notes, and snippets.

@kwasniew
Created May 28, 2016 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwasniew/d91a8264c587e59fdb4748eb9ca98732 to your computer and use it in GitHub Desktop.
Save kwasniew/d91a8264c587e59fdb4748eb9ca98732 to your computer and use it in GitHub Desktop.
module.exports = function() {
var items = [];
return {
_items: function(state) {
items = state;
},
stockUp: function (isbn, count) {
var updated = false;
items.forEach(function(item) {
if(item.isbn === isbn) {
item.count = count;
updated = true;
}
});
if(!updated) {
items.push({"isbn": isbn, "count": count});
}
return Promise.resolve();
},
findAll: function () {
return Promise.resolve(items);
},
getCount: function (isbn) {
var foundItemCount = null;
items.forEach(function(item) {
if(item.isbn === isbn) {
foundItemCount = item.count;
}
});
return Promise.resolve(foundItemCount);
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment