From 2a4ede6507f55e492736c4b82a139ac5d2e2eec0 Mon Sep 17 00:00:00 2001 From: Sean Fridman Date: Wed, 8 Apr 2015 15:04:48 -0400 Subject: Update OKAdminView template data fetch for custom IDs --- app/node_modules/okutil/index.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'app/node_modules/okutil/index.js') diff --git a/app/node_modules/okutil/index.js b/app/node_modules/okutil/index.js index 738c6a4..01041b6 100644 --- a/app/node_modules/okutil/index.js +++ b/app/node_modules/okutil/index.js @@ -24,17 +24,27 @@ module.exports = { }))) .then(function(results) { var metadata = results.shift(); - var normalized = results.reduce(function(data, result, i) { + var normalized = results.reduce(function(cache, result, i) { + var resource = queries[i].resource; var type = queries[i].type; + var plural = pluralize(type); if (isarray(result)) { - data[pluralize(type)] = result; + result = result.map(function(data) { + // Inform template of ID in generic way + data.id = data[resource.idField]; + return data; + }); } else { - data[type] = result; + // Inform template of ID in generic way + result.id = result[resource.idField]; + result = [result] } - return data; + cache[plural] = cache[plural] || []; + cache[plural] = cache[plural].concat(result); + return cache; }, {meta: metadata}); resolve(normalized); - }, reject); + }).fail(reject); }); }, -- cgit v1.2.3-70-g09d2