Fixed entity API database query.
This commit is contained in:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user