Last active
August 29, 2015 14:15
-
-
Save jcdalton2201/046cf889cd0af7c8f6f6 to your computer and use it in GitHub Desktop.
inventoryDemo
This file contains hidden or 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
| '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