cms/app-client/app/mirage/config.js
changeset 134 c06d08c8a1b8
parent 127 5cd8c3065c38
child 158 366509ae2f37
--- a/cms/app-client/app/mirage/config.js	Thu Feb 25 21:26:15 2016 +0100
+++ b/cms/app-client/app/mirage/config.js	Sun Feb 28 09:30:23 2016 +0100
@@ -51,6 +51,29 @@
 
   });
 
+  this.get('/bnf/:ids', function(db, request) {
+
+    var bnfIds = decodeURIComponent(request.params.ids);
+    var resMap = _.reduce(bnfIds.split(','), function(res, id) {
+        var fullId = id;
+        if(_.startsWith(fullId, constants.BNF_BASE_URL)) {
+          fullId = fullId.slice(constants.BNF_BASE_URL.length);
+        } else if (_.startsWith(fullId, constants.BNF_ARK_BASE_URL)) {
+          fullId = fullId.slice(constants.BNF_ARK_BASE_URL.length);
+        } else if (!_.startsWith(fullId, constants.BNF_ARK_BASE_ID)) {
+          fullId = constants.BNF_ARK_BASE_ID + fullId;
+        }
+        var bnfRes = db.lexvo.find(fullId);
+        res[fullId] = bnfRes?bnfRes.label:null;
+        return res;
+    }, {});
+
+    return {
+      'bnfids': resMap
+    };
+
+  });
+
   /*
     Route shorthand cheatsheet
   */