json-server
Advanced tools
Comparing version 0.8.0 to 0.8.1
# Change Log | ||
## [Unreleased][unreleased] | ||
## [0.8.1][2015-10-06] | ||
### Fixed | ||
* Fix plural resources: PUT should replace resource instead of updating properties. | ||
* Fix singular resources: POST, PUT, PATCH should not convert resource properties. | ||
## [0.8.0][2015-09-21] | ||
### Changed | ||
@@ -6,0 +13,0 @@ |
{ | ||
"name": "json-server", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"description": "Serves JSON files through REST routes.", | ||
@@ -24,3 +24,3 @@ "main": "./src/server/index.js", | ||
"pluralize": "^1.1.2", | ||
"underscore-db": "^0.9.0", | ||
"underscore-db": "^0.9.1", | ||
"update-notifier": "^0.5.0", | ||
@@ -27,0 +27,0 @@ "yargs": "^3.10.0" |
@@ -10,3 +10,3 @@ # JSON Server [![](https://travis-ci.org/typicode/json-server.svg)](https://travis-ci.org/typicode/json-server) [![](https://badge.fury.io/js/json-server.svg)](http://badge.fury.io/js/json-server) [![](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/typicode/json-server?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
_See also [hotel](https://github.com/typicode/hotel), a simple process manager for developers._ | ||
_See also [hotel](https://github.com/typicode/hotel) :hotel:, a process manager for web developers._ | ||
@@ -13,0 +13,0 @@ ## Example |
@@ -218,5 +218,8 @@ var express = require('express') | ||
var resource = db(name) | ||
.updateById(utils.toNative(req.params.id), req.body) | ||
var id = utils.toNative(req.params.id) | ||
var resource = req.method === 'PATCH' ? | ||
db(name).updateById(id, req.body) : | ||
db(name).replaceById(id, req.body) | ||
if (resource) { | ||
@@ -223,0 +226,0 @@ res.locals.data = resource |
var express = require('express') | ||
var utils = require('../utils') | ||
@@ -14,6 +13,2 @@ module.exports = function (db, name) { | ||
function create (req, res, next) { | ||
for (var prop in req.body) { | ||
req.body[prop] = utils.toNative(req.body[prop]) | ||
} | ||
res.locals.data = db.object[name] = req.body | ||
@@ -25,4 +20,9 @@ res.status(201) | ||
function update (req, res, next) { | ||
if (req.method === 'PUT') { | ||
delete db.object[name] | ||
db.object[name] = {} | ||
} | ||
for (var prop in req.body) { | ||
db.object[name][prop] = utils.toNative(req.body[prop]) | ||
db.object[name][prop] = req.body[prop] | ||
} | ||
@@ -29,0 +29,0 @@ |
@@ -411,8 +411,10 @@ var assert = require('assert') | ||
describe('PUT /:resource/:id', function () { | ||
it('should respond with json and update resource', function (done) { | ||
it('should respond with json and replace resource', function (done) { | ||
var post = {id: 1, booleanValue: true, integerValue: 1} | ||
request(server) | ||
.put('/posts/1') | ||
.send({id: 1, body: 'bar', booleanValue: 'true', integerValue: '1'}) | ||
// body property omitted to test that the resource is replaced | ||
.send({id: 1, booleanValue: 'true', integerValue: '1'}) | ||
.expect('Content-Type', /json/) | ||
.expect({id: 1, body: 'bar', booleanValue: true, integerValue: 1}) | ||
.expect(post) | ||
.expect(200) | ||
@@ -422,3 +424,3 @@ .end(function (err, res) { | ||
// assert it was created in database too | ||
assert.deepEqual(db.posts[0], {id: 1, body: 'bar', booleanValue: true, integerValue: 1}) | ||
assert.deepEqual(db.posts[0], post) | ||
done() | ||
@@ -425,0 +427,0 @@ }) |
@@ -47,3 +47,3 @@ var request = require('supertest') | ||
describe('PUT /:resource', function () { | ||
it('should uptade resource', function (done) { | ||
it('should update resource', function (done) { | ||
var user = { name: 'bar' } | ||
@@ -53,3 +53,3 @@ request(server) | ||
.send(user) | ||
.expect(db.user) | ||
.expect(user) | ||
.expect(200, done) | ||
@@ -60,3 +60,3 @@ }) | ||
describe('PATCH /:resource', function () { | ||
it('should uptade resource', function (done) { | ||
it('should update resource', function (done) { | ||
request(server) | ||
@@ -63,0 +63,0 @@ .patch('/user') |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57495
1477
Updatedunderscore-db@^0.9.1