From 98b4940f7018ff2937dcac3d58b0011d3f5ed984 Mon Sep 17 00:00:00 2001 From: Fabien O'Carroll Date: Mon, 4 Mar 2019 17:53:58 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Allowed=20data=20in=20collection?= =?UTF-8?q?s=20to=20use=20specified=20key=20(#10559)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #10434 This adds the list of objects to the specified key, finishing off the work started in the PR here: https://github.com/TryGhost/Ghost/pull/10449 --- core/server/services/routing/helpers/fetch-data.js | 8 +++++--- .../test/unit/services/routing/helpers/fetch-data_spec.js | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/core/server/services/routing/helpers/fetch-data.js b/core/server/services/routing/helpers/fetch-data.js index 014cc196e5..9a3ab46775 100644 --- a/core/server/services/routing/helpers/fetch-data.js +++ b/core/server/services/routing/helpers/fetch-data.js @@ -105,10 +105,12 @@ function fetchData(pathOptions, routerOptions, locals) { response.data = {}; _.each(routerOptions.data, function (config, name) { + response.data[name] = results[name][config.resource]; + if (config.type === 'browse') { - response.data[name] = results[name]; - } else { - response.data[name] = results[name][config.resource]; + response.data[name].meta = results[name].meta; + // @TODO remove in v3 + response.data[name][config.resource] = results[name][config.resource]; } }); } diff --git a/core/test/unit/services/routing/helpers/fetch-data_spec.js b/core/test/unit/services/routing/helpers/fetch-data_spec.js index 45b6fc19c7..ea4ccc86b9 100644 --- a/core/test/unit/services/routing/helpers/fetch-data_spec.js +++ b/core/test/unit/services/routing/helpers/fetch-data_spec.js @@ -98,6 +98,8 @@ describe('Unit - services/routing/helpers/fetch-data', function () { result.data.featured.should.not.have.properties('data'); result.posts.length.should.eql(posts.length); + result.data.featured.length.should.eql(posts.length); + // @TODO v3 will deprecate this style (featured.posts) result.data.featured.posts.length.should.eql(posts.length); api.posts.browse.calledTwice.should.be.true(); @@ -133,6 +135,8 @@ describe('Unit - services/routing/helpers/fetch-data', function () { result.data.featured.should.not.have.properties('data'); result.posts.length.should.eql(posts.length); + result.data.featured.length.should.eql(posts.length); + // @TODO v3 will deprecate this style (featured.posts) result.data.featured.posts.length.should.eql(posts.length); api.posts.browse.calledTwice.should.be.true();