Ghost/ghost/api-framework/lib/serializers/input/all.js
Daniel Lockyer 348924d431 Updated API framework debug and test names
- these tests have moved from `core/` so the names are no longer
  relevant
2022-08-11 17:44:59 +02:00

42 lines
1.3 KiB
JavaScript

const debug = require('@tryghost/debug')('serializers:input:all');
const _ = require('lodash');
const utils = require('../../utils');
const INTERNAL_OPTIONS = ['transacting', 'forUpdate'];
/**
* @description Shared serializer for all requests.
*
* Transforms certain options from API notation into model readable language/notation.
*
* e.g. API uses "include", but model layer uses "withRelated".
*/
module.exports = {
all(apiConfig, frame) {
debug('serialize all');
if (frame.options.include) {
frame.options.withRelated = utils.options.trimAndLowerCase(frame.options.include);
delete frame.options.include;
}
if (frame.options.fields) {
frame.options.columns = utils.options.trimAndLowerCase(frame.options.fields);
delete frame.options.fields;
}
if (frame.options.formats) {
frame.options.formats = utils.options.trimAndLowerCase(frame.options.formats);
}
if (frame.options.formats && frame.options.columns) {
frame.options.columns = frame.options.columns.concat(frame.options.formats);
}
if (!frame.options.context.internal) {
debug('omit internal options');
frame.options = _.omit(frame.options, INTERNAL_OPTIONS);
}
}
};