From df99e724e3d7dc1665916844983849494deea80d Mon Sep 17 00:00:00 2001 From: Fabien O'Carroll Date: Wed, 31 Jul 2019 14:02:21 +0800 Subject: [PATCH] Renamed page->type in the page&posts serializers refs #10922 --- .../api/v2/utils/serializers/input/pages.js | 23 +++++++++++++++++++ .../api/v2/utils/serializers/input/posts.js | 23 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/core/server/api/v2/utils/serializers/input/pages.js b/core/server/api/v2/utils/serializers/input/pages.js index 6a3316b915..28ab66858b 100644 --- a/core/server/api/v2/utils/serializers/input/pages.js +++ b/core/server/api/v2/utils/serializers/input/pages.js @@ -3,6 +3,27 @@ const debug = require('ghost-ignition').debug('api:v2:utils:serializers:input:pa const converters = require('../../../../../lib/mobiledoc/converters'); const url = require('./utils/url'); const localUtils = require('../../index'); +const mongo = require('./utils/mongo'); + +/* + * Replaces references of "page" in filters + * with the correct column "type" + */ +function replacePageWithType(mongoJSON) { + return mongo.mapKeysAndValues(mongoJSON, { + 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')) { @@ -86,6 +107,8 @@ module.exports = { defaultRelations(frame); } + frame.options.mongoTransformer = replacePageWithType; + debug(frame.options); }, diff --git a/core/server/api/v2/utils/serializers/input/posts.js b/core/server/api/v2/utils/serializers/input/posts.js index 5a57926823..218895cd04 100644 --- a/core/server/api/v2/utils/serializers/input/posts.js +++ b/core/server/api/v2/utils/serializers/input/posts.js @@ -4,6 +4,27 @@ const url = require('./utils/url'); const localUtils = require('../../index'); const labs = require('../../../../../services/labs'); const converters = require('../../../../../lib/mobiledoc/converters'); +const mongo = require('./utils/mongo'); + +/* + * Replaces references of "page" in filters + * with the correct column "type" + */ +function replacePageWithType(mongoJSON) { + return mongo.mapKeysAndValues(mongoJSON, { + 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')) { @@ -108,6 +129,8 @@ module.exports = { defaultRelations(frame); } + frame.options.mongoTransformer = replacePageWithType; + debug(frame.options); },