Skip to content

Commit 5516ff0

Browse files
committed
Convert props to native for POST, PUT, PATCH
1 parent 11e383e commit 5516ff0

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/routes.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ routes.show = function(req, res, next) {
5353

5454
// POST /:resource
5555
routes.create = function(req, res, next) {
56+
for (var key in req.body) {
57+
req.body[key] = utils.toNative(req.body[key])
58+
}
59+
5660
var resource = low(req.params.resource)
5761
.insert(req.body)
5862
.value()
@@ -63,6 +67,10 @@ routes.create = function(req, res, next) {
6367
// PUT /:resource/:id
6468
// PATCH /:resource/:id
6569
routes.update = function(req, res, next) {
70+
for (var key in req.body) {
71+
req.body[key] = utils.toNative(req.body[key])
72+
}
73+
6674
var resource = low(req.params.resource)
6775
.update(+req.params.id, req.body)
6876
.value()

test/server.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ describe('Server', function() {
9292
it('should respond with json and create a resource', function(done) {
9393
request(server)
9494
.post('/posts')
95-
.send({body: 'foo'})
95+
.send({body: 'foo', booleanValue: 'true', integerValue: '1'})
9696
.expect('Content-Type', /json/)
97-
.expect({id: 3, body: 'foo'})
97+
.expect({id: 3, body: 'foo', booleanValue: true, integerValue: 1})
9898
.expect(200)
9999
.end(function(err, res){
100100
if (err) return done(err)
@@ -108,13 +108,13 @@ describe('Server', function() {
108108
it('should respond with json and update resource', function(done) {
109109
request(server)
110110
.put('/posts/1')
111-
.send({id: 1, body: 'foo'})
111+
.send({id: 1, body: 'bar', booleanValue: 'true', integerValue: '1'})
112112
.expect('Content-Type', /json/)
113-
.expect({id: 1, body: 'foo'})
113+
.expect({id: 1, body: 'bar', booleanValue: true, integerValue: 1})
114114
.expect(200)
115115
.end(function(err, res){
116116
if (err) return done(err)
117-
assert.deepEqual(low.db.posts[0], {id: 1, body: 'foo'})
117+
assert.deepEqual(low.db.posts[0], {id: 1, body: 'bar', booleanValue: true, integerValue: 1})
118118
done()
119119
})
120120
})

0 commit comments

Comments
 (0)