Permalink
Browse files

Fix _id bug, restore project.js, and use hapi 0.9 new payload format …

…func
  • Loading branch information...
1 parent 2087899 commit d4ede42063ac62f512954edab1a26006ffdc72bc @hueniverse committed Nov 17, 2012
Showing with 19 additions and 27 deletions.
  1. +18 −26 api/index.js
  2. +1 −1 clients/view/js/project.js
View
@@ -23,38 +23,30 @@ var internals = {};
// Post handler extension middleware
-internals.onPostHandler = function (request, next) {
+internals.formatPayload = function (payload) {
- if (request.response &&
- request.response.result &&
- !(request.response.result instanceof Error)) {
+ if (typeof payload !== 'object' ||
+ payload instanceof Array) {
- var result = request.response.result;
-
- // Sanitize database fields
-
- if (result._id) {
-
- result.id = result._id;
- delete result._id;
- }
-
- if (result instanceof Object) {
-
- for (var i in result) {
+ return payload;
+ }
- if (result.hasOwnProperty(i)) {
+ // Sanitize database fields
- if (i[0] === '_') {
+ if (payload._id) {
+ payload.id = payload._id;
+ delete payload._id;
+ }
- delete result[i];
- }
- }
+ for (var i in payload) {
+ if (payload.hasOwnProperty(i)) {
+ if (i[0] === '_') {
+ delete payload[i];
}
}
}
- next();
+ return payload;
};
@@ -69,10 +61,10 @@ var configuration = {
name: 'http',
- // Extension points
+ // Formatter
- ext: {
- onPostHandler: internals.onPostHandler
+ format: {
+ payload: internals.formatPayload
},
// Authentication
@@ -78,7 +78,7 @@ YUI.add('postmile-project', function (Y) {
// once we've rendered project, dump the initial cache, get tips, sugs, etc
Y.postmile.initialTasks = Y.postmile.initialProjectId = null;
- } /*else*/ {
+ } else {
// do not refretch/rerender details we aleady have
renderProjectTasks(project);

0 comments on commit d4ede42

Please sign in to comment.