mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Add deleteLabelForHighlights
This commit is contained in:
parent
145867fe05
commit
22c604c15b
1 changed files with 58 additions and 0 deletions
|
|
@ -255,3 +255,61 @@ export const setLabelsForHighlight = async (
|
|||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export const deleteLabelForHighlights = async (
|
||||
userId: string,
|
||||
label: string,
|
||||
ctx: PageContext
|
||||
): Promise<boolean> => {
|
||||
try {
|
||||
const { body } = await client.updateByQuery({
|
||||
index: INDEX_ALIAS,
|
||||
body: {
|
||||
script: {
|
||||
source:
|
||||
'ctx._source.highlights[0].labels.removeIf(label -> label.name == params.label)',
|
||||
lang: 'painless',
|
||||
params: {
|
||||
label: label,
|
||||
},
|
||||
},
|
||||
query: {
|
||||
bool: {
|
||||
filter: [
|
||||
{
|
||||
term: {
|
||||
userId,
|
||||
},
|
||||
},
|
||||
{
|
||||
nested: {
|
||||
path: 'highlights',
|
||||
query: {
|
||||
nested: {
|
||||
path: 'labels',
|
||||
query: {
|
||||
term: {
|
||||
'highlights.labels.name': label,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
refresh: ctx.refresh,
|
||||
conflicts: 'proceed', // ignore conflicts
|
||||
})
|
||||
|
||||
body.updated > 0 &&
|
||||
(await ctx.pubsub.entityDeleted(EntityType.LABEL, label, ctx.uid))
|
||||
|
||||
return true
|
||||
} catch (e) {
|
||||
console.error('failed to delete a label for highlights in elastic', e)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue