Fixed include option not working for fetching tiers via #get helper

refs https://github.com/TryGhost/Team/issues/1004

The output serializer for product was not handling `include` option value as comma separated string, which is passed via `#get` helper to fetch related prices for tiers. This change fixes the handling to work with both array as well as comma-separated include values.
This commit is contained in:
Rishabh 2022-03-02 21:34:28 +05:30 committed by Rishabh Garg
parent eac732f620
commit a328e3e88b
2 changed files with 4 additions and 2 deletions

View File

@ -1,6 +1,7 @@
//@ts-check
const debug = require('@tryghost/debug')('api:canary:utils:serializers:output:products');
const _ = require('lodash');
const utils = require('../../../../shared/utils');
const allowedIncludes = ['stripe_prices', 'monthly_price', 'yearly_price'];
@ -22,7 +23,7 @@ module.exports = {
*/
function paginatedProducts(page, _apiConfig, frame) {
const requestedQueryIncludes = frame.original && frame.original.query && frame.original.query.include && frame.original.query.include.split(',') || [];
const requestedOptionsIncludes = frame.original && frame.original.options && frame.original.options.include || [];
const requestedOptionsIncludes = utils.options.trimAndLowerCase(frame.original && frame.original.options && frame.original.options.include || []);
return {
products: page.data.map((model) => {
return cleanIncludes(

View File

@ -3,6 +3,7 @@ const debug = require('@tryghost/debug')('api:canary:utils:serializers:output:ti
const _ = require('lodash');
const allowedIncludes = ['monthly_price', 'yearly_price'];
const utils = require('../../../../shared/utils');
module.exports = {
browse: createSerializer('browse', paginatedTiers),
@ -22,7 +23,7 @@ module.exports = {
*/
function paginatedTiers(page, _apiConfig, frame) {
const requestedQueryIncludes = frame.original && frame.original.query && frame.original.query.include && frame.original.query.include.split(',') || [];
const requestedOptionsIncludes = frame.original && frame.original.options && frame.original.options.include || [];
const requestedOptionsIncludes = utils.options.trimAndLowerCase(frame.original && frame.original.options && frame.original.options.include || []);
return {
tiers: page.data.map((model) => {
return cleanIncludes(