0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Fixed product API removing included data

no refs

The product output serializer is removing the include data due to the includes being missing in frame options for some reason. This is a temporary fix that always allows the default includes as `monthly/yearly_price` to unblock the API, and we can revert it back to explicit request once fixed.
This commit is contained in:
Rishabh 2021-06-04 12:28:56 +05:30
parent 3adeab142d
commit ea9a83d444

View file

@ -21,11 +21,13 @@ module.exports = {
*/
function paginatedProducts(page, _apiConfig, frame) {
const requestedIncludes = frame.original && frame.original.options && frame.original.options.include || [];
const defaultIncludes = ['monthly_price', 'yearly_price'];
return {
products: page.data.map((model) => {
return cleanIncludes(
allowedIncludes,
requestedIncludes,
defaultIncludes,
serializeProduct(model, frame.options, frame.apiType)
);
}),
@ -42,11 +44,13 @@ function paginatedProducts(page, _apiConfig, frame) {
*/
function singleProduct(model, _apiConfig, frame) {
const requestedIncludes = frame.original && frame.original.options && frame.original.options.include || [];
const defaultIncludes = ['monthly_price', 'yearly_price'];
return {
products: [
cleanIncludes(
allowedIncludes,
requestedIncludes,
defaultIncludes,
serializeProduct(model, frame.options, frame.apiType)
)
]
@ -119,15 +123,17 @@ function serializeStripePrice(data, hideStripeData) {
*
* @returns {Data}
*/
function cleanIncludes(allowed, requested, data) {
function cleanIncludes(allowed, requested, defaults, data) {
const cleaned = {
...data
};
for (const include of allowed) {
if (!requested.includes(include)) {
if (!requested.includes(include) && !defaults.includes(include)) {
delete cleaned[include];
}
}
return cleaned;
}