all files / api/toJSON/ articleContent.js

95.83% Statements 23/24
90% Branches 9/10
100% Functions 1/1
95% Lines 19/20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39                                       
'use strict';
 
const R = require('ramda');
let createContentItem = require('./contentItem');
let createEmbeddedContent = require('./embed');
 
const isEmbedded = articleContent => !R.isNil(articleContent.static_content) && articleContent.static_content.type === 'embed';
const isText = articleContent => !R.isNil(articleContent.static_content);
const contentItemMissing = articleContent => !R.isNil(articleContent.content_item_id);
const isContentItem = articleContent => !R.isNil(articleContent.content_item);
 
module.exports = function (config, articleContent, homeSection, filename) {
    if(isEmbedded(articleContent)){
        const staticContent = articleContent.static_content;
        const meta = {
            "type": "embed"
        };
        return [meta, {
            data: createEmbeddedContent(homeSection, filename, staticContent)
        }];
    }else if (isContentItem(articleContent)) {
        return createContentItem(config, articleContent.static_content, articleContent.content_item);
    } else Iif(contentItemMissing(articleContent)) {
        return null;
    }else if(isText(articleContent)) {
        const staticContent = articleContent.static_content;
        const meta = {
            "type": "text"
        };
        return [meta, {
            data: {
                type: staticContent.type,
                attributes: {
                    body: staticContent.body
                }
            }
        }];
    }
};