Skip to content

Instantly share code, notes, and snippets.

@jcdalton2201
Last active August 29, 2015 14:15
Show Gist options
  • Save jcdalton2201/046cf889cd0af7c8f6f6 to your computer and use it in GitHub Desktop.
Save jcdalton2201/046cf889cd0af7c8f6f6 to your computer and use it in GitHub Desktop.
inventoryDemo
'use strict';
var q = require('q');
var mock = require('./mock/inventoryMock.js');
function findInventory (id) {
var promise = q.defer();
if(id){
var filter = mock.InventoryMock.inventory.filter(
function(item){
return item.guid === id;
});
promise.resolve(filter[0]);
} else {
promise.resolve(mock.InventoryMock.inventory);
}
return promise.promise;
}
var getInventory = function (req, res) {
console.log('getting Inventory');
console.debug('Inventory _id='+req.params.id);
findInventory(req.params.id).then(
function (data){
res.json(data);
},
function (error){
console.log('error getting inventory:' + error);
res.json(500, error);
});
};
var getAllInventory = function(req, res){
console.log('getting all Inventory');
findInventory().then(
function (data){
res.json(data);
},
function (error){
console.info('error getting all Inventory:' + error);
res.json(500, error);
});
};
exports.init = function (server) {
server.get('/inventory/', getAllInventory);
server.get('/inventory/:id', getInventory);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment