diff --git a/core/server/api/canary/utils/serializers/input/pages.js b/core/server/api/canary/utils/serializers/input/pages.js index 696d3e0744..8d41ee0349 100644 --- a/core/server/api/canary/utils/serializers/input/pages.js +++ b/core/server/api/canary/utils/serializers/input/pages.js @@ -1,9 +1,24 @@ const _ = require('lodash'); const debug = require('ghost-ignition').debug('api:canary:utils:serializers:input:pages'); +const mapNQLKeyValues = require('nql-map-key-values'); const converters = require('../../../../../lib/mobiledoc/converters'); const url = require('./utils/url'); const localUtils = require('../../index'); +const replacePageWithType = mapNQLKeyValues({ + key: { + from: 'page', + to: 'type' + }, + values: [{ + from: false, + to: 'post' + }, { + from: true, + to: 'page' + }] +}); + function removeMobiledocFormat(frame) { if (frame.options.formats && frame.options.formats.includes('mobiledoc')) { frame.options.formats = frame.options.formats.filter((format) => { @@ -55,9 +70,9 @@ function defaultFormat(frame) { */ const forcePageFilter = (frame) => { if (frame.options.filter) { - frame.options.filter = `(${frame.options.filter})+page:true`; + frame.options.filter = `(${frame.options.filter})+type:page`; } else { - frame.options.filter = 'page:true'; + frame.options.filter = 'type:page'; } }; @@ -86,6 +101,8 @@ module.exports = { defaultRelations(frame); } + frame.options.mongoTransformer = replacePageWithType; + debug(frame.options); }, @@ -123,7 +140,7 @@ module.exports = { // @NOTE: force storing page if (options.add) { - frame.data.pages[0].page = true; + frame.data.pages[0].type = 'page'; } // CASE: Transform short to long format @@ -163,7 +180,7 @@ module.exports = { destroy(apiConfig, frame) { frame.options.destroyBy = { id: frame.options.id, - page: true + type: 'page' }; defaultFormat(frame); diff --git a/core/server/api/canary/utils/serializers/input/posts.js b/core/server/api/canary/utils/serializers/input/posts.js index e61b212685..b89ee84fbe 100644 --- a/core/server/api/canary/utils/serializers/input/posts.js +++ b/core/server/api/canary/utils/serializers/input/posts.js @@ -1,10 +1,25 @@ const _ = require('lodash'); const debug = require('ghost-ignition').debug('api:canary:utils:serializers:input:posts'); +const mapNQLKeyValues = require('nql-map-key-values'); const url = require('./utils/url'); const localUtils = require('../../index'); const labs = require('../../../../../services/labs'); const converters = require('../../../../../lib/mobiledoc/converters'); +const replacePageWithType = mapNQLKeyValues({ + key: { + from: 'page', + to: 'type' + }, + values: [{ + from: false, + to: 'post' + }, { + from: true, + to: 'page' + }] +}); + function removeMobiledocFormat(frame) { if (frame.options.formats && frame.options.formats.includes('mobiledoc')) { frame.options.formats = frame.options.formats.filter((format) => { @@ -64,9 +79,9 @@ function defaultFormat(frame) { */ const forcePageFilter = (frame) => { if (frame.options.filter) { - frame.options.filter = `(${frame.options.filter})+page:false`; + frame.options.filter = `(${frame.options.filter})+type:post`; } else { - frame.options.filter = 'page:false'; + frame.options.filter = 'type:post'; } }; @@ -108,6 +123,8 @@ module.exports = { defaultRelations(frame); } + frame.options.mongoTransformer = replacePageWithType; + debug(frame.options); }, @@ -158,7 +175,7 @@ module.exports = { // @NOTE: force adding post if (options.add) { - frame.data.posts[0].page = false; + frame.data.posts[0].type = 'post'; } // CASE: Transform short to long format @@ -196,7 +213,7 @@ module.exports = { destroy(apiConfig, frame) { frame.options.destroyBy = { id: frame.options.id, - page: false + type: 'post' }; defaultFormat(frame); diff --git a/core/server/api/canary/utils/serializers/output/utils/mapper.js b/core/server/api/canary/utils/serializers/output/utils/mapper.js index 77aab97d44..4d7112932d 100644 --- a/core/server/api/canary/utils/serializers/output/utils/mapper.js +++ b/core/server/api/canary/utils/serializers/output/utils/mapper.js @@ -57,6 +57,8 @@ const mapPost = (model, frame) => { }); } + delete jsonModel.type; + return jsonModel; }; diff --git a/core/test/regression/api/canary/admin/schedules_spec.js b/core/test/regression/api/canary/admin/schedules_spec.js index 3b91d096ec..ff6eaf5539 100644 --- a/core/test/regression/api/canary/admin/schedules_spec.js +++ b/core/test/regression/api/canary/admin/schedules_spec.js @@ -80,7 +80,7 @@ describe('Schedules API', function () { published_at: moment().add(30, 'seconds').toDate(), status: 'scheduled', slug: 'fifth', - page: true + type: 'page' })); return Promise.mapSeries(resources, function (post) { diff --git a/core/test/regression/api/canary/content/utils.js b/core/test/regression/api/canary/content/utils.js index 8e807c0d95..3c5cbc9c0e 100644 --- a/core/test/regression/api/canary/content/utils.js +++ b/core/test/regression/api/canary/content/utils.js @@ -25,6 +25,7 @@ const expectedProperties = { .without('status') // @TODO: https://github.com/TryGhost/Ghost/issues/10335 // .without('page') + .without('type') // canary returns a calculated excerpt field .concat('excerpt') , diff --git a/core/test/regression/site/site_spec.js b/core/test/regression/site/site_spec.js index bfd93db41c..b3c7d32635 100644 --- a/core/test/regression/site/site_spec.js +++ b/core/test/regression/site/site_spec.js @@ -3659,7 +3659,7 @@ describe('Integration - Web - Site', function () { response.statusCode.should.eql(200); response.template.should.eql('tag'); - postSpy.args[0][0].options.filter.should.eql('(tags:\'bacon\'+tags.visibility:public)+page:false'); + postSpy.args[0][0].options.filter.should.eql('(tags:\'bacon\'+tags.visibility:public)+type:post'); postSpy.args[0][0].options.page.should.eql(1); postSpy.args[0][0].options.limit.should.eql(2); }); diff --git a/core/test/unit/api/canary/utils/serializers/input/pages_spec.js b/core/test/unit/api/canary/utils/serializers/input/pages_spec.js index 6e585812ba..ba4ff130b4 100644 --- a/core/test/unit/api/canary/utils/serializers/input/pages_spec.js +++ b/core/test/unit/api/canary/utils/serializers/input/pages_spec.js @@ -13,7 +13,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () { }; serializers.input.pages.browse(apiConfig, frame); - frame.options.filter.should.eql('page:true'); + frame.options.filter.should.eql('type:page'); }); it('combine filters', function () { @@ -27,7 +27,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () { }; serializers.input.pages.browse(apiConfig, frame); - frame.options.filter.should.eql('(status:published+tag:eins)+page:true'); + frame.options.filter.should.eql('(status:published+tag:eins)+type:page'); }); it('combine filters', function () { @@ -41,7 +41,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () { }; serializers.input.pages.browse(apiConfig, frame); - frame.options.filter.should.eql('(page:false+tag:eins)+page:true'); + frame.options.filter.should.eql('(page:false+tag:eins)+type:page'); }); it('combine filters', function () { @@ -55,7 +55,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () { }; serializers.input.pages.browse(apiConfig, frame); - frame.options.filter.should.eql('(page:false)+page:true'); + frame.options.filter.should.eql('(page:false)+type:page'); }); it('remove mobiledoc option from formats', function () { @@ -87,7 +87,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () { }; serializers.input.pages.read(apiConfig, frame); - frame.options.filter.should.eql('page:true'); + frame.options.filter.should.eql('type:page'); }); it('content api default', function () { @@ -107,7 +107,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () { }; serializers.input.pages.read(apiConfig, frame); - frame.options.filter.should.eql('page:true'); + frame.options.filter.should.eql('type:page'); }); it('admin api default', function () { @@ -127,7 +127,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () { }; serializers.input.pages.read(apiConfig, frame); - frame.options.filter.should.eql('(page:true)+status:[draft,published,scheduled]'); + frame.options.filter.should.eql('(type:page)+status:[draft,published,scheduled]'); }); it('custom page filter', function () { @@ -142,7 +142,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () { }; serializers.input.pages.read(apiConfig, frame); - frame.options.filter.should.eql('(page:false)+page:true'); + frame.options.filter.should.eql('(page:false)+type:page'); }); it('custom status filter', function () { @@ -163,7 +163,7 @@ describe('Unit: canary/utils/serializers/input/pages', function () { }; serializers.input.pages.read(apiConfig, frame); - frame.options.filter.should.eql('(status:draft)+page:true'); + frame.options.filter.should.eql('(status:draft)+type:page'); }); it('remove mobiledoc option from formats', function () { diff --git a/core/test/unit/api/canary/utils/serializers/input/posts_spec.js b/core/test/unit/api/canary/utils/serializers/input/posts_spec.js index 0e93a70446..530d0fd165 100644 --- a/core/test/unit/api/canary/utils/serializers/input/posts_spec.js +++ b/core/test/unit/api/canary/utils/serializers/input/posts_spec.js @@ -21,7 +21,7 @@ describe('Unit: canary/utils/serializers/input/posts', function () { }; serializers.input.posts.browse(apiConfig, frame); - frame.options.filter.should.eql('page:false'); + frame.options.filter.should.eql('type:post'); }); it('should not work for non public context', function () { @@ -36,7 +36,7 @@ describe('Unit: canary/utils/serializers/input/posts', function () { }; serializers.input.posts.browse(apiConfig, frame); - should.equal(frame.options.filter, '(page:false)+status:[draft,published,scheduled]'); + should.equal(frame.options.filter, '(type:post)+status:[draft,published,scheduled]'); }); it('combine filters', function () { @@ -56,7 +56,7 @@ describe('Unit: canary/utils/serializers/input/posts', function () { }; serializers.input.posts.browse(apiConfig, frame); - frame.options.filter.should.eql('(status:published+tag:eins)+page:false'); + frame.options.filter.should.eql('(status:published+tag:eins)+type:post'); }); it('combine filters', function () { @@ -76,7 +76,7 @@ describe('Unit: canary/utils/serializers/input/posts', function () { }; serializers.input.posts.browse(apiConfig, frame); - frame.options.filter.should.eql('(page:true+tag:eins)+page:false'); + frame.options.filter.should.eql('(page:true+tag:eins)+type:post'); }); it('combine filters', function () { @@ -96,7 +96,7 @@ describe('Unit: canary/utils/serializers/input/posts', function () { }; serializers.input.posts.browse(apiConfig, frame); - frame.options.filter.should.eql('(page:true)+page:false'); + frame.options.filter.should.eql('(page:true)+type:post'); }); it('combine filters', function () { @@ -116,7 +116,7 @@ describe('Unit: canary/utils/serializers/input/posts', function () { }; serializers.input.posts.browse(apiConfig, frame); - frame.options.filter.should.eql('((page:true,page:false))+page:false'); + frame.options.filter.should.eql('((page:true,page:false))+type:post'); }); it('remove mobiledoc option from formats', function () { @@ -137,7 +137,7 @@ describe('Unit: canary/utils/serializers/input/posts', function () { }); describe('read', function () { - it('with apiType of "content" it forces page filter', function () { + it('with apiType of "content" it forces type filter', function () { const apiConfig = {}; const frame = { apiType: 'content', @@ -146,24 +146,24 @@ describe('Unit: canary/utils/serializers/input/posts', function () { }; serializers.input.posts.read(apiConfig, frame); - frame.options.filter.should.eql('page:false'); + frame.options.filter.should.eql('type:post'); }); - it('with apiType of "content" it forces page false filter', function () { + it('with apiType of "content" it forces type:post filter', function () { const apiConfig = {}; const frame = { apiType: 'content', options: { - filter: 'page:true' + filter: 'type:page' }, data: {} }; serializers.input.posts.read(apiConfig, frame); - frame.options.filter.should.eql('(page:true)+page:false'); + frame.options.filter.should.eql('(type:page)+type:post'); }); - it('with apiType of "admin" it forces page & status false filter', function () { + it('with apiType of "admin" it forces type & status false filter', function () { const apiConfig = {}; const frame = { apiType: 'admin', @@ -179,10 +179,10 @@ describe('Unit: canary/utils/serializers/input/posts', function () { }; serializers.input.posts.read(apiConfig, frame); - frame.options.filter.should.eql('(page:false)+status:[draft,published,scheduled]'); + frame.options.filter.should.eql('(type:post)+status:[draft,published,scheduled]'); }); - it('with apiType of "admin" it forces page filter & respects custom status filter', function () { + it('with apiType of "admin" it forces type:post filter & respects custom status filter', function () { const apiConfig = {}; const frame = { apiType: 'admin', @@ -199,7 +199,7 @@ describe('Unit: canary/utils/serializers/input/posts', function () { }; serializers.input.posts.read(apiConfig, frame); - frame.options.filter.should.eql('(status:draft)+page:false'); + frame.options.filter.should.eql('(status:draft)+type:post'); }); it('remove mobiledoc option from formats', function () {