'use strict';
const R = require('ramda');
// once merged to master this can be exported
const splitAndParse = R.compose(
R.defaultTo(null),
parseInt,
R.takeLast(1),
R.split('.'),
String
);
module.exports = response => {
const metadata = {
type:'author',
id: splitAndParse(response.id)
};
const attributes = R.assoc('attributes',
R.pick(
[
'name',
'description',
'twitterId'
],
response
),
{});
// links property could not be there
// and should not be in the result object
const links = R.ifElse(
R.any(x => x !== undefined),
() => R.assoc('links', R.pick(['url','imageUrl'], response), {}),
R.defaultTo(null)
)([response.url, response.imageUrl]);
return R.assoc('data',
R.mergeAll([metadata, attributes, links]),
{}
);
};
|