diff --git a/config/environment.js b/config/environment.js index 05b7b4d..847fa80 100644 --- a/config/environment.js +++ b/config/environment.js @@ -41,30 +41,26 @@ module.exports = function(environment) { }, }; + var apiURL; + if (environment === 'development') { - ENV['simple-auth']['crossOriginWhitelist'] = ['http://127.0.0.1:4200']; - ENV['simple-auth-token']['serverTokenEndpoint'] = '/api/authenticate'; - ENV.apiURL = 'http://127.0.0.1:4200'; - ENV.contentSecurityPolicy['connect-src'] = "'self' http://127.0.0.1:4200"; + apiURL = 'http://127.0.0.1:8901'; } if (environment === 'test') { - ENV['simple-auth']['crossOriginWhitelist'] = ['https://bactdb-test.herokuapp.com']; - ENV['simple-auth-token']['serverTokenEndpoint'] = 'https://bactdb-test.herokuapp.com/api/authenticate'; - ENV.apiURL = 'https://bactdb-test.herokuapp.com'; - ENV.contentSecurityPolicy['connect-src'] = "'self' https://bactdb-test.herokuapp.com"; - - // keep test console output quieter + apiURL = 'https://bactdb-test.herokuapp.com'; ENV.APP.LOG_ACTIVE_GENERATION = false; ENV.APP.LOG_VIEW_LOOKUPS = false; } if (environment === 'production') { - ENV['simple-auth']['crossOriginWhitelist'] = ['https://bactdb.herokuapp.com']; - ENV['simple-auth-token']['serverTokenEndpoint'] = 'https://bactdb.herokuapp.com/api/authenticate'; - ENV.apiURL = 'https://bactdb.herokuapp.com'; - ENV.contentSecurityPolicy['connect-src'] = "'self' https://bactdb.herokuapp.com"; + apiURL = 'https://bactdb.herokuapp.com'; } + ENV['simple-auth']['crossOriginWhitelist'] = [apiURL]; + ENV['simple-auth-token']['serverTokenEndpoint'] = apiURL + '/api/authenticate'; + ENV.apiURL = apiURL; + ENV.contentSecurityPolicy['connect-src'] = "'self' " + apiURL; + return ENV; }; diff --git a/package.json b/package.json index 4b024f0..466029d 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,6 @@ "author": "", "license": "MIT", "devDependencies": { - "body-parser": "^1.12.2", "broccoli-asset-rev": "^2.0.2", "ember-cli": "0.2.7", "ember-cli-app-version": "0.3.3", @@ -40,9 +39,6 @@ "ember-export-application-global": "^1.0.2", "ember-select-2": "1.3.0", "ember-table": "0.5.0", - "express": "^4.12.4", - "glob": "^4.5.3", - "jsonwebtoken": "^5.0.0", - "morgan": "^1.6.0" + "glob": "^4.5.3" } } diff --git a/server/.jshintrc b/server/.jshintrc deleted file mode 100644 index c1f2978..0000000 --- a/server/.jshintrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "node": true -} diff --git a/server/index.js b/server/index.js deleted file mode 100644 index 4bdb85a..0000000 --- a/server/index.js +++ /dev/null @@ -1,42 +0,0 @@ -// To use it create some files under `mocks/` -// e.g. `server/mocks/ember-hamsters.js` -// -// module.exports = function(app) { -// app.get('/ember-hamsters', function(req, res) { -// res.send('hello'); -// }); -// }; - -// http://stackoverflow.com/q/11001817 -var allowCrossDomain = function(req, res, next) { - res.header('Access-Control-Allow-Origin', '*'); - res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS'); - res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With'); - - // intercept OPTIONS method - if ('OPTIONS' == req.method) { - res.sendStatus(200); - } - else { - next(); - } -}; - -module.exports = function(app) { - var globSync = require('glob').sync; - var mocks = globSync('./mocks/**/*.js', { cwd: __dirname }).map(require); - var proxies = globSync('./proxies/**/*.js', { cwd: __dirname }).map(require); - - // Log proxy requests - var morgan = require('morgan'); - app.use(morgan('dev')); - app.use(allowCrossDomain); - - // Parse json - var bodyParser = require('body-parser'); - app.use(bodyParser.json()); - - mocks.forEach(function(route) { route(app); }); - proxies.forEach(function(route) { route(app); }); - -}; diff --git a/server/mocks/authenticate.js b/server/mocks/authenticate.js deleted file mode 100644 index 4ec4913..0000000 --- a/server/mocks/authenticate.js +++ /dev/null @@ -1,66 +0,0 @@ -module.exports = function(app) { - var express = require('express'); - var jwt = require('jsonwebtoken'); - var authenticateRouter = express.Router(); - - var USERS = [ - { - id: 1, - email: 'testA', - name: 'Test Admin User', - role: 'A', - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - deletedAt: null - }, - { - id: 2, - email: 'testR', - name: 'Test Read User', - role: 'R', - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - deletedAt: null - }, - { - id: 3, - email: 'testW', - name: 'Test Write User', - role: 'W', - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - deletedAt: null - } - ] - - authenticateRouter.post('/', function(req, res) { - // wait for a bit to simulate cold boot of heroku api - var ms = 1000 + new Date().getTime(); - while (new Date() < ms){} - - if ((req.body.email === 'testA' || req.body.email === 'testR' || req.body.email === 'testW' ) - && req.body.password === 'test') { - var user = USERS.filter(function(u) { - if (u.email == req.body.email) { - return u; - } - })[0]; - var token = jwt.sign({ - 'name': user.name, - 'role': user.role - }, 'secret', - { - expiresInMinutes: 60, - issuer: 'bactdb', - subject: user.id, - }); - res.send({ - 'token': token - }); - } else { - res.status(401).send({'error':'Invalid username or password'}); - } - }); - - app.use('/api/authenticate', authenticateRouter); -}; diff --git a/server/mocks/characteristic-types.js b/server/mocks/characteristic-types.js deleted file mode 100644 index 9eb84bc..0000000 --- a/server/mocks/characteristic-types.js +++ /dev/null @@ -1,84 +0,0 @@ -module.exports = function(app) { - var express = require('express'); - var characteristicTypesRouter = express.Router(); - - var CHARACTERISTIC_TYPES = [ - { - id: 1, - characteristicTypeName: 'Type 1', - characteristics: [1,4], - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - deletedAt: null, - createdBy: 1, - updatedBy: 1, - deletedBy: null, - sortOrder: 1, - }, - { - id: 2, - characteristicTypeName: 'Type 2', - characteristics: [2,5], - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - deletedAt: null, - createdBy: 1, - updatedBy: 1, - deletedBy: null, - sortOrder: 2, - }, - { - id: 3, - characteristicTypeName: 'Type 3', - characteristics: [3], - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - deletedAt: null, - createdBy: 1, - updatedBy: 1, - deletedBy: null, - sortOrder: 3, - }, - ] - - characteristicTypesRouter.get('/', function(req, res) { - var characteristics; - if (req.query.ids) { - characteristic_types = CHARACTERISTIC_TYPES.filter(function(c) { - return req.query.ids.indexOf(c.id.toString()) > -1; - }); - } else { - characteristic_types = CHARACTERISTIC_TYPES; - } - res.send({ - 'characteristicTypes': characteristic_types - }); - }); - - characteristicTypesRouter.post('/', function(req, res) { - res.status(201).end(); - }); - - characteristicTypesRouter.get('/:id', function(req, res) { - var characteristic_type = CHARACTERISTIC_TYPES.filter(function(c) { - return c.id == req.params.id; - }); - res.send({ - 'characteristicType': characteristic_type - }); - }); - - characteristicTypesRouter.put('/:id', function(req, res) { - res.send({ - 'characteristicTypes': { - id: req.params.id - } - }); - }); - - characteristicTypesRouter.delete('/:id', function(req, res) { - res.status(204).end(); - }); - - app.use('/api/hymenobacter/characteristicTypes', characteristicTypesRouter); -}; diff --git a/server/mocks/characteristics.js b/server/mocks/characteristics.js deleted file mode 100644 index 09c4d44..0000000 --- a/server/mocks/characteristics.js +++ /dev/null @@ -1,118 +0,0 @@ -module.exports = function(app) { - var express = require('express'); - var characteristicsRouter = express.Router(); - - var CHARACTERISTICS = [ - { - id: 1, - characteristicName: 'α-fucosidase (API ZYM)', - characteristicType: 1, - strains: [1,2], - measurements: [1,6], - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - deletedAt: null, - createdBy: 1, - updatedBy: 1, - deletedBy: null, - sortOrder: 1, - }, - { - id: 2, - characteristicName: 'α-glucosidase', - characteristicType: 2, - strains: [1,2], - measurements: [2,7], - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - deletedAt: null, - createdBy: 1, - updatedBy: 1, - deletedBy: null, - sortOrder: 2, - }, - { - id: 3, - characteristicName: 'Chloramphenicol', - characteristicType: 3, - strains: [1,2], - measurements: [3,8], - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - deletedAt: null, - createdBy: 1, - updatedBy: 1, - deletedBy: null, - sortOrder: 3, - }, - { - id: 4, - characteristicName: 'Bacitracin', - characteristicType: 1, - strains: [1,2], - measurements: [4,9], - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - deletedAt: null, - createdBy: 1, - updatedBy: 1, - deletedBy: null, - sortOrder: 4, - }, - { - id: 5, - characteristicName: 'Indole', - characteristicType: 2, - strains: [1,2], - measurements: [5,10], - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - deletedAt: null, - createdBy: 1, - updatedBy: 1, - deletedBy: null, - sortOrder: 5, - } - ] - - characteristicsRouter.get('/', function(req, res) { - var characteristics; - if (req.query.ids) { - characteristics = CHARACTERISTICS.filter(function(c) { - return req.query.ids.indexOf(c.id.toString()) > -1; - }); - } else { - characteristics = CHARACTERISTICS; - } - res.send({ - 'characteristics': characteristics - }); - }); - - characteristicsRouter.post('/', function(req, res) { - res.status(201).end(); - }); - - characteristicsRouter.get('/:id', function(req, res) { - var characteristic = CHARACTERISTICS.filter(function(c) { - return c.id == req.params.id; - }); - res.send({ - 'characteristic': characteristic - }); - }); - - characteristicsRouter.put('/:id', function(req, res) { - res.send({ - 'characteristics': { - id: req.params.id - } - }); - }); - - characteristicsRouter.delete('/:id', function(req, res) { - res.status(204).end(); - }); - - app.use('/api/hymenobacter/characteristics', characteristicsRouter); -}; diff --git a/server/mocks/measurements.js b/server/mocks/measurements.js deleted file mode 100644 index e4e7fdc..0000000 --- a/server/mocks/measurements.js +++ /dev/null @@ -1,209 +0,0 @@ -module.exports = function(app) { - var express = require('express'); - var measurementsRouter = express.Router(); - - var MEASUREMENTS = [ - { - id: 1, - strain: 1, - characteristic: 1, - textMeasurementType: 'Meas. Type 1', - txtValue: null, - numValue: null, - confidenceInterval: null, - unitType: null, - notes: null, - testMethod: null, - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - createdBy: 1, - updatedBy: 1 - }, - { - id: 2, - strain: 1, - characteristic: 2, - textMeasurementType: 'Meas. Type 1', - txtValue: null, - numValue: null, - confidenceInterval: null, - unitType: null, - notes: null, - testMethod: null, - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - createdBy: 1, - updatedBy: 1 - }, - { - id: 3, - strain: 1, - characteristic: 3, - textMeasurementType: null, - txtValue: "text value", - numValue: null, - confidenceInterval: null, - unitType: null, - notes: "some notes", - testMethod: null, - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - createdBy: 1, - updatedBy: 1 - }, - { - id: 4, - strain: 1, - characteristic: 4, - textMeasurementType: null, - txtValue: null, - numValue: 123.4, - confidenceInterval: null, - unitType: 'Unit 1', - notes: null, - testMethod: null, - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - createdBy: 1, - updatedBy: 1 - }, - { - id: 5, - strain: 1, - characteristic: 5, - textMeasurementType: null, - txtValue: null, - numValue: 567.8, - confidenceInterval: 0.2, - unitType: 'Unit 1', - notes: null, - testMethod: null, - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - createdBy: 1, - updatedBy: 1 - }, - { - id: 6, - strain: 2, - characteristic: 1, - textMeasurementType: 'Meas. Type 1', - txtValue: null, - numValue: null, - confidenceInterval: null, - unitType: null, - notes: null, - testMethod: null, - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - createdBy: 1, - updatedBy: 1 - }, - { - id: 7, - strain: 2, - characteristic: 2, - textMeasurementType: 'Meas. Type 1', - txtValue: null, - numValue: null, - confidenceInterval: null, - unitType: null, - notes: null, - testMethod: null, - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - createdBy: 1, - updatedBy: 1 - }, - { - id: 8, - strain: 2, - characteristic: 3, - textMeasurementType: null, - txtValue: "text value", - numValue: null, - confidenceInterval: null, - unitType: null, - notes: "some notes", - testMethod: null, - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - createdBy: 1, - updatedBy: 1 - }, - { - id: 9, - strain: 2, - characteristic: 4, - textMeasurementType: null, - txtValue: null, - numValue: 123.4, - confidenceInterval: null, - unitType: 'Unit 1', - notes: null, - testMethod: null, - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - createdBy: 1, - updatedBy: 1 - }, - { - id: 10, - strain: 2, - characteristic: 5, - textMeasurementType: null, - txtValue: null, - numValue: 567.8, - confidenceInterval: 0.2, - unitType: 'Unit 1', - notes: null, - testMethod: null, - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - createdBy: 1, - updatedBy: 1 - } - ] - - measurementsRouter.get('/', function(req, res) { - var measurements; - if (req.query.ids) { - measurements = MEASUREMENTS.filter(function(m) { - return req.query.ids.indexOf(m.id.toString()) > -1; - }); - } else { - measurements = MEASUREMENTS; - } - res.send({ - 'measurements': measurements - }); - }); - - measurementsRouter.post('/', function(req, res) { - res.status(201).end(); - }); - - measurementsRouter.get('/:id', function(req, res) { - var measurements = MEASUREMENTS.filter(function(m) { - return m.id == req.params.id; - }); - res.send({ - 'measurement': measurements - }); - }); - - measurementsRouter.put('/:id', function(req, res) { - var measurements = MEASUREMENTS.filter(function(m) { - return m.id == req.params.id; - }); - res.send({ - 'measurement': measurements[0] - }); - }); - - measurementsRouter.delete('/:id', function(req, res) { - res.status(204).end(); - }); - - app.use('/api/hymenobacter/measurements', measurementsRouter); -}; diff --git a/server/mocks/species.js b/server/mocks/species.js deleted file mode 100644 index c7b66a4..0000000 --- a/server/mocks/species.js +++ /dev/null @@ -1,109 +0,0 @@ -module.exports = function(app) { - var express = require('express'); - var speciesRouter = express.Router(); - - var SPECIES = [ - { - id: 1, - genusName: "Hymenobacter", - speciesName: "One", - typeSpecies: true, - etymology: "Test Etymology", - strains: [1,2], - totalStrains: 1, - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - deletedAt: null, - createdBy: 1, - updatedBy: 1, - deletedBy: null, - sortOrder: 1, - }, - { - id: 2, - genusName: "Hymenobacter", - speciesName: "Two", - typeSpecies: true, - etymology: "Test Etymology", - strains: [3], - totalStrains: 1, - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - deletedAt: null, - createdBy: 1, - updatedBy: 1, - deletedBy: null, - sortOrder: 2, - }, - { - id: 3, - genusName: "Hymenobacter", - speciesName: "Three", - typeSpecies: true, - etymology: "Test Etymology", - strains: [4], - totalStrains: 1, - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - deletedAt: null, - createdBy: 1, - updatedBy: 1, - deletedBy: null, - sortOrder: 3, - }, - { - id: 4, - genusName: "Hymenobacter", - speciesName: "Four", - typeSpecies: true, - etymology: "Test Etymology", - strains: [4], - totalStrains: 1, - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - deletedAt: null, - createdBy: 1, - updatedBy: 1, - deletedBy: null, - sortOrder: 4, - } - ]; - - speciesRouter.get('/', function(req, res) { - var species; - if (req.query.ids) { - species = SPECIES.filter(function(s) { - return req.query.ids.indexOf(s.id.toString()) > -1; - }); - } else { - species = SPECIES; - } - res.send({ - 'species': species - }); - }); - - speciesRouter.post('/', function(req, res) { - req.body.species.id = Math.max.apply(Math, SPECIES.map(function(o){return o.id;})) + 1; - res.status(201).send(req.body); - }); - - speciesRouter.get('/:id', function(req, res) { - var species = SPECIES.filter(function(s) { - return s.id == req.params.id; - }); - res.send({ - 'species': species[0] - }); - }); - - speciesRouter.put('/:id', function(req, res) { - res.send(req.body); - }); - - speciesRouter.delete('/:id', function(req, res) { - res.status(204).end(); - }); - - app.use('/api/hymenobacter/species', speciesRouter); -}; diff --git a/server/mocks/strains.js b/server/mocks/strains.js deleted file mode 100644 index d98fc96..0000000 --- a/server/mocks/strains.js +++ /dev/null @@ -1,138 +0,0 @@ -module.exports = function(app) { - var express = require('express'); - var strainsRouter = express.Router(); - - var STRAINS = [ - { - id: 1, - species: 1, - strainName: "ABC", - typeStrain: true, - accessionNumbers: "Test Accession", - genbank: "Test Genbank", - wholeGenomeSequence: "Seq123", - isolatedFrom: "Location 1", - measurements: [1,2,3,4,5], - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - deletedAt: null, - createdBy: 1, - updatedBy: 1, - deletedBy: null, - totalMeasurements: 5, - notes: "Test notes", - sortOrder: 1, - }, - { - id: 2, - species: 1, - strainName: "XYZ", - typeStrain: false, - accessionNumbers: "Test Accession", - genbank: "Test Genbank", - wholeGenomeSequence: null, - isolatedFrom: "Location 2", - measurements: [6,7,8,9,10], - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - deletedAt: null, - createdBy: 3, - updatedBy: 3, - deletedBy: null, - totalMeasurements: 5, - notes: "Test notes", - sortOrder: 2, - }, - { - id: 3, - species: 2, - strainName: "QRS", - typeStrain: true, - accessionNumbers: "Test Accession", - genbank: "Test Genbank", - wholeGenomeSequence: "Seq123", - isolatedFrom: "Location 1", - measurements: [], - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - deletedAt: null, - createdBy: 1, - updatedBy: 1, - deletedBy: null, - totalMeasurements: 0, - notes: "Test notes", - sortOrder: 3, - }, - { - id: 4, - species: 3, - strainName: "LMN", - typeStrain: true, - accessionNumbers: "Test Accession", - genbank: "Test Genbank", - wholeGenomeSequence: "Seq123", - isolatedFrom: "Location 2", - measurements: [], - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - deletedAt: null, - createdBy: 3, - updatedBy: 3, - deletedBy: null, - totalMeasurements: 0, - notes: "Test notes", - sortOrder: 4. - } - ]; - - strainsRouter.get('/', function(req, res) { - var strains; - if (req.query.ids) { - strains = STRAINS.filter(function(s) { - return req.query.ids.indexOf(s.id.toString()) > -1; - }); - } else { - strains = STRAINS; - } - res.send({ - 'strains': strains - }); - }); - - strainsRouter.post('/', function(req, res) { - req.body.strain.id = Math.max.apply(Math, STRAINS.map(function(o){return o.id;})) + 1; - res.status(201).send(req.body); - }); - - strainsRouter.get('/:id', function(req, res) { - var strains = STRAINS.filter(function(s) { - return s.id == req.params.id; - }); - res.send({ - 'strain': strains[0] - }); - }); - - strainsRouter.put('/:id', function(req, res) { - var strains = STRAINS.filter(function(s) { - return s.id == req.params.id; - }); - if (strains.length === 0) { - res.status(422).send({ - 'errors':{ - "strainName": ["error1"], - "typeStrain": ["error2", "error3"], - "isolatedFrom": ["error4"] - } - }).end(); - } else { - res.status(204).end(); - } - }); - - strainsRouter.delete('/:id', function(req, res) { - res.status(204).end(); - }); - - app.use('/api/hymenobacter/strains', strainsRouter); -}; diff --git a/server/mocks/users.js b/server/mocks/users.js deleted file mode 100644 index 1e3183c..0000000 --- a/server/mocks/users.js +++ /dev/null @@ -1,84 +0,0 @@ -module.exports = function(app) { - var express = require('express'); - var usersRouter = express.Router(); - - var USERS = [ - { - id: 1, - email: 'testA', - name: 'Test Admin User', - role: 'A', - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - deletedAt: null - }, - { - id: 2, - email: 'testR', - name: 'Test Read User', - role: 'R', - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - deletedAt: null - }, - { - id: 3, - email: 'testW', - name: 'Test Write User', - role: 'W', - createdAt: "0001-01-01T00:00:00Z", - updatedAt: "0001-01-01T00:00:00Z", - deletedAt: null - } - ] - - usersRouter.get('/', function(req, res) { - var users; - if (req.query.ids) { - users = USERS.filter(function(u) { - return req.query.ids.indexOf(u.id.toString()) > -1; - }); - } else { - users = USERS; - } - res.send({ - 'users': users - }); - }); - - usersRouter.post('/', function(req, res) { - req.body.user.id = Math.max.apply(Math, USERS.map(function(o){return o.id;})) + 1; - res.status(201).send(req.body); - // // NOTE - use the following for testing errors - // res.status(422).send({ - // 'errors':{ - // "name": ["Must provide a value"], - // "email": ["Must provide a value"], - // "password": ["Must provide a value"], - // } - // }).end(); - }); - - usersRouter.get('/:id', function(req, res) { - var user = USERS.filter(function(u) { - return u.id == req.params.id; - }); - res.send({ - 'user': user - }); - }); - - usersRouter.put('/:id', function(req, res) { - res.send({ - 'users': { - id: req.params.id - } - }); - }); - - usersRouter.delete('/:id', function(req, res) { - res.status(204).end(); - }); - - app.use('/api/users', usersRouter); -};