From ecdd6d8fb0f733a4a7adc5eaca77928744ec7afb Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Tue, 20 Oct 2020 15:28:58 +0200 Subject: [PATCH] Added logo path to entity API. --- src/entities.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/entities.js b/src/entities.js index 00d9271a..e3c881a2 100644 --- a/src/entities.js +++ b/src/entities.js @@ -13,6 +13,11 @@ function curateEntity(entity, includeParameters = false) { return null; } + const logo = (entity.has_logo + && (((entity.independent || entity.type === 'network') && `${entity.slug}/network.png`) + || (entity.parent && `${entity.parent.slug}/${entity.slug}.png`))) + || null; + const curatedEntity = entity.id ? { id: entity.id, name: entity.name, @@ -20,7 +25,9 @@ function curateEntity(entity, includeParameters = false) { description: entity.description, slug: entity.slug, type: entity.type, + independent: !!entity.independent, aliases: entity.alias, + logo, parent: curateEntity(entity.parent, includeParameters), } : {}; @@ -176,7 +183,7 @@ async function fetchEntities(type, limit) { async function searchEntities(query, type, limit) { const entities = await knex .select(knex.raw(` - entities.id, entities.name, entities.slug, entities.type, entities.url, entities.description, entities.alias, + entities.id, entities.name, entities.slug, entities.type, entities.url, entities.description, entities.alias, entities.has_logo, COALESCE(json_agg(tags) FILTER (WHERE tags.id IS NOT NULL), '[]') as tags, row_to_json(parents) as parent `)) @@ -189,7 +196,7 @@ async function searchEntities(query, type, limit) { .leftJoin('entities as parents', 'parents.id', 'entities.parent_id') .leftJoin('entities_tags', 'entities_tags.entity_id', 'entities.id') .leftJoin('tags', 'tags.id', 'entities_tags.tag_id') - .groupBy('entities.id', 'entities.name', 'entities.slug', 'entities.type', 'entities.url', 'entities.description', 'entities.alias', 'parents.id') + .groupBy('entities.id', 'entities.name', 'entities.slug', 'entities.type', 'entities.url', 'entities.description', 'entities.alias', 'entities.has_logo', 'parents.id') .limit(limit || 100); return curateEntities(entities);