From c0966d908f59ef7d2d243baafbe431b13e22019f Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Thu, 14 Apr 2022 12:14:15 +0800 Subject: [PATCH] upload highlight and label to gcs if successfully updated in elastic (#420) --- packages/api/src/elastic/highlights.ts | 4 +- packages/api/src/elastic/labels.ts | 44 ++++++++++++++++++++-- packages/api/src/resolvers/labels/index.ts | 20 +++++----- 3 files changed, 53 insertions(+), 15 deletions(-) diff --git a/packages/api/src/elastic/highlights.ts b/packages/api/src/elastic/highlights.ts index 934563ca3..8277f7b9b 100644 --- a/packages/api/src/elastic/highlights.ts +++ b/packages/api/src/elastic/highlights.ts @@ -134,7 +134,7 @@ export const deleteHighlight = async ( refresh: ctx.refresh, }) - if (body.result !== 'updated') return false + if (body.updated === 0) return false await ctx.pubsub.entityDeleted(EntityType.HIGHLIGHT, highlightId, ctx.uid) @@ -279,7 +279,7 @@ export const updateHighlight = async ( refresh: ctx.refresh, }) - if (body.result !== 'updated') return false + if (body.updated === 0) return false await ctx.pubsub.entityUpdated( EntityType.HIGHLIGHT, diff --git a/packages/api/src/elastic/labels.ts b/packages/api/src/elastic/labels.ts index 2bb00bba8..69af5365e 100644 --- a/packages/api/src/elastic/labels.ts +++ b/packages/api/src/elastic/labels.ts @@ -3,14 +3,14 @@ import { client, INDEX_ALIAS } from './index' import { EntityType } from '../datalayer/pubsub' export const addLabelInPage = async ( - id: string, + pageId: string, label: Label, ctx: PageContext ): Promise => { try { const { body } = await client.update({ index: INDEX_ALIAS, - id, + id: pageId, body: { script: { source: `if (ctx._source.labels == null) { @@ -32,7 +32,7 @@ export const addLabelInPage = async ( await ctx.pubsub.entityCreated