Repository URL to install this package:
|
Version:
1.3.3 ▾
|
import { getTyped } from '@skava/modules/___dist/composition'
import { isArray } from 'exotic'
function autofixHACK(snapshot) {
let categories = snapshot
// logCategories(snapshot)
// then we have a nested response, do first transform of a lift
if (snapshot.children) {
categories = snapshot.children.categories
}
// if it's an object still
if (isArray(categories.categories)) {
categories = categories.categories
}
// if nothing good
if (!isArray(categories)) {
categories = []
}
return categories
}
function fromArrayToVideo(category) {
const { array } = getTyped(category)
const { label, value } = array('videos')[0] || array('properties.iteminfo.videos')[0] || {}
return value
}
const toCategory = category => {
const { array } = getTyped(category)
// ONLY ON TOP LEVEL?!
// const children = category.children === null ? {} : category.children
const _identifier = category.identifier + category.image + category.name
// const defaultDescription = 'In the beginning, There were ' + category.name
const getDescription = category => {
switch (category.name) {
case 'Plain Tees':
return category.name + ' - Shirts For The Long-Haul'
case 'Workwear':
return 'Do ' + category.name + ' Like A Boss'
case 'Fashion':
return category.name + ' Tees. | Own The Oxymoron'
case 'Logo/Graphic':
return 'Graphic Tees, the original Statement-makers'
case 'Undershirts':
return 'In the beginning, There were ' + category.name
}
}
const defaultDescription = getDescription(category)
const description = category.description ? category.description : defaultDescription
return {
// uuid
_identifier,
// nav
identifier: category.identifier,
// label
name: category.name,
image: category.image,
// not sure if needed?
type: category.type,
description,
video: fromArrayToVideo(category),
// ?
categories: array('children.categories').map(toCategory),
categoryids: array('properties.iteminfo.categoryids'),
sortingoptions: array('properties.state.sorting.0.options'),
/* Fix for MST type vs graphql type */
// @todo hoist children.categories => list
// children,
// starttime: +getCategory('properties.state.starttime', category),
// status: +getCategory('properties.state.status', category),
}
}
const transformCategories = snapshot => {
const categories = autofixHACK(snapshot)
return {
type: snapshot.type,
categories: categories.map(toCategory),
}
// return {
// type: snapshot.type,
// categories: categories.map(toCategory),
// }
}
export { transformCategories }
export default transformCategories