summaryrefslogtreecommitdiff
path: root/app/node_modules/okadminview/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/node_modules/okadminview/index.js')
-rw-r--r--app/node_modules/okadminview/index.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/app/node_modules/okadminview/index.js b/app/node_modules/okadminview/index.js
index 884c4b8..897c583 100644
--- a/app/node_modules/okadminview/index.js
+++ b/app/node_modules/okadminview/index.js
@@ -173,6 +173,40 @@ function OKAdminView(options) {
}
});
+ router.put('/:type/__batch/', function putBatch(req, res, next) {
+ var type = req.params.type;
+ var body = req.body || {};
+ var resourcesJSON = body[type];
+ var resource = resourceCache.get(type);
+ if (!resourcesJSON || !resourcesJSON.length) {
+ res.status(400);
+ errorHandler(req, res)(new Error('Bad request'));
+ } else if (!resource) {
+ res.status(404);
+ errorHandler(req, res)(new Error('No such resource'));
+ } else {
+ try {
+ var ids = [];
+ var resourcesParsed = resourcesJSON.map(function(resourceJSON) {
+ var data = JSON.parse(resourceJSON);
+ ids.push(resource.getID(data));
+ return data;
+ });
+ } catch (e) {
+ errorHandler(req, res)(new Error('Resource batch contains invalid JSON'));
+ return;
+ }
+ Q.all([
+ meta.get(),
+ resource.updateBatch(ids, resourcesParsed),
+ ]).then(function(results) {
+ var metadata = results.shift();
+ req.flash('success', {action: 'batch_update'});
+ res.redirect(303, '../..');
+ }).fail(errorHandler(req, res));
+ }
+ });
+
router.put('/:type/:id/', function updateResource(req, res, next) {
var type = req.params.type;
var id = req.params.id;