Fetch event types, link them with event nodes

This commit is contained in:
ponas committed 2019-02-22 01:44:22 +01:00
1 parent 6db1424ee5
commit eacec6e824
2 files changed
+25 -1

No files matched your search

+1
View File
@@ -24,6 +24,7 @@ module.exports = {
includedRoutes: [
"**/*/*/categories",
"**/*/*/events",
"**/*/*/event_type",
"**/*/*/posts",
"**/*/*/pages",
"**/*/*/media",
+24 -1
View File
@@ -4,6 +4,7 @@ const htmlEntities = new Entities();
const neufNormalizer = ({ entities }) => {
entities = decodeTitles(entities)
entities = mapEventsToEventTypes(entities)
return entities
}
@@ -16,4 +17,26 @@ const decodeTitles = entities => {
}
return e
})
}
}
const mapEventsToEventTypes = entities => {
const eventTaxonomies = [`wordpress__wp_event_type`, ]
const eventTypes = entities.filter(e => eventTaxonomies.includes(e.__type))
return entities.map(e => {
// Replace event types with links to their nodes.
let eventHasType = e.event_type && Array.isArray(e.event_type) && e.event_type.length
if (eventTypes.length && eventHasType) {
e.event_type___NODE = e.event_type.map(
t =>
eventTypes.find(
tObj =>
(Number.isInteger(t) ? t : t.wordpress_id) === tObj.wordpress_id
).id
)
delete e.event_type
}
return e
})
}