feat: add topic hierarchy APIs
This commit is contained in:
@@ -53,3 +53,31 @@ export async function findConnectedTopicRows(
|
||||
.orderBy('topics.normalized_name', 'asc')
|
||||
.execute() as Promise<ConnectedTopicRow[]>;
|
||||
}
|
||||
|
||||
export async function findChildTopicRows(
|
||||
executor: DatabaseExecutor,
|
||||
parentTopicId: string,
|
||||
): Promise<TopicRecord[]> {
|
||||
return executor
|
||||
.selectFrom('topic_relations')
|
||||
.innerJoin('topics', 'topics.id', 'topic_relations.child_topic_id')
|
||||
.selectAll('topics')
|
||||
.where('topic_relations.parent_topic_id', '=', parentTopicId)
|
||||
.where('topic_relations.relation', '=', 'parent_of')
|
||||
.orderBy('topics.normalized_name', 'asc')
|
||||
.execute();
|
||||
}
|
||||
|
||||
export async function findParentTopicRows(
|
||||
executor: DatabaseExecutor,
|
||||
childTopicId: string,
|
||||
): Promise<TopicRecord[]> {
|
||||
return executor
|
||||
.selectFrom('topic_relations')
|
||||
.innerJoin('topics', 'topics.id', 'topic_relations.parent_topic_id')
|
||||
.selectAll('topics')
|
||||
.where('topic_relations.child_topic_id', '=', childTopicId)
|
||||
.where('topic_relations.relation', '=', 'parent_of')
|
||||
.orderBy('topics.normalized_name', 'asc')
|
||||
.execute();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user