From dfd5099eee79e320df2f293fa6aa12ea27975e86 Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Sat, 3 Mar 2012 08:04:33 +0100 Subject: [PATCH] action cleanup --- js/actions/geo.js | 8 ++++++++ js/modules/actions.js | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/js/actions/geo.js b/js/actions/geo.js index a6294b9276..cd7adbe00f 100644 --- a/js/actions/geo.js +++ b/js/actions/geo.js @@ -41,11 +41,15 @@ actions.defineHttp({ lon : "number" }, +<<<<<<< HEAD <<<<<<< HEAD callback : function (req, res) { ======= function : function (req, res) { >>>>>>> unfinished actions cleanup +======= + callback : function (req, res) { +>>>>>>> action cleanup var result = req.collection.near(req.lat, req.lon).distance(); actions.queryResult(req, res, result); @@ -67,11 +71,15 @@ actions.defineHttp({ radius : "number" }, +<<<<<<< HEAD <<<<<<< HEAD callback : function (req, res) { ======= function : function (req, res) { >>>>>>> unfinished actions cleanup +======= + callback : function (req, res) { +>>>>>>> action cleanup var result = req.collection.within(req.lat, req.lon, req.radius).distance(); actions.queryResult(req, res, result); diff --git a/js/modules/actions.js b/js/modules/actions.js index 26e7de6906..d5cef6e974 100644 --- a/js/modules/actions.js +++ b/js/modules/actions.js @@ -343,13 +343,51 @@ function actionError (req, res, err) { try { 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) { 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 /// @@ -460,6 +498,7 @@ function queryReferences (req, res, query) { } //////////////////////////////////////////////////////////////////////////////// +<<<<<<< HEAD /// @brief returns a result /// <<<<<<< HEAD @@ -561,6 +600,8 @@ function actionError (req, res, err) { } //////////////////////////////////////////////////////////////////////////////// +======= +>>>>>>> action cleanup /// @} ////////////////////////////////////////////////////////////////////////////////