From 13afb7febd6df6ce378aed8e677f5d6d0ea1fa95 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Fri, 30 Jun 2023 11:40:39 +0800 Subject: [PATCH] feat: create labels if not exist when setting labels in the highlight --- packages/api/src/elastic/labels.ts | 26 ++++++----- packages/api/src/generated/graphql.ts | 3 +- packages/api/src/generated/schema.graphql | 3 +- packages/api/src/resolvers/labels/index.ts | 51 +++++++++++++++++----- packages/api/src/schema.ts | 3 +- 5 files changed, 60 insertions(+), 26 deletions(-) diff --git a/packages/api/src/elastic/labels.ts b/packages/api/src/elastic/labels.ts index 6117a2857..cafaf01e0 100644 --- a/packages/api/src/elastic/labels.ts +++ b/packages/api/src/elastic/labels.ts @@ -1,7 +1,7 @@ -import { Label, PageContext } from './types' -import { client, INDEX_ALIAS } from './index' -import { EntityType } from '../datalayer/pubsub' import { ResponseError } from '@elastic/elasticsearch/lib/errors' +import { EntityType } from '../datalayer/pubsub' +import { client, INDEX_ALIAS } from './index' +import { Label, PageContext } from './types' export const addLabelInPage = async ( pageId: string, @@ -273,7 +273,8 @@ export const updateLabel = async ( export const setLabelsForHighlight = async ( highlightId: string, labels: Label[], - ctx: PageContext + ctx: PageContext, + labelsToAdd?: Label[] ): Promise => { try { const { body } = await client.updateByQuery({ @@ -304,14 +305,17 @@ export const setLabelsForHighlight = async ( conflicts: 'proceed', // ignore conflicts }) - if (body.updated > 0) { - for (const label of labels) { - await ctx.pubsub.entityCreated