mirror of https://gitee.com/bigwinds/arangodb
action cleanup
This commit is contained in:
parent
a8d4b74e4f
commit
809344f526
|
@ -41,7 +41,7 @@ actions.defineHttp({
|
||||||
lon : "number"
|
lon : "number"
|
||||||
},
|
},
|
||||||
|
|
||||||
function : function (req, res) {
|
callback : function (req, res) {
|
||||||
var result = req.collection.near(req.lat, req.lon).distance();
|
var result = req.collection.near(req.lat, req.lon).distance();
|
||||||
|
|
||||||
actions.queryResult(req, res, result);
|
actions.queryResult(req, res, result);
|
||||||
|
@ -63,7 +63,7 @@ actions.defineHttp({
|
||||||
radius : "number"
|
radius : "number"
|
||||||
},
|
},
|
||||||
|
|
||||||
function : function (req, res) {
|
callback : function (req, res) {
|
||||||
var result = req.collection.within(req.lat, req.lon, req.radius).distance();
|
var result = req.collection.within(req.lat, req.lon, req.radius).distance();
|
||||||
|
|
||||||
actions.queryResult(req, res, result);
|
actions.queryResult(req, res, result);
|
||||||
|
|
|
@ -112,13 +112,51 @@ function defineHttp (options) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
internal.defineAction(url, "CLIENT", callback, parameter);
|
internal.defineAction(url, "CLIENT", callback, parameter);
|
||||||
console.debug("defining action '" + url + "' in domain(s) " + domain);
|
console.trace("defining action '" + url + "' in domain(s) " + domain);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.error("action '" + url + "' encountered error: " + err);
|
console.error("action '" + url + "' encountered error: " + err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief returns a result
|
||||||
|
///
|
||||||
|
/// @FUN{actionResult(@FA{req}, @FA{res}, @FA{code}, @FA{result}, @FA{headers})}
|
||||||
|
///
|
||||||
|
/// The functions returns a result object. @FA{code} is the status code
|
||||||
|
/// to return.
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
function actionResult (req, res, code, result, headers) {
|
||||||
|
res.responseCode = code;
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
res.contentType = "application/json";
|
||||||
|
res.body = JSON.stringify(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (headers != undefined) {
|
||||||
|
res.headers = headers;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief returns an error
|
||||||
|
///
|
||||||
|
/// @FUN{actionError(@FA{req}, @FA{res}, @FA{errorMessage})}
|
||||||
|
///
|
||||||
|
/// The functions returns an error message. The status code is 500 and the
|
||||||
|
/// returned object is an array with an attribute @LIT{error} containing
|
||||||
|
/// the error message @FA{errorMessage}.
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
function actionError (req, res, err) {
|
||||||
|
res.responseCode = 500;
|
||||||
|
res.contentType = "application/json";
|
||||||
|
res.body = JSON.stringify({ 'error' : "" + err });
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief returns a result of a query as documents
|
/// @brief returns a result of a query as documents
|
||||||
///
|
///
|
||||||
|
@ -227,42 +265,6 @@ function queryReferences (req, res, query) {
|
||||||
res.body = JSON.stringify(result);
|
res.body = JSON.stringify(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief returns a result
|
|
||||||
///
|
|
||||||
/// @FUN{actionResult(@FA{req}, @FA{res}, @FA{code}, @FA{result})}
|
|
||||||
///
|
|
||||||
/// The functions returns a result object. @FA{code} is the status code
|
|
||||||
/// to return.
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
function actionResult (req, res, code, result) {
|
|
||||||
if (code == 204) {
|
|
||||||
res.responseCode = code;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
res.responseCode = code;
|
|
||||||
res.contentType = "application/json";
|
|
||||||
res.body = JSON.stringify(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief returns an error
|
|
||||||
///
|
|
||||||
/// @FUN{actionError(@FA{req}, @FA{res}, @FA{errorMessage})}
|
|
||||||
///
|
|
||||||
/// The functions returns an error message. The status code is 500 and the
|
|
||||||
/// returned object is an array with an attribute @LIT{error} containing
|
|
||||||
/// the error message @FA{errorMessage}.
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
function actionError (req, res, err) {
|
|
||||||
res.responseCode = 500;
|
|
||||||
res.contentType = "application/json";
|
|
||||||
res.body = JSON.stringify({ 'error' : "" + err });
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @}
|
/// @}
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Reference in New Issue