From 2536405dbaebba808453b793ffff36bf6830fba3 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Sun, 18 Oct 2020 00:01:34 +0200 Subject: [PATCH] Fixed entity API database query. --- README.md | 2 +- src/entities.js | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 40670e17..1a9e09d4 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ To generate thumbnails for new logos and tag photos, install ImageMagick and run * `--level`: Change log level to `silly`, `verbose`, `info`, `warn` or `error`. ### API -A GraphQL API is available at `/graphql`, and a REST API is available at the following endpoints: +A GraphQL API is available at `/graphql`, and a REST API is available at the following `GET` endpoints: * `/api/scenes`: Fetch the latest releases. Supports search with `query` or `q` parameter; * `/api/scenes/{ID}`: Fetch scene by ID. diff --git a/src/entities.js b/src/entities.js index 1b8ec94d..4de2093f 100644 --- a/src/entities.js +++ b/src/entities.js @@ -17,7 +17,6 @@ function curateEntity(entity, includeParameters = false) { description: entity.description, slug: entity.slug, type: entity.type, - parameters: includeParameters ? entity.parameters : null, parent: curateEntity(entity.parent, includeParameters), } : {}; @@ -37,6 +36,10 @@ function curateEntity(entity, includeParameters = false) { })); } + if (includeParameters) { + curatedEntity.parameters = entity.parameters; + } + return curatedEntity; } @@ -168,7 +171,7 @@ async function fetchEntities(type, limit) { async function searchEntities(query, type, limit) { const entities = knex .select(knex.raw(` - entities.*, + entities.id, entities.name, entities.slug, entities.type, entities.url, entities.description, COALESCE(json_agg(tags) FILTER (WHERE tags.id IS NOT NULL), '[]') as tags, row_to_json(parents) as parent `)) @@ -181,7 +184,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', 'parents.id') + .groupBy('entities.id', 'entities.name', 'entities.slug', 'entities.type', 'entities.url', 'entities.description', 'parents.id') .limit(limit || 100); console.log(entities.toString());