'use strict';
const R = require('ramda');
let getLastUpdated = require("./getLastUpdated");
let createGalleryContent = require('./galleryContent');
module.exports = function (imageDimensions, tuple) {
let images = [];
let gallery = tuple[1];
const galleryObj = {
data: {
type: 'gallery',
id: gallery.escenic_id,
attributes: {
title: gallery.title
}
}
};
Eif (R.has('gallery_contents', gallery)) {
const contents = gallery.gallery_contents.map(contentItem => {
return createGalleryContent(imageDimensions, contentItem);
});
images = R.reject(R.isNil, contents);
}
galleryObj.included = R.tail(images).map(R.last);
galleryObj.data.attributes.leadMedia = R.isEmpty(images) ? null : R.head(images)[1];
const meta = {
"type": "gallery",
"lastModifiedDate": getLastUpdated(gallery.last_modified_date || gallery.updated_at, images),
"id": gallery.id
};
Iif(R.has('article_relations', gallery) && gallery.article_relations.length > 0){
const attributes = R.merge(galleryObj.data.attributes, gallery.article_relations[0].static_content);
return Array.of(meta, R.assocPath(['data', 'attributes'], attributes, galleryObj));
} else {
return Array.of(meta, galleryObj);
}
}; |