Created
May 28, 2016 08:36
-
-
Save kwasniew/d91a8264c587e59fdb4748eb9ca98732 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
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