From f272238dde9f385b04036248ba0b4c53b395c568 Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 5 Jun 2022 23:13:09 +0200 Subject: [PATCH] fix backend implementation of bulk actions --- src/routes/api/search.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/routes/api/search.js b/src/routes/api/search.js index 5372540df..a929d357e 100644 --- a/src/routes/api/search.js +++ b/src/routes/api/search.js @@ -78,21 +78,33 @@ const ACTION_HANDLERS = { }, renameLabel: (action, note) => { for (const label of note.getOwnedLabels(action.oldLabelName)) { - label.name = action.newLabelName; - label.save(); + // attribute name is immutable, renaming means delete old + create new + const newLabel = label.createClone('label', action.newLabelName, label.value); + + newLabel.save(); + label.markAsDeleted(); } }, renameRelation: (action, note) => { for (const relation of note.getOwnedRelations(action.oldRelationName)) { - relation.name = action.newRelationName; - relation.save(); + // attribute name is immutable, renaming means delete old + create new + const newRelation = relation.createClone('relation', action.newRelationName, relation.value); + + newRelation.save(); + relation.markAsDeleted(); } }, - setLabelValue: (action, note) => { - note.setLabel(action.labelName, action.labelValue); + updateLabelValue: (action, note) => { + for (const label of note.getOwnedLabels(action.labelName)) { + label.value = action.labelValue; + label.save(); + } }, - setRelationTarget: (action, note) => { - note.setRelation(action.relationName, action.targetNoteId); + updateRelationTarget: (action, note) => { + for (const relation of note.getOwnedLabels(action.relationName)) { + relation.value = action.targetNoteId; + relation.save(); + } }, moveNote: (action, note) => { const targetParentNote = becca.getNote(action.targetParentNoteId);