Create send response middleware
This commit is contained in:
@@ -28,7 +28,8 @@ NamedMapsAdminController.prototype.register = function (app) {
|
||||
credentialsMiddleware(),
|
||||
checkContentType('POST', 'POST TEMPLATE'),
|
||||
authorizedByAPIKey(this.authApi, 'create', 'POST TEMPLATE'),
|
||||
createTemplate(this.templateMaps)
|
||||
createTemplate(this.templateMaps),
|
||||
sendResponse()
|
||||
);
|
||||
|
||||
app.put(
|
||||
@@ -39,7 +40,8 @@ NamedMapsAdminController.prototype.register = function (app) {
|
||||
credentialsMiddleware(),
|
||||
checkContentType('PUT', 'PUT TEMPLATE'),
|
||||
authorizedByAPIKey(this.authApi, 'update', 'PUT TEMPLATE'),
|
||||
updateTemplate(this.templateMaps)
|
||||
updateTemplate(this.templateMaps),
|
||||
sendResponse()
|
||||
);
|
||||
|
||||
app.get(
|
||||
@@ -49,7 +51,8 @@ NamedMapsAdminController.prototype.register = function (app) {
|
||||
localsMiddleware(),
|
||||
credentialsMiddleware(),
|
||||
authorizedByAPIKey(this.authApi, 'get', 'GET TEMPLATE'),
|
||||
retrieveTemplate(this.templateMaps)
|
||||
retrieveTemplate(this.templateMaps),
|
||||
sendResponse()
|
||||
);
|
||||
|
||||
app.delete(
|
||||
@@ -59,7 +62,8 @@ NamedMapsAdminController.prototype.register = function (app) {
|
||||
localsMiddleware(),
|
||||
credentialsMiddleware(),
|
||||
authorizedByAPIKey(this.authApi, 'delete', 'DELETE TEMPLATE'),
|
||||
destroyTemplate(this.templateMaps)
|
||||
destroyTemplate(this.templateMaps),
|
||||
sendResponse()
|
||||
);
|
||||
|
||||
app.get(
|
||||
@@ -69,7 +73,8 @@ NamedMapsAdminController.prototype.register = function (app) {
|
||||
localsMiddleware(),
|
||||
credentialsMiddleware(),
|
||||
authorizedByAPIKey(this.authApi, 'list', 'GET TEMPLATE LIST'),
|
||||
listTemplates(this.templateMaps)
|
||||
listTemplates(this.templateMaps),
|
||||
sendResponse()
|
||||
);
|
||||
|
||||
app.options(
|
||||
@@ -85,6 +90,7 @@ function checkContentType (action, label) {
|
||||
error.label = label;
|
||||
return next(error);
|
||||
}
|
||||
|
||||
next();
|
||||
};
|
||||
}
|
||||
@@ -120,10 +126,9 @@ function createTemplate (templateMaps) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.status(200);
|
||||
res.body = { template_id: templateId };
|
||||
|
||||
const method = req.query.callback ? 'jsonp' : 'json';
|
||||
res[method]({ template_id: templateId });
|
||||
next();
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -139,10 +144,9 @@ function updateTemplate (templateMaps) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.status(200);
|
||||
res.body = { template_id: templateId };
|
||||
|
||||
const method = req.query.callback ? 'jsonp' : 'json';
|
||||
res[method]({ template_id: templateId });
|
||||
next();
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -168,10 +172,9 @@ function retrieveTemplate (templateMaps) {
|
||||
// so we remove it before returning to the user
|
||||
delete template.auth_id;
|
||||
|
||||
res.status(200);
|
||||
res.body = { template };
|
||||
|
||||
const method = req.query.callback ? 'jsonp' : 'json';
|
||||
res[method]({ template });
|
||||
next();
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -188,10 +191,10 @@ function destroyTemplate (templateMaps) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.status(204);
|
||||
res.statusCode = 204;
|
||||
res.body = '';
|
||||
|
||||
const method = req.query.callback ? 'jsonp' : 'json';
|
||||
res[method]('');
|
||||
next();
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -207,10 +210,18 @@ function listTemplates (templateMaps) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.status(200);
|
||||
res.body = { template_ids: templateIds };
|
||||
|
||||
const method = req.query.callback ? 'jsonp' : 'json';
|
||||
res[method]({ template_ids: templateIds });
|
||||
next();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function sendResponse () {
|
||||
return function sendResponseMiddleware (req, res) {
|
||||
res.status(res.statusCode || 200);
|
||||
|
||||
const method = req.query.callback ? 'jsonp' : 'json';
|
||||
res[method](res.body);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user