Skip to content

Commit

Permalink
Merge pull request #39 from CodeVoyager/feat/reader-nav-single-type
Browse files Browse the repository at this point in the history
feat: single type is a template for itself
  • Loading branch information
cyp3rius authored Mar 2, 2021
2 parents 7bfd441 + 2582d0c commit 9227c04
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions services/utils/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,25 @@ module.exports = {
}),
);
const relatedResponseMap = responses.reduce((acc, curr) => ({ ...acc, ...curr }), {});
const singleTypes = new Set(
contentTypes
.filter(x => x.isSingle)
.map(({ contentTypeName }) => contentTypeName)
);

return (contentType, id) => {
const template = get(relatedResponseMap[contentType].find(data => data.id === id), 'template');
const templateComponent = this.getTemplateComponentFromTemplate(template);
return get(templateComponent, 'options.templateName', TEMPLATE_DEFAULT);

if (template) {
const templateComponent = this.getTemplateComponentFromTemplate(template);
return get(templateComponent, 'options.templateName', TEMPLATE_DEFAULT);
}

if (singleTypes.has(contentType)) {
return contentType;
}

return TEMPLATE_DEFAULT;
};
},

Expand Down

0 comments on commit 9227c04

Please sign in to comment.