rest-query
Advanced tools
Comparing version
@@ -270,6 +270,13 @@ /* | ||
case 'post' : | ||
self.root.post( message.path , message.data , { performer: performer } , function( error , rawDocument ) { | ||
self.root.post( message.path , message.data , { performer: performer } , function( error , rawDocument , details ) { | ||
if ( error ) { return self.httpErrorHandler( httpResponse , error ) ; } | ||
httpResponse.writeHeader( 201 ) ; | ||
var status = details.status || 200 ; | ||
if ( status === 201 && rawDocument.id ) | ||
{ | ||
httpResponse.setHeader( 'Location' , httpRequest.url + '/' + details.id ) ; | ||
} | ||
httpResponse.writeHeader( status ) ; | ||
httpResponse.end( JSON.stringify( rawDocument ) ) ; | ||
@@ -436,3 +443,3 @@ | ||
callback( undefined , batch.export() ) ; | ||
callback( undefined , batch.export() , {} ) ; | ||
} ) ; | ||
@@ -499,3 +506,4 @@ | ||
if ( error ) { callback( error ) ; return ; } | ||
callback( undefined , { id: id } ) ; | ||
callback( undefined , { id: id } , { status: 201 } ) ; | ||
} ) ; | ||
@@ -517,33 +525,3 @@ | ||
if ( error ) | ||
{ | ||
if ( error.type === 'notFound' && path.length === 1 ) | ||
{ | ||
// This is a normal case: the target does not exist yet, | ||
// and should be created by the request | ||
rawDocument.parent = {} ; | ||
if ( context.parentNode && context.parentNode.id !== '/' ) | ||
{ | ||
parentCollectionName = context.parentNode.collectionNode.collection.name ; | ||
rawDocument.parent[ parentCollectionName ] = context.parentNode.id ; | ||
} | ||
document = self.collection.createDocument( rawDocument , { id: parsedPathNode.identifier } ) ; | ||
// /!\ That should be changed when 'auth' will be enforced | ||
document.save( { overwrite: true } , function( error ) { | ||
if ( error ) { callback( error ) ; return ; } | ||
callback() ; | ||
} ) ; | ||
} | ||
else | ||
{ | ||
// Here this is really an error | ||
callback( error ) ; | ||
} | ||
return ; | ||
} | ||
if ( error ) { callback( error ) ; } | ||
@@ -615,3 +593,3 @@ // The resource exists, overwrite or access should be done by the underlying ObjectNode | ||
if ( error ) { callback( error ) ; return ; } | ||
callback() ; | ||
callback( undefined , {} , { status: 201 } ) ; | ||
} ) ; | ||
@@ -792,3 +770,3 @@ } | ||
// Return that object! | ||
callback( undefined , this.object.export() ) ; | ||
callback( undefined , this.object.export() , {} ) ; | ||
return ; | ||
@@ -909,3 +887,3 @@ } | ||
if ( error ) { callback( error ) ; return ; } | ||
callback() ; | ||
callback( undefined , {} , {} ) ; | ||
} ) ; | ||
@@ -975,3 +953,3 @@ | ||
if ( error ) { callback( error ) ; return ; } | ||
callback() ; | ||
callback( undefined , {} , {} ) ; | ||
} ) ; | ||
@@ -1034,3 +1012,3 @@ | ||
if ( error ) { callback( error ) ; return ; } | ||
callback() ; | ||
callback( undefined , {} , {} ) ; | ||
} ) ; | ||
@@ -1037,0 +1015,0 @@ |
{ | ||
"name": "rest-query", | ||
"version": "0.0.20", | ||
"version": "0.0.21", | ||
"description": "Perform REST queries directly on your database!", | ||
@@ -5,0 +5,0 @@ "main": "lib/restQuery.js", |
@@ -53,2 +53,3 @@ /* | ||
var config = require( './app-config.js' ) ; | ||
@@ -58,55 +59,10 @@ | ||
// Collections... | ||
var blogs , posts , comments ; | ||
var blogsDescriptor = { | ||
url: 'mongodb://localhost:27017/restQuery/blogs' , | ||
properties: { | ||
//title: { constraint: 'string' } , // already defined by restQuery | ||
description: { constraint: 'string' }, | ||
embedded: { constraint: 'object' } // just for the test | ||
} , | ||
meta: { | ||
} , | ||
indexes: [ | ||
] , | ||
hooks: { | ||
} , | ||
useMemProxy: false | ||
} ; | ||
var postsDescriptor = { | ||
url: 'mongodb://localhost:27017/restQuery/posts' , | ||
properties: { | ||
//title: { constraint: 'string' } , // already defined by restQuery | ||
content: { constraint: 'string' } | ||
} , | ||
meta: { | ||
} , | ||
indexes: [ | ||
] , | ||
hooks: { | ||
} , | ||
useMemProxy: false | ||
} ; | ||
var commentsDescriptor = { | ||
url: 'mongodb://localhost:27017/restQuery/comments' , | ||
properties: { | ||
content: { constraint: 'string' } | ||
} , | ||
meta: { | ||
} , | ||
indexes: [ | ||
] , | ||
hooks: { | ||
} , | ||
useMemProxy: false | ||
} ; | ||
/* Utils */ | ||
@@ -161,5 +117,5 @@ | ||
var blogsNode = app.createCollectionNode( 'blogs' , blogsDescriptor ) ; | ||
var postsNode = app.createCollectionNode( 'posts' , postsDescriptor ) ; | ||
var commentsNode = app.createCollectionNode( 'comments' , commentsDescriptor ) ; | ||
var blogsNode = app.createCollectionNode( 'blogs' , config.descriptors.blogs ) ; | ||
var postsNode = app.createCollectionNode( 'posts' , config.descriptors.posts ) ; | ||
var commentsNode = app.createCollectionNode( 'comments' , config.descriptors.comments ) ; | ||
@@ -192,9 +148,9 @@ app.root.contains( blogsNode ) ; | ||
blogs = world.createCollection( 'blogs' , blogsDescriptor ) ; | ||
blogs = world.createCollection( 'blogs' , config.descriptors.blogs ) ; | ||
expect( blogs ).to.be.a( odm.Collection ) ; | ||
posts = world.createCollection( 'posts' , postsDescriptor ) ; | ||
posts = world.createCollection( 'posts' , config.descriptors.posts ) ; | ||
expect( posts ).to.be.a( odm.Collection ) ; | ||
comments = world.createCollection( 'comments' , commentsDescriptor ) ; | ||
comments = world.createCollection( 'comments' , config.descriptors.comments ) ; | ||
expect( comments ).to.be.a( odm.Collection ) ; | ||
@@ -201,0 +157,0 @@ |
Sorry, the diff of this file is not supported yet
119191
0.74%22
4.76%2572
0.19%