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); },